From eaeeb5c69866729117168287d20183d3e1f431a0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=A1bor=20Farkas?= Date: Wed, 19 Jul 2023 11:42:23 +0200 Subject: [PATCH] logs: improved unit tests (#71840) --- .../logs/components/logParser.test.ts | 32 ++++++++++++++----- public/app/features/logs/utils.test.ts | 16 ++++++++-- 2 files changed, 38 insertions(+), 10 deletions(-) diff --git a/public/app/features/logs/components/logParser.test.ts b/public/app/features/logs/components/logParser.test.ts index 01141cb5a3a..9e6dd21ace7 100644 --- a/public/app/features/logs/components/logParser.test.ts +++ b/public/app/features/logs/components/logParser.test.ts @@ -6,12 +6,18 @@ import { getAllFields, createLogLineLinks, FieldDef } from './logParser'; describe('logParser', () => { describe('getAllFields', () => { - it('should filter out field with labels name and other type', () => { + it('should filter out field with labels name old-loki-style frame', () => { const logRow = createLogRow({ - entryFieldIndex: 10, + entryFieldIndex: 1, dataFrame: new MutableDataFrame({ + meta: { + custom: { + frameType: 'LabeledTimeValues', + }, + }, refId: 'A', fields: [ + testTimeField, testLineField, testStringField, { @@ -29,12 +35,13 @@ describe('logParser', () => { expect(fields.find((field) => field.keys[0] === 'labels')).toBe(undefined); }); - it('should not filter out field with labels name and string type', () => { + it('should not filter out field with labels name in not-old-loki-style frame', () => { const logRow = createLogRow({ - entryFieldIndex: 10, + entryFieldIndex: 1, dataFrame: new MutableDataFrame({ refId: 'A', fields: [ + testTimeField, testLineField, testStringField, { @@ -53,10 +60,11 @@ describe('logParser', () => { it('should not filter out field with labels name and other type and datalinks', () => { const logRow = createLogRow({ - entryFieldIndex: 10, + entryFieldIndex: 1, dataFrame: new MutableDataFrame({ refId: 'A', fields: [ + testTimeField, testLineField, testStringField, { @@ -82,10 +90,11 @@ describe('logParser', () => { it('should filter out field with id name', () => { const logRow = createLogRow({ - entryFieldIndex: 10, + entryFieldIndex: 1, dataFrame: new MutableDataFrame({ refId: 'A', fields: [ + testTimeField, testLineField, testStringField, { @@ -139,10 +148,10 @@ describe('logParser', () => { it('should not filter out field with string values', () => { const logRow = createLogRow({ - entryFieldIndex: 10, + entryFieldIndex: 1, dataFrame: new MutableDataFrame({ refId: 'A', - fields: [testLineField, { ...testStringField }], + fields: [testTimeField, testLineField, { ...testStringField }], }), }); @@ -214,6 +223,13 @@ describe('logParser', () => { }); }); +const testTimeField = { + name: 'timestamp', + type: FieldType.time, + config: {}, + values: [1], +}; + const testLineField = { name: 'body', type: FieldType.string, diff --git a/public/app/features/logs/utils.test.ts b/public/app/features/logs/utils.test.ts index 34fb4e2b9f5..6e745ef63e7 100644 --- a/public/app/features/logs/utils.test.ts +++ b/public/app/features/logs/utils.test.ts @@ -222,10 +222,16 @@ describe('checkLogsError()', () => { describe('logRowsToReadableJson', () => { const testRow: LogRowModel = { rowIndex: 0, - entryFieldIndex: 0, + entryFieldIndex: 1, dataFrame: { length: 1, fields: [ + { + name: 'timestamp', + type: FieldType.time, + config: {}, + values: [1], + }, { name: 'body', type: FieldType.string, @@ -252,6 +258,12 @@ describe('logRowsToReadableJson', () => { const testDf: DataFrame = { length: 1, fields: [ + { + name: 'timestamp', + type: FieldType.time, + config: {}, + values: [1], + }, { name: 'body', type: FieldType.string, @@ -268,7 +280,7 @@ describe('logRowsToReadableJson', () => { }; const testRow2: LogRowModel = { rowIndex: 0, - entryFieldIndex: -1, + entryFieldIndex: 1, dataFrame: testDf, entry: 'test entry', hasAnsi: false,