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

Function TestLogin_recordsAuthTelemetry

pkg/cmd/auth/shared/login_flow_test.go:687–741  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

685}
686
687func TestLogin_recordsAuthTelemetry(t *testing.T) {
688 // An interactive https login to github.com that configures gh as the credential helper should record a complete
689 // auth_invocation event.
690 ios, _, _, _ := iostreams.Test()
691 recorder := &telemetry.InvocationRecorderSpy{}
692
693 opts := &LoginOptions{
694 IO: ios,
695 Config: tinyConfig{},
696 HTTPClient: &http.Client{},
697 Hostname: "github.com",
698 Interactive: true,
699 GitProtocol: "https",
700 Telemetry: recorder,
701 Prompter: &prompter.PrompterMock{
702 SelectFunc: func(prompt, _ string, opts []string) (int, error) {
703 if prompt == "How would you like to authenticate GitHub CLI?" {
704 return prompter.IndexFor(opts, "Login with a web browser")
705 }
706 return -1, prompter.NoSuchPromptErr(prompt)
707 },
708 },
709 AuthFlow: func(_ *http.Client, _ string, _ *iostreams.IOStreams, _ string, _ []string, _ bool, _ browser.Browser, _, _ bool) (*authflow.AuthResult, error) {
710 return &authflow.AuthResult{Token: "ATOKEN", Username: "monalisa"}, nil
711 },
712 CredentialFlow: &GitCredentialFlow{
713 Prompter: &prompter.PrompterMock{
714 ConfirmFunc: func(prompt string, _ bool) (bool, error) {
715 return true, nil
716 },
717 },
718 HelperConfig: &gitcredentials.FakeHelperConfig{
719 SelfExecutablePath: "/path/to/gh",
720 Helpers: map[string]gitcredentials.Helper{},
721 },
722 },
723 }
724
725 require.NoError(t, Login(opts))
726
727 events := recorder.Events()
728 require.Len(t, events, 1)
729 assert.Equal(t, ghtelemetry.SAMPLE_ALL, recorder.LastSampleRate)
730 dims := events[0].Dimensions
731 assert.Equal(t, "auth_invocation", events[0].Type)
732 assert.Equal(t, "login", dims["auth_command"])
733 assert.Equal(t, "false", dims["expiring_requested"])
734 assert.Equal(t, "false", dims["expiring_setup_cred_helper_cancelled"])
735 assert.Equal(t, "https", dims["git_protocol"])
736 assert.Equal(t, "none", dims["git_credential_helper_before"])
737 assert.Equal(t, "ours", dims["git_credential_helper_after"])
738 assert.Equal(t, "false", dims["expiring_received"])
739 assert.Equal(t, "keyring", dims["storage_type"])
740 assert.Equal(t, "true", dims["auth_success"])
741}
742
743func TestLogin_recordsAuthTelemetryOnFailure(t *testing.T) {
744 // Telemetry must reflect how far the login got: an issued expiring token is recorded even when storing it fails,

Callers

nothing calls this directly

Calls 7

TestFunction · 0.92
IndexForFunction · 0.92
NoSuchPromptErrFunction · 0.92
LoginFunction · 0.85
EventsMethod · 0.80
EqualMethod · 0.80
LenMethod · 0.65

Tested by

no test coverage detected