From 0a038b187916ae28eacaaa610f4864c74e7f1fd5 Mon Sep 17 00:00:00 2001 From: Keegan Irby Date: Wed, 13 Nov 2024 13:54:00 -0800 Subject: [PATCH] Remove redundant code in tests --- .../registry/liveTailSession.test.ts | 127 ++++++++---------- 1 file changed, 57 insertions(+), 70 deletions(-) diff --git a/packages/core/src/test/awsService/cloudWatchLogs/registry/liveTailSession.test.ts b/packages/core/src/test/awsService/cloudWatchLogs/registry/liveTailSession.test.ts index cf7ddaa89c1..b1c5dfa3b4e 100644 --- a/packages/core/src/test/awsService/cloudWatchLogs/registry/liveTailSession.test.ts +++ b/packages/core/src/test/awsService/cloudWatchLogs/registry/liveTailSession.test.ts @@ -5,93 +5,80 @@ import assert from 'assert' import { LiveTailSession } from '../../../../awsService/cloudWatchLogs/registry/liveTailSession' import { StartLiveTailCommand } from '@aws-sdk/client-cloudwatch-logs' +import { LogStreamFilterResponse } from '../../../../awsService/cloudWatchLogs/wizard/liveTailLogStreamSubmenu' + describe('LiveTailSession', async function () { const testLogGroupArn = 'arn:aws:test-log-group' const testRegion = 'test-region' const testFilter = 'test-filter' const testAwsCredentials = {} as any as AWS.Credentials + it('builds StartLiveTailCommand: no stream Filter, no event filter.', function () { - const session = new LiveTailSession({ - logGroupArn: testLogGroupArn, - region: testRegion, - awsCredentials: testAwsCredentials, - }) - assert.strictEqual( - JSON.stringify(session.buildStartLiveTailCommand()), - JSON.stringify( - new StartLiveTailCommand({ - logGroupIdentifiers: [testLogGroupArn], - logEventFilterPattern: undefined, - logStreamNamePrefixes: undefined, - logStreamNames: undefined, - }) - ) + const session = buildLiveTailSession({ type: 'all' }, undefined) + validateStartLiveTailCommand( + session.buildStartLiveTailCommand(), + new StartLiveTailCommand({ + logGroupIdentifiers: [testLogGroupArn], + logEventFilterPattern: undefined, + logStreamNamePrefixes: undefined, + logStreamNames: undefined, + }) ) }) + it('builds StartLiveTailCommand: with prefix stream Filter', function () { - const session = new LiveTailSession({ - logGroupArn: testLogGroupArn, - logStreamFilter: { - type: 'prefix', - filter: 'test-filter', - }, - region: testRegion, - awsCredentials: testAwsCredentials, - }) - assert.strictEqual( - JSON.stringify(session.buildStartLiveTailCommand()), - JSON.stringify( - new StartLiveTailCommand({ - logGroupIdentifiers: [testLogGroupArn], - logEventFilterPattern: undefined, - logStreamNamePrefixes: [testFilter], - logStreamNames: undefined, - }) - ) + const session = buildLiveTailSession({ type: 'prefix', filter: testFilter }, undefined) + validateStartLiveTailCommand( + session.buildStartLiveTailCommand(), + new StartLiveTailCommand({ + logGroupIdentifiers: [testLogGroupArn], + logEventFilterPattern: undefined, + logStreamNamePrefixes: [testFilter], + logStreamNames: undefined, + }) ) }) + it('builds StartLiveTailCommand: with specific stream Filter', function () { - const session = new LiveTailSession({ - logGroupArn: testLogGroupArn, - logStreamFilter: { - type: 'specific', - filter: 'test-filter', - }, - region: testRegion, - awsCredentials: testAwsCredentials, - }) - assert.strictEqual( - JSON.stringify(session.buildStartLiveTailCommand()), - JSON.stringify( - new StartLiveTailCommand({ - logGroupIdentifiers: [testLogGroupArn], - logEventFilterPattern: undefined, - logStreamNamePrefixes: undefined, - logStreamNames: [testFilter], - }) - ) + const session = buildLiveTailSession({ type: 'specific', filter: testFilter }, undefined) + validateStartLiveTailCommand( + session.buildStartLiveTailCommand(), + new StartLiveTailCommand({ + logGroupIdentifiers: [testLogGroupArn], + logEventFilterPattern: undefined, + logStreamNamePrefixes: undefined, + logStreamNames: [testFilter], + }) ) }) + it('builds StartLiveTailCommand: with log event Filter', function () { - const session = new LiveTailSession({ + const session = buildLiveTailSession({ type: 'all' }, testFilter) + validateStartLiveTailCommand( + session.buildStartLiveTailCommand(), + new StartLiveTailCommand({ + logGroupIdentifiers: [testLogGroupArn], + logEventFilterPattern: testFilter, + logStreamNamePrefixes: undefined, + logStreamNames: undefined, + }) + ) + }) + + function buildLiveTailSession( + logStreamFilter: LogStreamFilterResponse, + logEventFilterPattern: string | undefined + ): LiveTailSession { + return new LiveTailSession({ logGroupArn: testLogGroupArn, - logStreamFilter: { - type: 'all', - }, - logEventFilterPattern: 'test-filter', + logStreamFilter: logStreamFilter, + logEventFilterPattern: logEventFilterPattern, region: testRegion, awsCredentials: testAwsCredentials, }) - assert.strictEqual( - JSON.stringify(session.buildStartLiveTailCommand()), - JSON.stringify( - new StartLiveTailCommand({ - logGroupIdentifiers: [testLogGroupArn], - logEventFilterPattern: testFilter, - logStreamNamePrefixes: undefined, - logStreamNames: undefined, - }) - ) - ) - }) + } + + function validateStartLiveTailCommand(actual: StartLiveTailCommand, expected: StartLiveTailCommand) { + assert.strictEqual(JSON.stringify(actual), JSON.stringify(expected)) + } })