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

Function TestNewCmdApiTelemetry

pkg/cmd/api/api_test.go:428–455  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

426}
427
428func TestNewCmdApiTelemetry(t *testing.T) {
429 server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
430 w.Header().Set("Content-Type", "application/json")
431 fmt.Fprint(w, "{}")
432 }))
433 t.Cleanup(server.Close)
434
435 var payload telemetry.SendTelemetryPayload
436 recorder := telemetry.NewService(func(p telemetry.SendTelemetryPayload) {
437 payload = p
438 })
439 recorder.Record(ghtelemetry.Event{Type: "command"})
440
441 ios, _, _, _ := iostreams.Test()
442 f := &cmdutil.Factory{
443 Config: func() (gh.Config, error) { return config.NewMockConfig(), nil },
444 IOStreams: ios,
445 TelemetryDisabler: recorder,
446 }
447 cmd := NewCmdApi(f, nil)
448 cmd.SetArgs([]string{server.URL})
449
450 _, err := cmd.ExecuteC()
451 require.NoError(t, err)
452 recorder.Finish()
453
454 assert.Empty(t, payload.Events)
455}
456
457func Test_apiRun(t *testing.T) {
458 tests := []struct {

Callers

nothing calls this directly

Calls 8

FinishMethod · 0.95
NewServiceFunction · 0.92
TestFunction · 0.92
NewMockConfigFunction · 0.92
NewCmdApiFunction · 0.85
EmptyMethod · 0.80
SetMethod · 0.65
RecordMethod · 0.65

Tested by

no test coverage detected