Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test(cwl): Add LiveTailSession unit tests for start and stopLiveTail #6023

Open
wants to merge 1 commit into
base: feature/cwltail
Choose a base branch
from

Conversation

keeganirby
Copy link

Problem

LiveTailSession's startLiveTail and stopLiveTail methods are uncovered

Solution

Adds tests to each, ensuring that:
StartLiveTail:

  • calls CWL Client with AbortSignal

StopLiveTail:

  • AbortSignal is fired
  • CWL client is destroyed

Also moves test helper functions buildLiveTailCommandOutput and getTestResponseStream to the LiveTailSession tests because that class is what is responsible for calling and returning the CWL backend APIs.


License: I confirm that my contribution is made under the terms of the Apache 2.0 license.

@keeganirby keeganirby requested a review from a team as a code owner November 14, 2024 21:59
@@ -65,6 +83,36 @@ describe('LiveTailSession', async function () {
)
})

it('startLiveTail sends command to CWL client with AbortSignal', async function () {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like a lot of code to test very little. The test description sounds like it's testing that a parameter is passed somewhere.


assert.strictEqual(sendCommandMock.calledOnce, true)
assert.strictEqual(
sendCommandMock.calledWith(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

instead of mocking many things just to test that parameters are sent, can you stub fake responses and let the code actually work on the response. that tests the full codepath, instead of just tiny parts of it (and requiring lots of test code)

})

it('stopLiveTail fires AbortSignal and destroys CWL client', function () {
const destroyClientSpy = sandbox.spy(CloudWatchLogsClient.prototype, 'destroy')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why does this need a spy? test the actual state. the client can expose some (readonly) state if needed.

do not use mocks and spies except as a last resort. it looks like it's the first resort in this tests, instead of the last resort.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants