(t *testing.T)
| 59 | } |
| 60 | |
| 61 | func TestTrackCommandCompleted_ReportsSuccess(t *testing.T) { |
| 62 | client := &recordingTelemetryClient{} |
| 63 | ctx := newTelemetryContext(client, "algolia indices list") |
| 64 | |
| 65 | trackCommandCompleted(ctx, &cobra.Command{Use: "list"}, exitOK, nil, 1500*time.Millisecond) |
| 66 | |
| 67 | if len(client.events) != 1 { |
| 68 | t.Fatalf("expected 1 event, got %d", len(client.events)) |
| 69 | } |
| 70 | event := client.events[0] |
| 71 | if event.name != telemetry.EventCommandCompleted { |
| 72 | t.Errorf("event = %q, want %q", event.name, telemetry.EventCommandCompleted) |
| 73 | } |
| 74 | if event.props["succeeded"] != true { |
| 75 | t.Errorf("succeeded = %v, want true", event.props["succeeded"]) |
| 76 | } |
| 77 | if event.props["exit_code"] != 0 { |
| 78 | t.Errorf("exit_code = %v, want 0", event.props["exit_code"]) |
| 79 | } |
| 80 | if event.props["duration_ms"] != int64(1500) { |
| 81 | t.Errorf("duration_ms = %v, want 1500", event.props["duration_ms"]) |
| 82 | } |
| 83 | if _, ok := event.props["error_class"]; ok { |
| 84 | t.Error("unexpected error_class on success") |
| 85 | } |
| 86 | } |
| 87 | |
| 88 | func TestTrackCommandCompleted_ReportsFailure(t *testing.T) { |
| 89 | client := &recordingTelemetryClient{} |
nothing calls this directly
no test coverage detected