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

Function TestTrackCommandCompleted_ReportsFailure

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

Source from the content-addressed store, hash-verified

86}
87
88func TestTrackCommandCompleted_ReportsFailure(t *testing.T) {
89 client := &recordingTelemetryClient{}
90 ctx := newTelemetryContext(client, "algolia indices list")
91
92 trackCommandCompleted(ctx, &cobra.Command{Use: "list"}, exitError, errors.New("boom"), time.Second)
93
94 if len(client.events) != 1 {
95 t.Fatalf("expected 1 event, got %d", len(client.events))
96 }
97 props := client.events[0].props
98 if props["succeeded"] != false {
99 t.Errorf("succeeded = %v, want false", props["succeeded"])
100 }
101 if props["exit_code"] != 1 {
102 t.Errorf("exit_code = %v, want 1", props["exit_code"])
103 }
104 if props["error_class"] != "*errors.errorString" {
105 t.Errorf("error_class = %v, want *errors.errorString", props["error_class"])
106 }
107 if props["user_cancelled"] != false {
108 t.Errorf("user_cancelled = %v, want false", props["user_cancelled"])
109 }
110}
111
112func TestPrintError(t *testing.T) {
113 cmd := &cobra.Command{}

Callers

nothing calls this directly

Calls 3

newTelemetryContextFunction · 0.85
trackCommandCompletedFunction · 0.85
ErrorfMethod · 0.65

Tested by

no test coverage detected