| 1 |
import { strict as assert } from 'assert'; |
| 2 |
import { TimeSeriesAggregationType, TimeSeriesDuplicatePolicies } from '.'; |
| 3 |
import testUtils, { GLOBAL } from '../test-utils'; |
| 4 |
import { InfoReply, transformArguments } from './INFO'; |
| 5 |
|
| 6 |
describe('INFO', () => { |
| 7 |
it('transformArguments', () => { |
| 8 |
assert.deepEqual( |
| 9 |
transformArguments('key'), |
| 10 |
['TS.INFO', 'key'] |
| 11 |
); |
| 12 |
}); |
| 13 |
|
| 14 |
testUtils.testWithClient('client.ts.info', async client => { |
| 15 |
await Promise.all([ |
| 16 |
client.ts.create('key', { |
| 17 |
LABELS: { id: '1' }, |
| 18 |
DUPLICATE_POLICY: TimeSeriesDuplicatePolicies.LAST |
| 19 |
}), |
| 20 |
client.ts.create('key2'), |
| 21 |
client.ts.createRule('key', 'key2', TimeSeriesAggregationType.COUNT, 5), |
| 22 |
client.ts.add('key', 1, 10) |
| 23 |
]); |
| 24 |
|
| 25 |
assertInfo(await client.ts.info('key')); |
| 26 |
}, GLOBAL.SERVERS.OPEN); |
| 27 |
}); |
| 28 |
|
| 29 |
export function assertInfo(info: InfoReply): void { |
| 30 |
assert.equal(typeof info.totalSamples, 'number'); |
| 31 |
assert.equal(typeof info.memoryUsage, 'number'); |
| 32 |
assert.equal(typeof info.firstTimestamp, 'number'); |
| 33 |
assert.equal(typeof info.lastTimestamp, 'number'); |
| 34 |
assert.equal(typeof info.retentionTime, 'number'); |
| 35 |
assert.equal(typeof info.chunkCount, 'number'); |
| 36 |
assert.equal(typeof info.chunkSize, 'number'); |
| 37 |
assert.equal(typeof info.chunkType, 'string'); |
| 38 |
assert.equal(typeof info.duplicatePolicy, 'string'); |
| 39 |
assert.ok(Array.isArray(info.labels)); |
| 40 |
for (const label of info.labels) { |
| 41 |
assert.equal(typeof label, 'object'); |
| 42 |
assert.equal(typeof label.name, 'string'); |
| 43 |
assert.equal(typeof label.value, 'string'); |
| 44 |
} |
| 45 |
assert.ok(Array.isArray(info.rules)); |
| 46 |
for (const rule of info.rules) { |
| 47 |
assert.equal(typeof rule, 'object'); |
| 48 |
assert.equal(typeof rule.aggregationType, 'string'); |
| 49 |
assert.equal(typeof rule.key, 'string'); |
| 50 |
assert.equal(typeof rule.timeBucket, 'number'); |
| 51 |
} |
| 52 |
assert.ok(info.sourceKey === null || typeof info.sourceKey === 'string'); |
| 53 |
} |