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

Function TestRecordTelemetryForSubcommands

pkg/cmdutil/telemetry_test.go:238–267  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

236}
237
238func TestRecordTelemetryForSubcommands(t *testing.T) {
239 t.Parallel()
240
241 // Given a command tree instrumented from its root
242 recorder := &telemetry.EventRecorderSpy{}
243 root := &cobra.Command{Use: "gh"}
244 parent := &cobra.Command{Use: "pr"}
245 child := &cobra.Command{
246 Use: "list",
247 RunE: func(cmd *cobra.Command, args []string) error { return nil },
248 }
249 root.AddCommand(parent)
250 root.AddCommand(&cobra.Command{
251 Use: "version",
252 RunE: func(cmd *cobra.Command, args []string) error { return nil },
253 })
254 parent.AddCommand(child)
255 root.SetArgs([]string{"pr", "list"})
256 cmdutil.RecordTelemetryForSubcommands(root, recorder)
257
258 // When Cobra executes a nested command
259 _, err := root.ExecuteC()
260
261 // Then only the invoked descendant is recorded
262 require.NoError(t, err)
263 events := recorder.Events()
264 require.Len(t, events, 1)
265 assert.Equal(t, "command_invocation", events[0].Type)
266 assert.Equal(t, "gh pr list", events[0].Dimensions["command"])
267}

Callers

nothing calls this directly

Calls 4

EventsMethod · 0.95
EqualMethod · 0.80
LenMethod · 0.65

Tested by

no test coverage detected