The open and composable observability and data visualization platform. Visualize metrics, logs, and traces from multiple sources like Prometheus, Loki, Elasticsearch, InfluxDB, Postgres and many more.
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.
 
 
 
 
 
 
grafana/public/app/features/logs/UniqueKeyMaker.test.ts

41 lines
1.0 KiB

import { UniqueKeyMaker } from './UniqueKeyMaker';
describe('UniqueKeyMaker', () => {
const expectKeys = (testData: Array<[string, string]>) => {
const k = new UniqueKeyMaker();
testData.forEach(([input, output]) => {
expect(k.getKey(input)).toBe(output);
});
// we also make a check that all the output-values are unique
const outputs = testData.map(([i, o]) => o);
const uniqueOutputLength = new Set(outputs).size;
expect(uniqueOutputLength).toBe(outputs.length);
};
it('should handle already unique keys', () => {
expectKeys([
['one', 'k_one'],
['two', 'k_two'],
['three', 'k_three'],
]);
});
it('should handle duplicate keys', () => {
expectKeys([
['one', 'k_one'],
['one', 'i_2'],
['one', 'i_3'],
]);
});
it('should handle a mix of unique and duplicate keys', () => {
expectKeys([
['one', 'k_one'],
['two', 'k_two'],
['one', 'i_3'],
['two', 'i_4'],
['three', 'k_three'],
]);
});
});