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.
44 lines
1.7 KiB
44 lines
1.7 KiB
2 years ago
|
import { Datasource, DatasourceType } from '../src/index';
|
||
|
import { InfluxdbConnector } from '../src/connectors/influxdb';
|
||
5 years ago
|
|
||
|
import 'jest';
|
||
|
|
||
|
|
||
|
describe('Correct InfluxDB query', function() {
|
||
|
let datasource: Datasource = {
|
||
|
url: 'url',
|
||
2 years ago
|
type: DatasourceType.INFLUXDB,
|
||
5 years ago
|
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() {
|
||
2 years ago
|
const connector = new InfluxdbConnector(datasource, [target]);
|
||
|
expect(connector.getQuery(1534809600,1537488000,666,10).schema.params.q).toBe(
|
||
5 years ago
|
`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)`;
|
||
2 years ago
|
const connector = new InfluxdbConnector(datasource, [target]);
|
||
|
expect(connector.getQuery(1534809600,1537488000,666,10).schema.params.q).toBe(
|
||
5 years ago
|
`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)`;
|
||
2 years ago
|
const connector = new InfluxdbConnector(datasource, [target]);
|
||
|
expect(connector.getQuery(1534809600,1537488000,666,10).schema.params.q).toBe(
|
||
5 years ago
|
`SELECT mean("value") FROM "cpu_value" WHERE time >= 1534809600ms AND time <= 1537488000ms GROUP BY time(30s) fill(null) LIMIT 666 OFFSET 10`
|
||
|
)
|
||
|
});
|
||
|
|
||
|
})
|