MCPcopy Index your code
hub / github.com/docker/docker-agent / TestCommandTracking

Function TestCommandTracking

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

Source from the content-addressed store, hash-verified

146}
147
148func TestCommandTracking(t *testing.T) {
149 t.Parallel()
150 logger := slog.New(slog.NewTextHandler(os.Stderr, nil))
151 mockHTTP := NewMockHTTPClient()
152 client := newClient(t.Context(), logger, true, true, "test-version", mockHTTP.Client)
153
154 client.endpoint = "https://test-command-tracking.com/api"
155 client.apiKey = "test-command-key"
156 client.header = "test-header"
157
158 executed := false
159 cmdInfo := CommandInfo{
160 Action: "test-command",
161 Args: []string{},
162 Flags: []string{},
163 }
164 err := client.TrackCommand(t.Context(), cmdInfo, func(ctx context.Context) error {
165 executed = true
166 return nil
167 })
168 require.NoError(t, err)
169 assert.True(t, executed)
170
171 require.Eventually(t, func() bool {
172 return mockHTTP.GetRequestCount() > 0
173 }, time.Second, 5*time.Millisecond, "Expected HTTP requests to be made for command tracking")
174
175 requestCount := mockHTTP.GetRequestCount()
176 t.Logf("Command tracking HTTP requests captured: %d", requestCount)
177
178 requests := mockHTTP.GetRequests()
179 for i, req := range requests {
180 assert.Equal(t, "test-command-key", req.Header.Get("test-header"), "Request %d: Expected test-header test-command-key", i)
181 }
182}
183
184func TestCommandTrackingWithError(t *testing.T) {
185 t.Parallel()

Callers

nothing calls this directly

Calls 8

GetRequestCountMethod · 0.95
GetRequestsMethod · 0.95
NewMockHTTPClientFunction · 0.85
newClientFunction · 0.85
ContextMethod · 0.80
TrackCommandMethod · 0.80
GetMethod · 0.65
NewMethod · 0.45

Tested by

no test coverage detected