(t *testing.T)
| 856 | } |
| 857 | |
| 858 | func Test_refreshRun_recordsTelemetry(t *testing.T) { |
| 859 | cfg, _ := config.NewIsolatedTestConfig(t, "") |
| 860 | _, err := cfg.Authentication().Login("github.com", "test-user", "abc123", "https", false) |
| 861 | require.NoError(t, err) |
| 862 | |
| 863 | recorder := &telemetry.InvocationRecorderSpy{} |
| 864 | ios, _, _, _ := iostreams.Test() |
| 865 | ios.SetStdinTTY(false) |
| 866 | ios.SetStdoutTTY(false) |
| 867 | |
| 868 | opts := &RefreshOptions{ |
| 869 | IO: ios, |
| 870 | Hostname: "github.com", |
| 871 | Telemetry: recorder, |
| 872 | ResetScopes: true, |
| 873 | Config: func() (gh.Config, error) { |
| 874 | return cfg, nil |
| 875 | }, |
| 876 | AuthFlow: func(_ *http.Client, _ *iostreams.IOStreams, _ string, _ []string, _, _, _ bool) (*authflow.AuthResult, error) { |
| 877 | return &authflow.AuthResult{Token: "xyz456", Username: "test-user"}, nil |
| 878 | }, |
| 879 | PlainHttpClient: func() (*http.Client, error) { |
| 880 | return &http.Client{Transport: &httpmock.Registry{}}, nil |
| 881 | }, |
| 882 | Prompter: &prompter.PrompterMock{}, |
| 883 | helperConfig: &gitcredentials.FakeHelperConfig{ |
| 884 | SelfExecutablePath: "/path/to/gh", |
| 885 | Helpers: map[string]gitcredentials.Helper{}, |
| 886 | }, |
| 887 | } |
| 888 | |
| 889 | require.NoError(t, refreshRun(opts)) |
| 890 | |
| 891 | events := recorder.Events() |
| 892 | require.Len(t, events, 1) |
| 893 | assert.Equal(t, ghtelemetry.SAMPLE_ALL, recorder.LastSampleRate) |
| 894 | dims := events[0].Dimensions |
| 895 | assert.Equal(t, "auth_invocation", events[0].Type) |
| 896 | assert.Equal(t, "refresh", dims["auth_command"]) |
| 897 | assert.Equal(t, "false", dims["expiring_requested"]) |
| 898 | assert.Equal(t, "false", dims["expiring_setup_cred_helper_cancelled"]) |
| 899 | assert.Equal(t, "https", dims["git_protocol"]) |
| 900 | assert.Equal(t, "false", dims["expiring_received"]) |
| 901 | assert.Equal(t, "true", dims["auth_success"]) |
| 902 | // Helper telemetry is recorded even for this non-interactive refresh. No helper is configured and no setup runs, |
| 903 | // so before and after are both "none". |
| 904 | assert.Equal(t, "none", dims["git_credential_helper_before"]) |
| 905 | assert.Equal(t, "none", dims["git_credential_helper_after"]) |
| 906 | assert.Contains(t, []string{"keyring", "plaintext"}, dims["storage_type"]) |
| 907 | } |
| 908 | |
| 909 | func Test_refreshRun_recordsTelemetryOnFailure(t *testing.T) { |
| 910 | // Telemetry must reflect how far the refresh got: an issued expiring token is recorded even when storing it fails, |
nothing calls this directly
no test coverage detected