Skip to content

Commit

Permalink
Construct LogEvent filter from params. Validate buildStartLiveTailCom…
Browse files Browse the repository at this point in the history
…mand in unit tests
  • Loading branch information
Keegan Irby committed Nov 13, 2024
1 parent 30d9217 commit 4d3b7f6
Show file tree
Hide file tree
Showing 2 changed files with 99 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ export class LiveTailSession {
public constructor(configuration: LiveTailSessionConfiguration) {
this._logGroupArn = configuration.logGroupArn
this.logStreamFilter = configuration.logStreamFilter
this.logEventFilterPattern = configuration.logEventFilterPattern
this.liveTailClient = {
cwlClient: new CloudWatchLogsClient({
credentials: configuration.awsCredentials,
Expand Down Expand Up @@ -120,7 +121,7 @@ export class LiveTailSession {
return this.endTime - this.startTime
}

private buildStartLiveTailCommand(): StartLiveTailCommand {
public buildStartLiveTailCommand(): StartLiveTailCommand {
let logStreamNamePrefix = undefined
let logStreamName = undefined
if (this.logStreamFilter) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
/*!
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0
*/
import assert from 'assert'
import { LiveTailSession } from '../../../../awsService/cloudWatchLogs/registry/liveTailSession'
import { StartLiveTailCommand } from '@aws-sdk/client-cloudwatch-logs'
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('correctly 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,
})
)
)
})
it('correctly 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,
})
)
)
})
it('correctly 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],
})
)
)
})
it('correctly builds StartLiveTailCommand: with log event Filter', function () {
const session = new LiveTailSession({
logGroupArn: testLogGroupArn,
logStreamFilter: {
type: 'all',
},
logEventFilterPattern: 'test-filter',
region: testRegion,
awsCredentials: testAwsCredentials,
})
assert.strictEqual(
JSON.stringify(session.buildStartLiveTailCommand()),
JSON.stringify(
new StartLiveTailCommand({
logGroupIdentifiers: [testLogGroupArn],
logEventFilterPattern: testFilter,
logStreamNamePrefixes: undefined,
logStreamNames: undefined,
})
)
)
})
})

0 comments on commit 4d3b7f6

Please sign in to comment.