-
Notifications
You must be signed in to change notification settings - Fork 437
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
base: feature/cwltail
Are you sure you want to change the base?
Conversation
@@ -65,6 +83,36 @@ describe('LiveTailSession', async function () { | |||
) | |||
}) | |||
|
|||
it('startLiveTail sends command to CWL client with AbortSignal', async function () { |
There was a problem hiding this comment.
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( |
There was a problem hiding this comment.
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') |
There was a problem hiding this comment.
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.
Problem
LiveTailSession's startLiveTail and stopLiveTail methods are uncovered
Solution
Adds tests to each, ensuring that:
StartLiveTail:
StopLiveTail:
Also moves test helper functions
buildLiveTailCommandOutput
andgetTestResponseStream
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.