(t *testing.T)
| 91 | } |
| 92 | |
| 93 | func TestFlagRecordTelemetry(t *testing.T) { |
| 94 | tests := []struct { |
| 95 | name string |
| 96 | input string |
| 97 | wantEvent bool |
| 98 | wantCount int64 |
| 99 | }{ |
| 100 | { |
| 101 | name: "flag not passed", |
| 102 | input: "", |
| 103 | }, |
| 104 | { |
| 105 | name: "one attachment", |
| 106 | input: "--attach ./first.png", |
| 107 | wantEvent: true, |
| 108 | wantCount: 1, |
| 109 | }, |
| 110 | { |
| 111 | name: "several attachments before validation", |
| 112 | input: "--attach ./first.png --attach ./second.png --attach ./third.png", |
| 113 | wantEvent: true, |
| 114 | wantCount: 3, |
| 115 | }, |
| 116 | } |
| 117 | |
| 118 | for _, tt := range tests { |
| 119 | t.Run(tt.name, func(t *testing.T) { |
| 120 | _, attachFlag := attachCmd(t, tt.input) |
| 121 | recorder := &telemetry.CommandRecorderSpy{} |
| 122 | |
| 123 | attachFlag.RecordTelemetry("gh issue comment", recorder) |
| 124 | |
| 125 | if !tt.wantEvent { |
| 126 | assert.Empty(t, recorder.Events) |
| 127 | assert.Zero(t, recorder.LastSampleRate) |
| 128 | return |
| 129 | } |
| 130 | |
| 131 | require.Equal(t, ghtelemetry.SAMPLE_ALL, recorder.LastSampleRate) |
| 132 | require.Equal(t, []ghtelemetry.Event{{ |
| 133 | Type: "attachment_invocation", |
| 134 | Dimensions: ghtelemetry.Dimensions{ |
| 135 | "command": "gh issue comment", |
| 136 | }, |
| 137 | Measures: ghtelemetry.Measures{ |
| 138 | "attach_count": tt.wantCount, |
| 139 | }, |
| 140 | }}, recorder.Events) |
| 141 | }) |
| 142 | } |
| 143 | } |
| 144 | |
| 145 | func TestFlagUserAssets(t *testing.T) { |
| 146 | tests := []struct { |
nothing calls this directly
no test coverage detected