(t *testing.T)
| 98 | } |
| 99 | |
| 100 | func TestAttachmentTelemetry(t *testing.T) { |
| 101 | t.Parallel() |
| 102 | |
| 103 | t.Run("flag not passed ignores operation updates", func(t *testing.T) { |
| 104 | t.Parallel() |
| 105 | |
| 106 | // Given a command with no attachment flag |
| 107 | _, attachFlag := attachCmd(t, "") |
| 108 | recorder := &telemetry.InvocationRecorderSpy{} |
| 109 | |
| 110 | // When an operation update is attempted without an attachment event |
| 111 | event := BeginTelemetry(recorder, "gh issue comment", attachFlag.Count()) |
| 112 | event.RecordOperations(UploadResult{AppendOperations: 1, ReplaceOperations: 1}) |
| 113 | |
| 114 | // Then no event or sampling promotion occurs |
| 115 | assert.Nil(t, event) |
| 116 | assert.Empty(t, recorder.Events()) |
| 117 | assert.Zero(t, recorder.LastSampleRate) |
| 118 | }) |
| 119 | |
| 120 | tests := []struct { |
| 121 | name string |
| 122 | input string |
| 123 | wantCount int64 |
| 124 | }{ |
| 125 | { |
| 126 | name: "one attachment", |
| 127 | input: "--attach ./first.png", |
| 128 | wantCount: 1, |
| 129 | }, |
| 130 | { |
| 131 | name: "several attachments before validation", |
| 132 | input: "--attach ./first.png --attach ./second.png --attach ./third.png", |
| 133 | wantCount: 3, |
| 134 | }, |
| 135 | { |
| 136 | name: "empty path counts before validation", |
| 137 | input: `--attach ""`, |
| 138 | wantCount: 1, |
| 139 | }, |
| 140 | { |
| 141 | name: "over limit counts before validation", |
| 142 | input: strings.Repeat("--attach ./missing.png ", maxAttachments+1), |
| 143 | wantCount: maxAttachments + 1, |
| 144 | }, |
| 145 | } |
| 146 | |
| 147 | for _, tt := range tests { |
| 148 | t.Run(tt.name, func(t *testing.T) { |
| 149 | t.Parallel() |
| 150 | |
| 151 | // Given raw attachment inputs that have not been validated |
| 152 | _, attachFlag := attachCmd(t, tt.input) |
| 153 | recorder := &telemetry.InvocationRecorderSpy{} |
| 154 | |
| 155 | // When an attachment event is recorded without any upload operations |
| 156 | BeginTelemetry(recorder, "gh issue comment", attachFlag.Count()) |
| 157 |
nothing calls this directly
no test coverage detected