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

Function TestNewCmdApiTelemetry

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

Source from the content-addressed store, hash-verified

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