result_transformer.test.ts 941 B

12345678910111213141516171819202122232425262728293031323334
  1. import { logStreamToDataFrame } from './result_transformer';
  2. describe('convert loki response to DataFrame', () => {
  3. const streams = [
  4. {
  5. labels: '{foo="bar"}',
  6. entries: [
  7. {
  8. line: "foo: 'bar'",
  9. ts: '1970-01-01T00:00:00Z',
  10. },
  11. ],
  12. },
  13. {
  14. labels: '{bar="foo"}',
  15. entries: [
  16. {
  17. line: "bar: 'foo'",
  18. ts: '1970-01-01T00:00:00Z',
  19. },
  20. ],
  21. },
  22. ];
  23. it('converts streams to series', () => {
  24. const data = streams.map(stream => logStreamToDataFrame(stream));
  25. expect(data.length).toBe(2);
  26. expect(data[0].labels['foo']).toEqual('bar');
  27. expect(data[0].rows[0][0]).toEqual(streams[0].entries[0].ts);
  28. expect(data[0].rows[0][1]).toEqual(streams[0].entries[0].line);
  29. expect(data[1].rows[0][0]).toEqual(streams[1].entries[0].ts);
  30. expect(data[1].rows[0][1]).toEqual(streams[1].entries[0].line);
  31. });
  32. });