MCPcopy
hub / github.com/docker/docker-agent / TestCommandTrackingWithError

Function TestCommandTrackingWithError

pkg/telemetry/telemetry_test.go:184–212  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

182}
183
184func TestCommandTrackingWithError(t *testing.T) {
185 t.Parallel()
186 logger := slog.New(slog.NewTextHandler(os.Stderr, nil))
187 mockHTTP := NewMockHTTPClient()
188 client := newClient(t.Context(), logger, true, true, "test-version", mockHTTP.Client)
189
190 client.endpoint = "https://test-command-error.com/api"
191 client.apiKey = "test-command-error-key"
192 client.header = "test-header"
193
194 testErr := &testError{}
195 cmdInfo := CommandInfo{
196 Action: "failing-command",
197 Args: []string{},
198 Flags: []string{},
199 }
200 err := client.TrackCommand(t.Context(), cmdInfo, func(ctx context.Context) error {
201 return testErr
202 })
203
204 assert.Equal(t, testErr, err)
205
206 require.Eventually(t, func() bool {
207 return mockHTTP.GetRequestCount() > 0
208 }, time.Second, 5*time.Millisecond, "Expected HTTP requests to be made for command error tracking")
209
210 requestCount := mockHTTP.GetRequestCount()
211 t.Logf("Command error tracking HTTP requests captured: %d", requestCount)
212}
213
214func TestStructuredEvent(t *testing.T) {
215 t.Parallel()

Callers

nothing calls this directly

Calls 6

GetRequestCountMethod · 0.95
NewMockHTTPClientFunction · 0.85
newClientFunction · 0.85
ContextMethod · 0.80
TrackCommandMethod · 0.80
NewMethod · 0.45

Tested by

no test coverage detected