MCPcopy Create free account
hub / github.com/cli/cli / TestFlagRecordTelemetry

Function TestFlagRecordTelemetry

internal/attachments/flags_test.go:93–143  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

91}
92
93func 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
145func TestFlagUserAssets(t *testing.T) {
146 tests := []struct {

Callers

nothing calls this directly

Calls 5

attachCmdFunction · 0.85
RecordTelemetryMethod · 0.80
EmptyMethod · 0.80
EqualMethod · 0.80
RunMethod · 0.65

Tested by

no test coverage detected