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

Function TestNewCmdApiTelemetry

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

Source from the content-addressed store, hash-verified

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