(t *testing.T)
| 182 | } |
| 183 | |
| 184 | func 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 | |
| 214 | func TestStructuredEvent(t *testing.T) { |
| 215 | t.Parallel() |
nothing calls this directly
no test coverage detected