Skip to content

Commit

Permalink
Remove redundant code in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Keegan Irby committed Nov 13, 2024
1 parent 5365d44 commit 0a038b1
Showing 1 changed file with 57 additions and 70 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
})

0 comments on commit 0a038b1

Please sign in to comment.