Skip to content

Commit

Permalink
Improve code coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
mrsillydog committed Jan 14, 2025
1 parent 9a8dabd commit 7893479
Showing 1 changed file with 17 additions and 5 deletions.
22 changes: 17 additions & 5 deletions client/httpclient_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -316,16 +316,24 @@ func TestRedirectHTTP(t *testing.T) {
func TestHTTPReportsAvailableComponents(t *testing.T) {
testCases := []struct {
desc string
capabilities protobufs.AgentCapabilities
availableComponents *protobufs.AvailableComponents
startErr error
}{
{
desc: "Does not report AvailableComponents",
availableComponents: nil,
},
{
desc: "Reports AvailableComponents",
capabilities: protobufs.AgentCapabilities_AgentCapabilities_ReportsAvailableComponents,
availableComponents: generateTestAvailableComponents(),
},
{
desc: "No AvailableComponents on Start() despite capability",
capabilities: protobufs.AgentCapabilities_AgentCapabilities_ReportsAvailableComponents,
startErr: internal.ErrAvailableComponentsMissing,
},
}

for _, tc := range testCases {
Expand Down Expand Up @@ -380,15 +388,19 @@ func TestHTTPReportsAvailableComponents(t *testing.T) {
// Start a client.
settings := types.StartSettings{}
settings.OpAMPServerURL = "http://" + srv.Endpoint
if tc.availableComponents != nil {
settings.Capabilities = protobufs.AgentCapabilities_AgentCapabilities_ReportsAvailableComponents
settings.AvailableComponents = tc.availableComponents
}
settings.Capabilities = tc.capabilities
settings.AvailableComponents = tc.availableComponents

client := NewHTTP(nil)
prepareClient(t, &settings, client)

assert.NoError(t, client.Start(context.Background(), settings))
startErr := client.Start(context.Background(), settings)
if tc.startErr == nil {
assert.NoError(t, startErr)
} else {
assert.ErrorIs(t, startErr, tc.startErr)
return
}

// Verify that status report is delivered.
eventually(t, func() bool {
Expand Down

0 comments on commit 7893479

Please sign in to comment.