ci: improve sysdig client test coverage#81
Conversation
There was a problem hiding this comment.
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, andWithVersion.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| ctx := sysdig.WrapContextWithHost(context.Background(), ts.URL) | ||
|
|
||
| _, err = client.GetMyPermissionsWithResponse(ctx) | ||
| Expect(err).To(MatchError(ContainSubstring("authorization token not present"))) | ||
| }) |
There was a problem hiding this comment.
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.
| _, err = client.GetMyPermissionsWithResponse(context.Background()) | ||
| Expect(err).To(MatchError(ContainSubstring("unable to authenticate"))) |
There was a problem hiding this comment.
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).
| _, 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()) |
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.