You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
43 lines
1.7 KiB
43 lines
1.7 KiB
import { Datasource, DatasourceType } from '../src/index'; |
|
import { InfluxdbConnector } from '../src/connectors/influxdb'; |
|
|
|
import 'jest'; |
|
|
|
|
|
describe('Correct InfluxDB query', function() { |
|
let datasource: Datasource = { |
|
url: 'url', |
|
type: DatasourceType.INFLUXDB, |
|
params: { |
|
db: 'db', |
|
q: `SELECT mean("value") FROM "db" WHERE time > xxx AND time <= xxx LIMIT 100 OFFSET 20`, |
|
epoch: '' |
|
} |
|
}; |
|
|
|
let target = 'mean("value")'; |
|
|
|
it("test query with two time expressions", function() { |
|
const connector = new InfluxdbConnector(datasource, [target]); |
|
expect(connector.getQuery(1534809600,1537488000,666,10).schema.params.q).toBe( |
|
`SELECT mean("value") FROM "db" WHERE time >= 1534809600ms AND time <= 1537488000ms LIMIT 666 OFFSET 10` |
|
) |
|
}); |
|
|
|
it('test query with one time expression', function() { |
|
datasource.params.q = `SELECT mean("value") FROM "cpu_value" WHERE time >= now() - 6h GROUP BY time(30s) fill(null)`; |
|
const connector = new InfluxdbConnector(datasource, [target]); |
|
expect(connector.getQuery(1534809600,1537488000,666,10).schema.params.q).toBe( |
|
`SELECT mean("value") FROM "cpu_value" WHERE time >= 1534809600ms AND time <= 1537488000ms GROUP BY time(30s) fill(null) LIMIT 666 OFFSET 10` |
|
) |
|
}); |
|
|
|
it('test query with time expression', function() { |
|
datasource.params.q = `SELECT mean("value") FROM "cpu_value" WHERE time>= now() - 6h AND time<xxx GROUP BY time(30s) fill(null)`; |
|
const connector = new InfluxdbConnector(datasource, [target]); |
|
expect(connector.getQuery(1534809600,1537488000,666,10).schema.params.q).toBe( |
|
`SELECT mean("value") FROM "cpu_value" WHERE time >= 1534809600ms AND time <= 1537488000ms GROUP BY time(30s) fill(null) LIMIT 666 OFFSET 10` |
|
) |
|
}); |
|
|
|
})
|
|
|