Skip to content

ci: improve sysdig client test coverage#81

Open
tembleking wants to merge 1 commit intomainfrom
test/improve-sysdig-client-coverage
Open

ci: improve sysdig client test coverage#81
tembleking wants to merge 1 commit intomainfrom
test/improve-sysdig-client-coverage

Conversation

@tembleking
Copy link
Copy Markdown
Member

@tembleking tembleking commented Apr 27, 2026

4 functions in client.go had 0% coverage (GetTokenFromContext, GetHostFromContext, WithFallbackAuthentication, WithVersion). New tests exercise auth strategies through the actual client against httptest servers, not as isolated RequestEditorFn unit tests.

Refactors duplicated handler into shared permissionsHandler across TLS and auth tests.

Copilot AI review requested due to automatic review settings April 27, 2026 08:58
@tembleking tembleking requested a review from a team as a code owner April 27, 2026 08:58
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Improves test coverage for Sysdig client authentication/context helpers by exercising the real client against httptest servers (rather than isolated RequestEditorFn unit tests).

Changes:

  • Refactors duplicated test server logic into a reusable permissionsHandler.
  • Adds coverage for context helpers (GetTokenFromContext, GetHostFromContext) including panic paths.
  • Adds authentication/versioning tests for WithHostAndTokenFromContext, WithFallbackAuthentication, and WithVersion.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +126 to +130
ctx := sysdig.WrapContextWithHost(context.Background(), ts.URL)

_, err = client.GetMyPermissionsWithResponse(ctx)
Expect(err).To(MatchError(ContainSubstring("authorization token not present")))
})
Copy link

Copilot AI Apr 27, 2026

Choose a reason for hiding this comment

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

In this error-path test you’re discarding the response value. Consider capturing the response and asserting it is nil (as in internal/infra/sysdig/client_permissions_integration_test.go:59-61) so the test also verifies the client doesn’t perform an HTTP call / doesn’t return a partial response when authentication fails.

Copilot uses AI. Check for mistakes.
Comment on lines +173 to +174
_, err = client.GetMyPermissionsWithResponse(context.Background())
Expect(err).To(MatchError(ContainSubstring("unable to authenticate")))
Copy link

Copilot AI Apr 27, 2026

Choose a reason for hiding this comment

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

This test discards the response value on the failure path. Consider capturing the response and asserting it’s nil to make the expected contract explicit (error returned implies no usable response).

Suggested change
_, err = client.GetMyPermissionsWithResponse(context.Background())
Expect(err).To(MatchError(ContainSubstring("unable to authenticate")))
resp, err := client.GetMyPermissionsWithResponse(context.Background())
Expect(err).To(MatchError(ContainSubstring("unable to authenticate")))
Expect(resp).To(BeNil())

Copilot uses AI. Check for mistakes.
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.

3 participants