(t *testing.T)
| 146 | } |
| 147 | |
| 148 | func 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 | |
| 184 | func TestCommandTrackingWithError(t *testing.T) { |
| 185 | t.Parallel() |
nothing calls this directly
no test coverage detected