(t *testing.T)
| 24 | ) |
| 25 | |
| 26 | func TestTrackCreateOutcome(t *testing.T) { |
| 27 | tests := []struct { |
| 28 | name string |
| 29 | result createResult |
| 30 | err error |
| 31 | wantEvent string |
| 32 | wantReason any |
| 33 | }{ |
| 34 | { |
| 35 | name: "created", |
| 36 | result: createResult{created: true, region: "us-east", plan: "free"}, |
| 37 | wantEvent: telemetry.EventApplicationCreateCompleted, |
| 38 | }, |
| 39 | { |
| 40 | name: "declined terms", |
| 41 | result: createResult{abortReason: telemetry.AbortReasonDeclinedTerms}, |
| 42 | wantEvent: telemetry.EventApplicationCreateAborted, |
| 43 | wantReason: telemetry.AbortReasonDeclinedTerms, |
| 44 | }, |
| 45 | { |
| 46 | name: "billing wall with error", |
| 47 | result: createResult{abortReason: telemetry.AbortReasonBillingRequired}, |
| 48 | err: errors.New("payment method required"), |
| 49 | wantEvent: telemetry.EventApplicationCreateAborted, |
| 50 | wantReason: telemetry.AbortReasonBillingRequired, |
| 51 | }, |
| 52 | { |
| 53 | name: "user cancellation", |
| 54 | err: cmdutil.ErrCancel, |
| 55 | wantEvent: telemetry.EventApplicationCreateAborted, |
| 56 | wantReason: telemetry.AbortReasonCancelled, |
| 57 | }, |
| 58 | { |
| 59 | name: "failure", |
| 60 | err: errors.New("boom"), |
| 61 | wantEvent: telemetry.EventApplicationCreateFailed, |
| 62 | }, |
| 63 | } |
| 64 | |
| 65 | for _, tt := range tests { |
| 66 | t.Run(tt.name, func(t *testing.T) { |
| 67 | client := &telemetrytest.RecordingClient{} |
| 68 | ctx := telemetry.WithTelemetryClient(context.Background(), client) |
| 69 | |
| 70 | trackCreateOutcome(ctx, telemetry.NewFlowTracker(), tt.result, tt.err) |
| 71 | |
| 72 | require.Len(t, client.Events, 1) |
| 73 | event := client.Events[0] |
| 74 | assert.Equal(t, tt.wantEvent, event.Name) |
| 75 | if tt.wantReason != nil { |
| 76 | assert.Equal(t, tt.wantReason, event.Properties["reason"]) |
| 77 | } |
| 78 | }) |
| 79 | } |
| 80 | } |
| 81 | |
| 82 | // seedToken installs an in-memory keyring with a valid token. |
| 83 | func seedToken(t *testing.T) { |
nothing calls this directly
no test coverage detected