MCPcopy Create free account
hub / github.com/algolia/cli / TestTrackCommandCompleted_ReportsSuccess

Function TestTrackCommandCompleted_ReportsSuccess

pkg/cmd/root/root_test.go:61–86  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

59}
60
61func 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
88func TestTrackCommandCompleted_ReportsFailure(t *testing.T) {
89 client := &recordingTelemetryClient{}

Callers

nothing calls this directly

Calls 4

newTelemetryContextFunction · 0.85
trackCommandCompletedFunction · 0.85
ErrorfMethod · 0.65
ErrorMethod · 0.45

Tested by

no test coverage detected