diff --git a/cmd/gen-docs/main.go b/cmd/gen-docs/main.go index cb76f422087..d6a317f595f 100644 --- a/cmd/gen-docs/main.go +++ b/cmd/gen-docs/main.go @@ -51,7 +51,7 @@ func run(args []string) error { IOStreams: ios, Browser: &browser{}, Config: func() (gh.Config, error) { - return config.NewFromString(""), nil + return config.NewMockConfigFromString(""), nil }, ExtensionManager: &em{}, }, &telemetry.NoOpService{}, "", "") diff --git a/git/client_test.go b/git/client_test.go index 7ffee2dc93c..ca3ba580f87 100644 --- a/git/client_test.go +++ b/git/client_test.go @@ -110,6 +110,7 @@ func TestClientAuthenticatedCommand(t *testing.T) { } func TestClientRemotes(t *testing.T) { + IsolateConfig(t) tempDir := t.TempDir() initRepo(t, tempDir) gitDir := filepath.Join(tempDir, ".git") @@ -149,6 +150,7 @@ func TestClientRemotes(t *testing.T) { } func TestClientRemotes_no_resolved_remote(t *testing.T) { + IsolateConfig(t) tempDir := t.TempDir() initRepo(t, tempDir) gitDir := filepath.Join(tempDir, ".git") @@ -708,6 +710,7 @@ func createCommitsCommandContext(t *testing.T, testData stubbedCommitsCommandDat } func TestClientLastCommit(t *testing.T) { + IsolateConfig(t) client := Client{ RepoDir: "./fixtures/simple.git", } @@ -718,6 +721,7 @@ func TestClientLastCommit(t *testing.T) { } func TestClientCommitBody(t *testing.T) { + IsolateConfig(t) client := Client{ RepoDir: "./fixtures/simple.git", } diff --git a/git/test.go b/git/test.go new file mode 100644 index 00000000000..aa873a142b7 --- /dev/null +++ b/git/test.go @@ -0,0 +1,25 @@ +package git + +import ( + "path/filepath" + "testing" +) + +// IsolateConfig prevents the ambient git configuration from reaching tests that shell +// out to real git. +// +// https://git-scm.com/docs/git-config#ENVIRONMENT +func IsolateConfig(t *testing.T) { + t.Helper() + + // Point the global config at an empty file and ignore the system one. + t.Setenv("GIT_CONFIG_GLOBAL", filepath.Join(t.TempDir(), ".gitconfig")) + t.Setenv("GIT_CONFIG_NOSYSTEM", "true") + + // Config from these vars is command line scope, which outranks the global and + // system files, so redirecting those files alone leaves it in place. Tools that + // wrap git inject config this way, and an inherited safe.bareRepository=explicit + // makes git refuse to open a bare repository at all. + t.Setenv("GIT_CONFIG_COUNT", "") + t.Setenv("GIT_CONFIG_PARAMETERS", "") +} diff --git a/internal/config/auth_config_test.go b/internal/config/auth_config_test.go index ca5f7e584cb..ad5e3732a26 100644 --- a/internal/config/auth_config_test.go +++ b/internal/config/auth_config_test.go @@ -12,7 +12,7 @@ import ( // Note that NewIsolatedTestConfig sets up a Mock keyring as well func newTestAuthConfig(t *testing.T) *AuthConfig { - cfg, _ := NewIsolatedTestConfig(t) + cfg, _ := NewIsolatedTestConfig(t, "") return &AuthConfig{cfg: cfg.cfg} } diff --git a/internal/config/stub.go b/internal/config/test.go similarity index 62% rename from internal/config/stub.go rename to internal/config/test.go index fe5e277b62b..6f096e9436d 100644 --- a/internal/config/stub.go +++ b/internal/config/test.go @@ -13,12 +13,23 @@ import ( ghConfig "github.com/cli/go-gh/v2/pkg/config" ) -func NewBlankConfig() *ghmock.ConfigMock { - return NewFromString(defaultConfigStr) +// NewMockConfig returns a mock config populated with gh's default config file. +// See NewMockConfigFromString for when to prefer a mock over NewIsolatedTestConfig. +func NewMockConfig() *ghmock.ConfigMock { + return NewMockConfigFromString(defaultConfigStr) } -func NewFromString(cfgStr string) *ghmock.ConfigMock { - c := ghConfig.ReadFromString(cfgStr) +// NewMockConfigFromString returns a mock config populated from cfgString, for tests +// that need to stub config behaviour by assigning to the mock's function fields. +// +// The mock answers host, token, and default host lookups from cfgString alone, so it +// ignores both the config files on disk and the environment. It never writes anything. +// +// Prefer NewIsolatedTestConfig when the code under test exercises the real config +// implementation, writes config, or reads the auth environment variables directly, +// since none of those go through the mock. +func NewMockConfigFromString(cfgString string) *ghmock.ConfigMock { + c := ghConfig.ReadFromString(cfgString) cfg := cfg{c} mock := &ghmock.ConfigMock{} mock.GetOrDefaultFunc = func(host, key string) o.Option[gh.ConfigEntry] { @@ -97,15 +108,39 @@ func NewFromString(cfgStr string) *ghmock.ConfigMock { return mock } -// NewIsolatedTestConfig sets up a Mock keyring, creates a blank config -// overwrites the ghConfig.Read function that returns a singleton config -// in the real implementation, sets the GH_CONFIG_DIR env var so that -// any call to Write goes to a different location on disk, and then returns -// the blank config and a function that reads any data written to disk. -func NewIsolatedTestConfig(t *testing.T) (*cfg, func(io.Writer, io.Writer)) { +// NewIsolatedTestConfig returns the real config implementation, built from cfgString +// and isolated from the machine running the tests. Pass "" for a config with no +// content. It also returns a function that reads back anything written to disk. +// +// Use it when the code under test exercises real config behaviour: writing config, +// logging in and out, or reading the auth environment variables directly. Prefer +// NewMockConfigFromString when the test only needs to stub config lookups. +// +// Isolation covers all three places config comes from. It mocks the keyring, replaces +// the ghConfig.Read singleton so each test gets its own config, points GH_CONFIG_DIR at +// a temp dir so writes stay off the real config, and clears the environment variables +// that go-gh consults for authentication and host resolution. +// +// Callers that want one of the auth env vars set should set it after calling this, +// otherwise the value is cleared along with the ambient environment. +func NewIsolatedTestConfig(t *testing.T, cfgString string) (*cfg, func(io.Writer, io.Writer)) { keyring.MockInit() - c := ghConfig.ReadFromString("") + // go-gh reads these ahead of any stored config, so isolating the config file is + // not enough on its own. A developer with GH_TOKEN exported, or any CI image that + // provides one, would otherwise see an authenticated config here and fail tests + // that assert on the logged out state. + for _, key := range []string{ + "GH_TOKEN", + "GITHUB_TOKEN", + "GH_ENTERPRISE_TOKEN", + "GITHUB_ENTERPRISE_TOKEN", + "GH_HOST", + } { + t.Setenv(key, "") + } + + c := ghConfig.ReadFromString(cfgString) cfg := cfg{c} // The real implementation of config.Read uses a sync.Once diff --git a/internal/ghcmd/cmd_test.go b/internal/ghcmd/cmd_test.go index d389bd7448f..fc05e94cddf 100644 --- a/internal/ghcmd/cmd_test.go +++ b/internal/ghcmd/cmd_test.go @@ -142,7 +142,7 @@ func Test_newIOStreams_pager(t *testing.T) { if tt.config != nil { cfg = tt.config } else { - cfg = config.NewBlankConfig() + cfg = config.NewMockConfig() } io := newIOStreams(cfg) assert.Equal(t, tt.wantPager, io.GetPager()) @@ -183,7 +183,7 @@ func Test_newIOStreams_prompt(t *testing.T) { if tt.config != nil { cfg = tt.config } else { - cfg = config.NewBlankConfig() + cfg = config.NewMockConfig() } io := newIOStreams(cfg) assert.Equal(t, tt.promptDisabled, io.GetNeverPrompt()) @@ -259,7 +259,7 @@ func Test_newIOStreams_spinnerDisabled(t *testing.T) { if tt.config != nil { cfg = tt.config } else { - cfg = config.NewBlankConfig() + cfg = config.NewMockConfig() } io := newIOStreams(cfg) assert.Equal(t, tt.spinnerDisabled, io.GetSpinnerDisabled()) @@ -325,7 +325,7 @@ func Test_newIOStreams_accessiblePrompterEnabled(t *testing.T) { if tt.config != nil { cfg = tt.config } else { - cfg = config.NewBlankConfig() + cfg = config.NewMockConfig() } io := newIOStreams(cfg) assert.Equal(t, tt.accessiblePrompterEnabled, io.AccessiblePrompterEnabled()) @@ -401,7 +401,7 @@ func Test_newIOStreams_colorLabels(t *testing.T) { if tt.config != nil { cfg = tt.config } else { - cfg = config.NewBlankConfig() + cfg = config.NewMockConfig() } io := newIOStreams(cfg) assert.Equal(t, tt.colorLabelsEnabled, io.ColorLabels()) @@ -411,109 +411,107 @@ func Test_newIOStreams_colorLabels(t *testing.T) { func Test_mightBeGHESUser(t *testing.T) { tests := []struct { - name string - env map[string]string - config gh.Config - want bool + name string + env map[string]string + cfgString string + want bool }{ { - name: "GH_ENTERPRISE_TOKEN set", - env: map[string]string{"GH_ENTERPRISE_TOKEN": "some-token"}, - config: config.NewBlankConfig(), - want: true, + name: "GH_ENTERPRISE_TOKEN set", + env: map[string]string{"GH_ENTERPRISE_TOKEN": "some-token"}, + want: true, }, { - name: "GITHUB_ENTERPRISE_TOKEN set", - env: map[string]string{"GITHUB_ENTERPRISE_TOKEN": "some-token"}, - config: config.NewBlankConfig(), - want: true, + name: "GITHUB_ENTERPRISE_TOKEN set", + env: map[string]string{"GITHUB_ENTERPRISE_TOKEN": "some-token"}, + want: true, }, { - name: "no env vars, config has enterprise host", - config: config.NewFromString("hosts:\n ghes.example.com:\n oauth_token: abc123\n"), - want: true, + name: "no env vars, config has enterprise host", + cfgString: "hosts:\n ghes.example.com:\n oauth_token: abc123\n", + want: true, }, { - name: "no env vars, config has only github.com", - config: config.NewFromString("hosts:\n github.com:\n oauth_token: abc123\n"), - want: false, + name: "no env vars, config has only github.com", + cfgString: "hosts:\n github.com:\n oauth_token: abc123\n", + want: false, }, { - name: "no env vars, config has no hosts", - config: config.NewBlankConfig(), - want: false, + name: "no env vars, config has no hosts", + want: false, }, { - name: "no env vars, config has github.com and enterprise host", - config: config.NewFromString("hosts:\n github.com:\n oauth_token: abc123\n ghes.example.com:\n oauth_token: def456\n"), - want: true, + name: "no env vars, config has github.com and enterprise host", + cfgString: "hosts:\n github.com:\n oauth_token: abc123\n ghes.example.com:\n oauth_token: def456\n", + want: true, }, { - name: "no env vars, config has tenancy host", - config: config.NewFromString("hosts:\n my-company.ghe.com:\n oauth_token: abc123\n"), - want: false, + name: "no env vars, config has tenancy host", + cfgString: "hosts:\n my-company.ghe.com:\n oauth_token: abc123\n", + want: false, }, { - name: "GH_HOST set to enterprise host", - env: map[string]string{"GH_HOST": "ghes.example.com"}, - config: config.NewBlankConfig(), - want: true, + name: "GH_HOST set to enterprise host", + env: map[string]string{"GH_HOST": "ghes.example.com"}, + want: true, }, { - name: "GH_HOST set to github.com", - env: map[string]string{"GH_HOST": "github.com"}, - config: config.NewBlankConfig(), - want: false, + name: "GH_HOST set to github.com", + env: map[string]string{"GH_HOST": "github.com"}, + want: false, }, { - name: "GH_HOST set to tenancy host", - env: map[string]string{"GH_HOST": "my-company.ghe.com"}, - config: config.NewBlankConfig(), - want: false, + name: "GH_HOST set to tenancy host", + env: map[string]string{"GH_HOST": "my-company.ghe.com"}, + want: false, }, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { + cfg, _ := config.NewIsolatedTestConfig(t, tt.cfgString) + + // Set after isolating the config, which clears the auth env vars. for k, v := range tt.env { t.Setenv(k, v) } - got := mightBeGHESUser(tt.config) + + got := mightBeGHESUser(cfg) assert.Equal(t, tt.want, got) }) } } func pagerConfig() gh.Config { - return config.NewFromString("pager: CONFIG_PAGER") + return config.NewMockConfigFromString("pager: CONFIG_PAGER") } func disablePromptConfig() gh.Config { - return config.NewFromString("prompt: disabled") + return config.NewMockConfigFromString("prompt: disabled") } func enableAccessiblePrompterConfig() gh.Config { - return config.NewFromString("accessible_prompter: enabled") + return config.NewMockConfigFromString("accessible_prompter: enabled") } func disableAccessiblePrompterConfig() gh.Config { - return config.NewFromString("accessible_prompter: disabled") + return config.NewMockConfigFromString("accessible_prompter: disabled") } func disableSpinnersConfig() gh.Config { - return config.NewFromString("spinner: disabled") + return config.NewMockConfigFromString("spinner: disabled") } func enableSpinnersConfig() gh.Config { - return config.NewFromString("spinner: enabled") + return config.NewMockConfigFromString("spinner: enabled") } func disableColorLabelsConfig() gh.Config { - return config.NewFromString("color_labels: disabled") + return config.NewMockConfigFromString("color_labels: disabled") } func enableColorLabelsConfig() gh.Config { - return config.NewFromString("color_labels: enabled") + return config.NewMockConfigFromString("color_labels: enabled") } func Test_authRecoveryCommand(t *testing.T) { @@ -555,7 +553,7 @@ func Test_authRecoveryCommand(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - authCfg := config.NewBlankConfig().Authentication() + authCfg := config.NewMockConfig().Authentication() authCfg.SetActiveToken(tt.token, tt.source) cfg := &ghmock.ConfigMock{ AuthenticationFunc: func() gh.AuthConfig { diff --git a/pkg/cmd/agent-task/agent_task_test.go b/pkg/cmd/agent-task/agent_task_test.go index dd4fe21b01e..a2dcf60884c 100644 --- a/pkg/cmd/agent-task/agent_task_test.go +++ b/pkg/cmd/agent-task/agent_task_test.go @@ -14,7 +14,7 @@ import ( // setupMockOAuthConfig configures a blank config with a default host and optional token behavior. func setupMockOAuthConfig(t *testing.T, tokenSource string) gh.Config { t.Helper() - c := config.NewBlankConfig() + c := config.NewMockConfig() switch tokenSource { case "oauth_token": // valid OAuth device flow token stored in config @@ -67,7 +67,7 @@ func TestNewCmdAgentTask(t *testing.T) { { name: "github.com oauth is accepted and enterprise token ignored", customConfig: func() (gh.Config, error) { - c := config.NewBlankConfig() + c := config.NewMockConfig() c.Set("something.ghes.com", "oauth_token", "ghe_ENTERPRISE123") c.Set("github.com", "oauth_token", "gho_OAUTH123") return c, nil diff --git a/pkg/cmd/alias/delete/delete_test.go b/pkg/cmd/alias/delete/delete_test.go index 9bc89830a7a..880192bf7a1 100644 --- a/pkg/cmd/alias/delete/delete_test.go +++ b/pkg/cmd/alias/delete/delete_test.go @@ -161,7 +161,7 @@ func TestDeleteRun(t *testing.T) { ios.SetStderrTTY(tt.isTTY) tt.opts.IO = ios - cfg := config.NewFromString(tt.config) + cfg := config.NewMockConfigFromString(tt.config) cfg.WriteFunc = func() error { return nil } diff --git a/pkg/cmd/alias/imports/import_test.go b/pkg/cmd/alias/imports/import_test.go index c2ae16e7a16..e775614a30b 100644 --- a/pkg/cmd/alias/imports/import_test.go +++ b/pkg/cmd/alias/imports/import_test.go @@ -309,7 +309,7 @@ func TestImportRun(t *testing.T) { tt.opts.IO = ios readConfigs := config.StubWriteConfig(t) - cfg := config.NewFromString(tt.initConfig) + cfg := config.NewMockConfigFromString(tt.initConfig) tt.opts.Config = func() (gh.Config, error) { return cfg, nil } diff --git a/pkg/cmd/alias/list/list_test.go b/pkg/cmd/alias/list/list_test.go index 0af36a38d08..df15fbf8e1d 100644 --- a/pkg/cmd/alias/list/list_test.go +++ b/pkg/cmd/alias/list/list_test.go @@ -58,7 +58,7 @@ func TestAliasList(t *testing.T) { } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - cfg := config.NewFromString(tt.config) + cfg := config.NewMockConfigFromString(tt.config) ios, _, stdout, stderr := iostreams.Test() ios.SetStdoutTTY(tt.isTTY) diff --git a/pkg/cmd/alias/set/set_test.go b/pkg/cmd/alias/set/set_test.go index 40198d878f6..4b22faa8075 100644 --- a/pkg/cmd/alias/set/set_test.go +++ b/pkg/cmd/alias/set/set_test.go @@ -281,7 +281,7 @@ func TestSetRun(t *testing.T) { fmt.Fprint(stdin, tt.stdin) } - cfg := config.NewBlankConfig() + cfg := config.NewMockConfig() cfg.WriteFunc = func() error { return nil } diff --git a/pkg/cmd/api/api_test.go b/pkg/cmd/api/api_test.go index 33a45543579..90d8242cb26 100644 --- a/pkg/cmd/api/api_test.go +++ b/pkg/cmd/api/api_test.go @@ -740,7 +740,7 @@ func Test_apiRun(t *testing.T) { ios.SetStdoutTTY(tt.isatty) tt.options.IO = ios - tt.options.Config = func() (gh.Config, error) { return config.NewBlankConfig(), nil } + tt.options.Config = func() (gh.Config, error) { return config.NewMockConfig(), nil } tt.options.HttpClient = func() (*http.Client, error) { var tr roundTripper = func(req *http.Request) (*http.Response, error) { resp := tt.httpResponse @@ -820,7 +820,7 @@ func Test_apiRun_paginationREST(t *testing.T) { return &http.Client{Transport: tr}, nil }, Config: func() (gh.Config, error) { - return config.NewBlankConfig(), nil + return config.NewMockConfig(), nil }, RequestMethod: "GET", @@ -892,7 +892,7 @@ func Test_apiRun_arrayPaginationREST(t *testing.T) { return &http.Client{Transport: tr}, nil }, Config: func() (gh.Config, error) { - return config.NewBlankConfig(), nil + return config.NewMockConfig(), nil }, RequestMethod: "GET", @@ -964,7 +964,7 @@ func Test_apiRun_arrayPaginationREST_with_headers(t *testing.T) { return &http.Client{Transport: tr}, nil }, Config: func() (gh.Config, error) { - return config.NewBlankConfig(), nil + return config.NewMockConfig(), nil }, RequestMethod: "GET", @@ -1033,7 +1033,7 @@ func Test_apiRun_paginationGraphQL(t *testing.T) { return &http.Client{Transport: tr}, nil }, Config: func() (gh.Config, error) { - return config.NewBlankConfig(), nil + return config.NewMockConfig(), nil }, RawFields: []string{"foo=bar"}, @@ -1132,7 +1132,7 @@ func Test_apiRun_paginationGraphQL_slurp(t *testing.T) { return &http.Client{Transport: tr}, nil }, Config: func() (gh.Config, error) { - return config.NewBlankConfig(), nil + return config.NewMockConfig(), nil }, RawFields: []string{"foo=bar"}, @@ -1244,7 +1244,7 @@ func Test_apiRun_paginated_template(t *testing.T) { return &http.Client{Transport: tr}, nil }, Config: func() (gh.Config, error) { - return config.NewBlankConfig(), nil + return config.NewMockConfig(), nil }, RequestMethod: "POST", @@ -1291,7 +1291,7 @@ func Test_apiRun_DELETE(t *testing.T) { err := apiRun(&ApiOptions{ IO: ios, Config: func() (gh.Config, error) { - return config.NewBlankConfig(), nil + return config.NewMockConfig(), nil }, HttpClient: func() (*http.Client, error) { var tr roundTripper = func(req *http.Request) (*http.Response, error) { @@ -1320,7 +1320,7 @@ func Test_apiRun_HEAD(t *testing.T) { err := apiRun(&ApiOptions{ IO: ios, Config: func() (gh.Config, error) { - return config.NewBlankConfig(), nil + return config.NewMockConfig(), nil }, HttpClient: func() (*http.Client, error) { var tr roundTripper = func(req *http.Request) (*http.Response, error) { @@ -1405,7 +1405,7 @@ func Test_apiRun_inputFile(t *testing.T) { return &http.Client{Transport: tr}, nil }, Config: func() (gh.Config, error) { - return config.NewBlankConfig(), nil + return config.NewMockConfig(), nil }, } @@ -1885,7 +1885,7 @@ func Test_apiRun_acceptHeader(t *testing.T) { tt.options.IO = ios tt.options.Config = func() (gh.Config, error) { - return config.NewBlankConfig(), nil + return config.NewMockConfig(), nil } var gotReq *http.Request diff --git a/pkg/cmd/attestation/verify/verify_integration_test.go b/pkg/cmd/attestation/verify/verify_integration_test.go index 195313b645e..137880e6f63 100644 --- a/pkg/cmd/attestation/verify/verify_integration_test.go +++ b/pkg/cmd/attestation/verify/verify_integration_test.go @@ -32,7 +32,7 @@ func TestVerifyIntegration(t *testing.T) { ios, _, _, _ := iostreams.Test() hc, err := factory.HttpClientFunc( - func() (gh.Config, error) { return config.NewBlankConfig(), nil }, + func() (gh.Config, error) { return config.NewMockConfig(), nil }, ios, "test", "", @@ -152,7 +152,7 @@ func TestVerifyIntegrationCustomIssuer(t *testing.T) { ios, _, _, _ := iostreams.Test() hc, err := factory.HttpClientFunc( - func() (gh.Config, error) { return config.NewBlankConfig(), nil }, + func() (gh.Config, error) { return config.NewMockConfig(), nil }, ios, "test", "", @@ -227,7 +227,7 @@ func TestVerifyIntegrationReusableWorkflow(t *testing.T) { TUFMetadataDir: o.Some(t.TempDir()), } - cfg := config.NewBlankConfig() + cfg := config.NewMockConfig() ios, _, _, _ := iostreams.Test() hc, err := factory.HttpClientFunc( func() (gh.Config, error) { return cfg, nil }, @@ -324,7 +324,7 @@ func TestVerifyIntegrationReusableWorkflowSignerWorkflow(t *testing.T) { TUFMetadataDir: o.Some(t.TempDir()), } - cfg := config.NewBlankConfig() + cfg := config.NewMockConfig() ios, _, _, _ := iostreams.Test() hc, err := factory.HttpClientFunc( func() (gh.Config, error) { return cfg, nil }, diff --git a/pkg/cmd/auth/login/login_test.go b/pkg/cmd/auth/login/login_test.go index 7ec17497359..f03792bc220 100644 --- a/pkg/cmd/auth/login/login_test.go +++ b/pkg/cmd/auth/login/login_test.go @@ -470,7 +470,7 @@ func Test_loginRun_nontty(t *testing.T) { ios.SetStdoutTTY(false) tt.opts.IO = ios - cfg, readConfigs := config.NewIsolatedTestConfig(t) + cfg, readConfigs := config.NewIsolatedTestConfig(t, "") if tt.cfgStubs != nil { tt.cfgStubs(t, cfg) } @@ -766,7 +766,7 @@ func Test_loginRun_Survey(t *testing.T) { tt.opts.IO = ios - cfg, readConfigs := config.NewIsolatedTestConfig(t) + cfg, readConfigs := config.NewIsolatedTestConfig(t, "") if tt.cfgStubs != nil { tt.cfgStubs(t, cfg) } diff --git a/pkg/cmd/auth/logout/logout_test.go b/pkg/cmd/auth/logout/logout_test.go index 02386c55b12..e7fe5504e83 100644 --- a/pkg/cmd/auth/logout/logout_test.go +++ b/pkg/cmd/auth/logout/logout_test.go @@ -311,7 +311,7 @@ func Test_logoutRun_tty(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - cfg, readConfigs := config.NewIsolatedTestConfig(t) + cfg, readConfigs := config.NewIsolatedTestConfig(t, "") for _, hostUsers := range tt.cfgHosts { for _, user := range hostUsers.users { @@ -506,7 +506,7 @@ func Test_logoutRun_nontty(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - cfg, readConfigs := config.NewIsolatedTestConfig(t) + cfg, readConfigs := config.NewIsolatedTestConfig(t, "") for _, hostUsers := range tt.cfgHosts { for _, user := range hostUsers.users { diff --git a/pkg/cmd/auth/refresh/refresh_test.go b/pkg/cmd/auth/refresh/refresh_test.go index 120f6efec60..9353de39e74 100644 --- a/pkg/cmd/auth/refresh/refresh_test.go +++ b/pkg/cmd/auth/refresh/refresh_test.go @@ -482,7 +482,7 @@ func Test_refreshRun(t *testing.T) { return token("xyz456"), username("test-user"), nil } - cfg, _ := config.NewIsolatedTestConfig(t) + cfg, _ := config.NewIsolatedTestConfig(t, "") for _, hostname := range tt.cfgHosts { _, err := cfg.Authentication().Login(hostname, "test-user", "abc123", "https", false) require.NoError(t, err) diff --git a/pkg/cmd/auth/setupgit/setupgit_test.go b/pkg/cmd/auth/setupgit/setupgit_test.go index 8d9dc2d2153..6561d6584dc 100644 --- a/pkg/cmd/auth/setupgit/setupgit_test.go +++ b/pkg/cmd/auth/setupgit/setupgit_test.go @@ -169,7 +169,7 @@ func Test_setupGitRun(t *testing.T) { ios.SetStdoutTTY(true) tt.opts.IO = ios - cfg, _ := config.NewIsolatedTestConfig(t) + cfg, _ := config.NewIsolatedTestConfig(t, "") if tt.cfgStubs != nil { tt.cfgStubs(t, cfg) } diff --git a/pkg/cmd/auth/shared/gitcredentials/helper_config_test.go b/pkg/cmd/auth/shared/gitcredentials/helper_config_test.go index 80ffac85a36..3dab8ad0945 100644 --- a/pkg/cmd/auth/shared/gitcredentials/helper_config_test.go +++ b/pkg/cmd/auth/shared/gitcredentials/helper_config_test.go @@ -2,7 +2,6 @@ package gitcredentials_test import ( "context" - "path/filepath" "runtime" "testing" @@ -13,19 +12,6 @@ import ( "github.com/stretchr/testify/require" ) -func withIsolatedGitConfig(t *testing.T) { - t.Helper() - - // https://git-scm.com/docs/git-config#ENVIRONMENT - // Set the global git config to a temporary file - tmpDir := t.TempDir() - configFile := filepath.Join(tmpDir, ".gitconfig") - t.Setenv("GIT_CONFIG_GLOBAL", configFile) - - // And disable git reading the system config - t.Setenv("GIT_CONFIG_NOSYSTEM", "true") -} - func configureTestCredentialHelper(t *testing.T, key string) { t.Helper() @@ -38,7 +24,7 @@ func configureTestCredentialHelper(t *testing.T, key string) { func TestHelperConfigContract(t *testing.T) { contract.HelperConfig{ NewHelperConfig: func(t *testing.T) shared.HelperConfig { - withIsolatedGitConfig(t) + git.IsolateConfig(t) return &gitcredentials.HelperConfig{ SelfExecutablePath: "/path/to/gh", @@ -54,7 +40,7 @@ func TestHelperConfigContract(t *testing.T) { // This is a whitebox test unlike the contract because although we don't use the exact configured command, it's // important that it is exactly right since git uses it. func TestSetsCorrectCommandInGitConfig(t *testing.T) { - withIsolatedGitConfig(t) + git.IsolateConfig(t) gc := &git.Client{} hc := &gitcredentials.HelperConfig{ diff --git a/pkg/cmd/auth/shared/gitcredentials/updater_test.go b/pkg/cmd/auth/shared/gitcredentials/updater_test.go index 10a9c5c6c55..06068093abc 100644 --- a/pkg/cmd/auth/shared/gitcredentials/updater_test.go +++ b/pkg/cmd/auth/shared/gitcredentials/updater_test.go @@ -43,7 +43,7 @@ func fillCredentials(t *testing.T) string { func TestUpdateAddsNewCredentials(t *testing.T) { // Given we have an isolated git config and we're using the built in store credential helper // https://git-scm.com/docs/git-credential-store - withIsolatedGitConfig(t) + git.IsolateConfig(t) configureStoreCredentialHelper(t) // When we add new credentials @@ -65,7 +65,7 @@ func TestUpdateReplacesOldCredentials(t *testing.T) { // Given we have an isolated git config and we're using the built in store credential helper // https://git-scm.com/docs/git-credential-store // and we have existing credentials - withIsolatedGitConfig(t) + git.IsolateConfig(t) configureStoreCredentialHelper(t) // When we replace old credentials diff --git a/pkg/cmd/auth/status/status_test.go b/pkg/cmd/auth/status/status_test.go index 87ee5f5e5a3..6e231825547 100644 --- a/pkg/cmd/auth/status/status_test.go +++ b/pkg/cmd/auth/status/status_test.go @@ -718,7 +718,7 @@ func Test_statusRun(t *testing.T) { ios.SetStdoutTTY(true) tt.opts.IO = ios - cfg, _ := config.NewIsolatedTestConfig(t) + cfg, _ := config.NewIsolatedTestConfig(t, "") if tt.cfgStubs != nil { tt.cfgStubs(t, cfg) } diff --git a/pkg/cmd/auth/switch/switch_test.go b/pkg/cmd/auth/switch/switch_test.go index 6ca77f44ca6..921a39d137b 100644 --- a/pkg/cmd/auth/switch/switch_test.go +++ b/pkg/cmd/auth/switch/switch_test.go @@ -373,7 +373,7 @@ func TestSwitchRun(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - cfg, readConfigs := config.NewIsolatedTestConfig(t) + cfg, readConfigs := config.NewIsolatedTestConfig(t, "") for k, v := range tt.env { t.Setenv(k, v) diff --git a/pkg/cmd/auth/token/token_test.go b/pkg/cmd/auth/token/token_test.go index 1d731f2ed17..165c169056d 100644 --- a/pkg/cmd/auth/token/token_test.go +++ b/pkg/cmd/auth/token/token_test.go @@ -58,7 +58,7 @@ func TestNewCmdToken(t *testing.T) { f := &cmdutil.Factory{ IOStreams: ios, Config: func() (gh.Config, error) { - cfg := config.NewBlankConfig() + cfg := config.NewMockConfig() return cfg, nil }, } @@ -165,11 +165,13 @@ func TestTokenRun(t *testing.T) { ios, _, stdout, _ := iostreams.Test() tt.opts.IO = ios + cfg, _ := config.NewIsolatedTestConfig(t, "") + + // Set after isolating the config, which clears the auth env vars. for k, v := range tt.env { t.Setenv(k, v) } - cfg, _ := config.NewIsolatedTestConfig(t) if tt.cfgStubs != nil { tt.cfgStubs(t, cfg) } @@ -252,7 +254,7 @@ func TestTokenRunSecureStorage(t *testing.T) { tt.opts.IO = ios tt.opts.SecureStorage = true - cfg, _ := config.NewIsolatedTestConfig(t) + cfg, _ := config.NewIsolatedTestConfig(t, "") if tt.cfgStubs != nil { tt.cfgStubs(t, cfg) } diff --git a/pkg/cmd/config/get/get_test.go b/pkg/cmd/config/get/get_test.go index 6320ffa16b9..12c88d5d8d6 100644 --- a/pkg/cmd/config/get/get_test.go +++ b/pkg/cmd/config/get/get_test.go @@ -44,7 +44,7 @@ func TestNewCmdConfigGet(t *testing.T) { t.Run(tt.name, func(t *testing.T) { f := &cmdutil.Factory{ Config: func() (gh.Config, error) { - return config.NewBlankConfig(), nil + return config.NewMockConfig(), nil }, } @@ -88,7 +88,7 @@ func Test_getRun(t *testing.T) { input: &GetOptions{ Key: "editor", Config: func() gh.Config { - cfg := config.NewBlankConfig() + cfg := config.NewMockConfig() cfg.Set("", "editor", "ed") return cfg }(), @@ -101,7 +101,7 @@ func Test_getRun(t *testing.T) { Hostname: "github.com", Key: "editor", Config: func() gh.Config { - cfg := config.NewBlankConfig() + cfg := config.NewMockConfig() cfg.Set("", "editor", "ed") cfg.Set("github.com", "editor", "vim") return cfg @@ -113,7 +113,7 @@ func Test_getRun(t *testing.T) { name: "non-existent key", input: &GetOptions{ Key: "non-existent", - Config: config.NewBlankConfig(), + Config: config.NewMockConfig(), }, err: nonExistentKeyError{key: "non-existent"}, }, diff --git a/pkg/cmd/config/list/list_test.go b/pkg/cmd/config/list/list_test.go index 61d3db35981..019d397eec6 100644 --- a/pkg/cmd/config/list/list_test.go +++ b/pkg/cmd/config/list/list_test.go @@ -39,7 +39,7 @@ func TestNewCmdConfigList(t *testing.T) { t.Run(tt.name, func(t *testing.T) { f := &cmdutil.Factory{ Config: func() (gh.Config, error) { - return config.NewBlankConfig(), nil + return config.NewMockConfig(), nil }, } @@ -81,7 +81,7 @@ func Test_listRun(t *testing.T) { { name: "list", config: func() gh.Config { - cfg := config.NewBlankConfig() + cfg := config.NewMockConfig() cfg.Set("HOST", "git_protocol", "ssh") cfg.Set("HOST", "editor", "/usr/bin/vim") cfg.Set("HOST", "prompt", "disabled") diff --git a/pkg/cmd/config/set/set_test.go b/pkg/cmd/config/set/set_test.go index adfb7ba7492..80aed28dbe7 100644 --- a/pkg/cmd/config/set/set_test.go +++ b/pkg/cmd/config/set/set_test.go @@ -51,7 +51,7 @@ func TestNewCmdConfigSet(t *testing.T) { f := &cmdutil.Factory{ Config: func() (gh.Config, error) { - return config.NewBlankConfig(), nil + return config.NewMockConfig(), nil }, } @@ -97,7 +97,7 @@ func Test_setRun(t *testing.T) { { name: "set key value", input: &SetOptions{ - Config: config.NewBlankConfig(), + Config: config.NewMockConfig(), Key: "editor", Value: "vim", }, @@ -106,7 +106,7 @@ func Test_setRun(t *testing.T) { { name: "set key value scoped by host", input: &SetOptions{ - Config: config.NewBlankConfig(), + Config: config.NewMockConfig(), Hostname: "github.com", Key: "editor", Value: "vim", @@ -116,7 +116,7 @@ func Test_setRun(t *testing.T) { { name: "set unknown key", input: &SetOptions{ - Config: config.NewBlankConfig(), + Config: config.NewMockConfig(), Key: "unknownKey", Value: "someValue", }, @@ -126,7 +126,7 @@ func Test_setRun(t *testing.T) { { name: "set invalid value", input: &SetOptions{ - Config: config.NewBlankConfig(), + Config: config.NewMockConfig(), Key: "git_protocol", Value: "invalid", }, diff --git a/pkg/cmd/extension/browse/browse_test.go b/pkg/cmd/extension/browse/browse_test.go index 8120da4d32a..13ecec97eea 100644 --- a/pkg/cmd/extension/browse/browse_test.go +++ b/pkg/cmd/extension/browse/browse_test.go @@ -76,7 +76,7 @@ func Test_getExtensionRepos(t *testing.T) { "per_page": []string{"100"}, "q": []string{"topic:gh-extension"}, } - cfg := config.NewBlankConfig() + cfg := config.NewMockConfig() cfg.AuthenticationFunc = func() gh.AuthConfig { authCfg := &config.AuthConfig{} diff --git a/pkg/cmd/extension/command_test.go b/pkg/cmd/extension/command_test.go index 7001c8f1a7a..fa829156e4c 100644 --- a/pkg/cmd/extension/command_test.go +++ b/pkg/cmd/extension/command_test.go @@ -933,7 +933,7 @@ func TestNewCmdExtension(t *testing.T) { f := cmdutil.Factory{ Config: func() (gh.Config, error) { - return config.NewBlankConfig(), nil + return config.NewMockConfig(), nil }, IOStreams: ios, ExtensionManager: em, diff --git a/pkg/cmd/extension/manager_test.go b/pkg/cmd/extension/manager_test.go index 567f3dba3ba..5a2b241bbcb 100644 --- a/pkg/cmd/extension/manager_test.go +++ b/pkg/cmd/extension/manager_test.go @@ -61,7 +61,7 @@ func newTestManager(dataDir, updateDir string, client *http.Client, gitClient gi cmd.Env = append([]string{"GH_WANT_HELPER_PROCESS=1"}, extraEnv...) return cmd }, - config: config.NewBlankConfig(), + config: config.NewMockConfig(), io: ios, client: client, gitClient: gitClient, diff --git a/pkg/cmd/factory/default_test.go b/pkg/cmd/factory/default_test.go index 9cf34f3b0e5..c41b77506d4 100644 --- a/pkg/cmd/factory/default_test.go +++ b/pkg/cmd/factory/default_test.go @@ -351,7 +351,7 @@ func TestSSOURL(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - cfg := config.NewBlankConfig() + cfg := config.NewMockConfig() ios, _, _, stderr := iostreams.Test() client, err := HttpClientFunc(func() (gh.Config, error) { return cfg, nil }, ios, "v1.2.3", "", &telemetry.NoOpService{})() require.NoError(t, err) @@ -421,7 +421,7 @@ func TestNewGitClient(t *testing.T) { f := &cmdutil.Factory{} f.Config = func() (gh.Config, error) { if tt.config == nil { - return config.NewBlankConfig(), nil + return config.NewMockConfig(), nil } else { return tt.config, nil } @@ -439,7 +439,7 @@ func TestNewGitClient(t *testing.T) { } func defaultConfig() *ghmock.ConfigMock { - cfg := config.NewFromString("") + cfg := config.NewMockConfigFromString("") cfg.Set("nonsense.com", "oauth_token", "BLAH") return cfg } diff --git a/pkg/cmd/gist/clone/clone_test.go b/pkg/cmd/gist/clone/clone_test.go index 46ab53a0fd5..64ac870d11c 100644 --- a/pkg/cmd/gist/clone/clone_test.go +++ b/pkg/cmd/gist/clone/clone_test.go @@ -24,7 +24,7 @@ func runCloneCommand(httpClient *http.Client, cli string) (*test.CmdOut, error) return httpClient, nil }, Config: func() (gh.Config, error) { - return config.NewBlankConfig(), nil + return config.NewMockConfig(), nil }, GitClient: &git.Client{ GhPath: "some/path/gh", diff --git a/pkg/cmd/gist/create/create_test.go b/pkg/cmd/gist/create/create_test.go index 44f0ba284ef..39ca572bd9c 100644 --- a/pkg/cmd/gist/create/create_test.go +++ b/pkg/cmd/gist/create/create_test.go @@ -357,7 +357,7 @@ func Test_createRun(t *testing.T) { tt.opts.HttpClient = mockClient tt.opts.Config = func() (gh.Config, error) { - return config.NewBlankConfig(), nil + return config.NewMockConfig(), nil } ios, stdin, stdout, stderr := iostreams.Test() diff --git a/pkg/cmd/gist/delete/delete_test.go b/pkg/cmd/gist/delete/delete_test.go index 2c4df8d8d6f..80ba17c53cf 100644 --- a/pkg/cmd/gist/delete/delete_test.go +++ b/pkg/cmd/gist/delete/delete_test.go @@ -302,7 +302,7 @@ func Test_deleteRun(t *testing.T) { } tt.opts.Config = func() (gh.Config, error) { - return config.NewBlankConfig(), nil + return config.NewMockConfig(), nil } ios, _, stdout, stderr := iostreams.Test() ios.SetStdoutTTY(true) diff --git a/pkg/cmd/gist/edit/edit_test.go b/pkg/cmd/gist/edit/edit_test.go index ac1555f5c24..9f5b557f390 100644 --- a/pkg/cmd/gist/edit/edit_test.go +++ b/pkg/cmd/gist/edit/edit_test.go @@ -801,7 +801,7 @@ func Test_editRun(t *testing.T) { tt.opts.IO = ios tt.opts.Config = func() (gh.Config, error) { - return config.NewBlankConfig(), nil + return config.NewMockConfig(), nil } t.Run(tt.name, func(t *testing.T) { diff --git a/pkg/cmd/gist/list/list_test.go b/pkg/cmd/gist/list/list_test.go index 14351418f51..d8fc7eac7fa 100644 --- a/pkg/cmd/gist/list/list_test.go +++ b/pkg/cmd/gist/list/list_test.go @@ -620,7 +620,7 @@ func Test_listRun(t *testing.T) { } tt.opts.Config = func() (gh.Config, error) { - return config.NewBlankConfig(), nil + return config.NewMockConfig(), nil } ios, _, stdout, _ := iostreams.Test() diff --git a/pkg/cmd/gist/rename/rename_test.go b/pkg/cmd/gist/rename/rename_test.go index e835cc8a72b..05c67fa7cab 100644 --- a/pkg/cmd/gist/rename/rename_test.go +++ b/pkg/cmd/gist/rename/rename_test.go @@ -168,7 +168,7 @@ func TestRenameRun(t *testing.T) { tt.opts.IO = ios tt.opts.Config = func() (gh.Config, error) { - return config.NewBlankConfig(), nil + return config.NewMockConfig(), nil } t.Run(tt.name, func(t *testing.T) { diff --git a/pkg/cmd/gist/view/view_test.go b/pkg/cmd/gist/view/view_test.go index dcfe561ef66..e778c457151 100644 --- a/pkg/cmd/gist/view/view_test.go +++ b/pkg/cmd/gist/view/view_test.go @@ -593,7 +593,7 @@ func Test_viewRun(t *testing.T) { } tt.opts.Config = func() (gh.Config, error) { - return config.NewBlankConfig(), nil + return config.NewMockConfig(), nil } ios, _, stdout, _ := iostreams.Test() diff --git a/pkg/cmd/gpg-key/add/add_test.go b/pkg/cmd/gpg-key/add/add_test.go index 45119bdfda3..38d8758406f 100644 --- a/pkg/cmd/gpg-key/add/add_test.go +++ b/pkg/cmd/gpg-key/add/add_test.go @@ -204,7 +204,7 @@ func Test_runAdd(t *testing.T) { tt.httpStubs(reg) } tt.opts.Config = func() (gh.Config, error) { - return config.NewBlankConfig(), nil + return config.NewMockConfig(), nil } t.Run(tt.name, func(t *testing.T) { diff --git a/pkg/cmd/gpg-key/delete/delete_test.go b/pkg/cmd/gpg-key/delete/delete_test.go index ef3b36f64ca..79f5b85e4d9 100644 --- a/pkg/cmd/gpg-key/delete/delete_test.go +++ b/pkg/cmd/gpg-key/delete/delete_test.go @@ -247,7 +247,7 @@ func Test_deleteRun(t *testing.T) { return &http.Client{Transport: reg}, nil } tt.opts.Config = func() (gh.Config, error) { - return config.NewBlankConfig(), nil + return config.NewMockConfig(), nil } ios, _, stdout, _ := iostreams.Test() ios.SetStdinTTY(tt.tty) diff --git a/pkg/cmd/gpg-key/list/list_test.go b/pkg/cmd/gpg-key/list/list_test.go index cf9a9b45d25..42c3e95210c 100644 --- a/pkg/cmd/gpg-key/list/list_test.go +++ b/pkg/cmd/gpg-key/list/list_test.go @@ -184,7 +184,7 @@ func Test_listRun(t *testing.T) { ios.SetStderrTTY(tt.isTTY) opts := tt.opts opts.IO = ios - opts.Config = func() (gh.Config, error) { return config.NewBlankConfig(), nil } + opts.Config = func() (gh.Config, error) { return config.NewMockConfig(), nil } err := listRun(&opts) if tt.wantErr { assert.Error(t, err) diff --git a/pkg/cmd/issue/create/create_test.go b/pkg/cmd/issue/create/create_test.go index bd39dfd9bdb..1632b2f5f8a 100644 --- a/pkg/cmd/issue/create/create_test.go +++ b/pkg/cmd/issue/create/create_test.go @@ -268,9 +268,9 @@ func TestNewCmdCreate(t *testing.T) { IOStreams: ios, Config: func() (gh.Config, error) { if tt.config != "" { - return config.NewFromString(tt.config), nil + return config.NewMockConfigFromString(tt.config), nil } - return config.NewBlankConfig(), nil + return config.NewMockConfig(), nil }, } @@ -989,7 +989,7 @@ func runCommandWithRootDirOverridden(rt http.RoundTripper, isTTY bool, cli strin return &http.Client{Transport: rt}, nil }, Config: func() (gh.Config, error) { - return config.NewBlankConfig(), nil + return config.NewMockConfig(), nil }, BaseRepo: func() (ghrepo.Interface, error) { return ghrepo.New("OWNER", "REPO"), nil diff --git a/pkg/cmd/issue/delete/delete_test.go b/pkg/cmd/issue/delete/delete_test.go index 64522b1d3f7..e62bfb65caa 100644 --- a/pkg/cmd/issue/delete/delete_test.go +++ b/pkg/cmd/issue/delete/delete_test.go @@ -38,7 +38,7 @@ func runCommand(rt http.RoundTripper, pm *prompter.MockPrompter, isTTY bool, cli return &http.Client{Transport: rt}, nil }, Config: func() (gh.Config, error) { - return config.NewBlankConfig(), nil + return config.NewMockConfig(), nil }, BaseRepo: func() (ghrepo.Interface, error) { return ghrepo.New("OWNER", "REPO"), nil diff --git a/pkg/cmd/issue/list/list_test.go b/pkg/cmd/issue/list/list_test.go index af0879a6b5e..7baed5c4091 100644 --- a/pkg/cmd/issue/list/list_test.go +++ b/pkg/cmd/issue/list/list_test.go @@ -85,7 +85,7 @@ func runCommand(rt http.RoundTripper, isTTY bool, cli string) (*test.CmdOut, err return &http.Client{Transport: rt}, nil }, Config: func() (gh.Config, error) { - return config.NewBlankConfig(), nil + return config.NewMockConfig(), nil }, BaseRepo: func() (ghrepo.Interface, error) { return ghrepo.New("OWNER", "REPO"), nil diff --git a/pkg/cmd/issue/pin/pin_test.go b/pkg/cmd/issue/pin/pin_test.go index 67b767b32b8..a9b0e4afa99 100644 --- a/pkg/cmd/issue/pin/pin_test.go +++ b/pkg/cmd/issue/pin/pin_test.go @@ -82,7 +82,7 @@ func TestPinRun(t *testing.T) { tt.opts.IO = ios tt.opts.Config = func() (gh.Config, error) { - return config.NewBlankConfig(), nil + return config.NewMockConfig(), nil } tt.opts.BaseRepo = func() (ghrepo.Interface, error) { diff --git a/pkg/cmd/issue/reopen/reopen_test.go b/pkg/cmd/issue/reopen/reopen_test.go index f7c8cb95a32..5ced4a9d1e1 100644 --- a/pkg/cmd/issue/reopen/reopen_test.go +++ b/pkg/cmd/issue/reopen/reopen_test.go @@ -36,7 +36,7 @@ func runCommand(rt http.RoundTripper, isTTY bool, cli string) (*test.CmdOut, err return &http.Client{Transport: rt}, nil }, Config: func() (gh.Config, error) { - return config.NewBlankConfig(), nil + return config.NewMockConfig(), nil }, BaseRepo: func() (ghrepo.Interface, error) { return ghrepo.New("OWNER", "REPO"), nil diff --git a/pkg/cmd/issue/status/status_test.go b/pkg/cmd/issue/status/status_test.go index 6fddf3b0c4e..1f002a9d3ce 100644 --- a/pkg/cmd/issue/status/status_test.go +++ b/pkg/cmd/issue/status/status_test.go @@ -29,7 +29,7 @@ func runCommand(rt http.RoundTripper, isTTY bool, cli string) (*test.CmdOut, err return &http.Client{Transport: rt}, nil }, Config: func() (gh.Config, error) { - return config.NewBlankConfig(), nil + return config.NewMockConfig(), nil }, BaseRepo: func() (ghrepo.Interface, error) { return ghrepo.New("OWNER", "REPO"), nil diff --git a/pkg/cmd/issue/transfer/transfer_test.go b/pkg/cmd/issue/transfer/transfer_test.go index 12faad1b6ba..36380bc9fe3 100644 --- a/pkg/cmd/issue/transfer/transfer_test.go +++ b/pkg/cmd/issue/transfer/transfer_test.go @@ -27,7 +27,7 @@ func runCommand(rt http.RoundTripper, cli string) (*test.CmdOut, error) { return &http.Client{Transport: rt}, nil }, Config: func() (gh.Config, error) { - return config.NewBlankConfig(), nil + return config.NewMockConfig(), nil }, BaseRepo: func() (ghrepo.Interface, error) { return ghrepo.New("OWNER", "REPO"), nil diff --git a/pkg/cmd/issue/unpin/unpin_test.go b/pkg/cmd/issue/unpin/unpin_test.go index 3cdf29a748a..fe124ac4483 100644 --- a/pkg/cmd/issue/unpin/unpin_test.go +++ b/pkg/cmd/issue/unpin/unpin_test.go @@ -82,7 +82,7 @@ func TestUnpinRun(t *testing.T) { tt.opts.IO = ios tt.opts.Config = func() (gh.Config, error) { - return config.NewBlankConfig(), nil + return config.NewMockConfig(), nil } tt.opts.BaseRepo = func() (ghrepo.Interface, error) { diff --git a/pkg/cmd/issue/view/view_test.go b/pkg/cmd/issue/view/view_test.go index d11afe8c0b4..9da37762b85 100644 --- a/pkg/cmd/issue/view/view_test.go +++ b/pkg/cmd/issue/view/view_test.go @@ -74,7 +74,7 @@ func runCommand(rt http.RoundTripper, isTTY bool, cli string) (*test.CmdOut, err return &http.Client{Transport: rt}, nil }, Config: func() (gh.Config, error) { - return config.NewBlankConfig(), nil + return config.NewMockConfig(), nil }, BaseRepo: func() (ghrepo.Interface, error) { return ghrepo.New("OWNER", "REPO"), nil diff --git a/pkg/cmd/org/list/list_test.go b/pkg/cmd/org/list/list_test.go index 3f81419e8cf..b040e30d234 100644 --- a/pkg/cmd/org/list/list_test.go +++ b/pkg/cmd/org/list/list_test.go @@ -226,7 +226,7 @@ cli tt.opts.IO = ios tt.opts.Config = func() (gh.Config, error) { - return config.NewBlankConfig(), nil + return config.NewMockConfig(), nil } err := listRun(&tt.opts) diff --git a/pkg/cmd/pr/checkout/checkout_test.go b/pkg/cmd/pr/checkout/checkout_test.go index 73beaa6dcb3..cc2302ff9e4 100644 --- a/pkg/cmd/pr/checkout/checkout_test.go +++ b/pkg/cmd/pr/checkout/checkout_test.go @@ -205,7 +205,7 @@ func Test_checkoutRun(t *testing.T) { } }(), Config: func() (gh.Config, error) { - return config.NewBlankConfig(), nil + return config.NewMockConfig(), nil }, Branch: func() (string, error) { return "main", nil @@ -233,7 +233,7 @@ func Test_checkoutRun(t *testing.T) { } }(), Config: func() (gh.Config, error) { - return config.NewBlankConfig(), nil + return config.NewMockConfig(), nil }, Branch: func() (string, error) { return "main", nil @@ -263,7 +263,7 @@ func Test_checkoutRun(t *testing.T) { } }(), Config: func() (gh.Config, error) { - return config.NewBlankConfig(), nil + return config.NewMockConfig(), nil }, Branch: func() (string, error) { return "main", nil @@ -291,7 +291,7 @@ func Test_checkoutRun(t *testing.T) { } }(), Config: func() (gh.Config, error) { - return config.NewBlankConfig(), nil + return config.NewMockConfig(), nil }, Branch: func() (string, error) { return "main", nil @@ -321,7 +321,7 @@ func Test_checkoutRun(t *testing.T) { } }(), Config: func() (gh.Config, error) { - return config.NewBlankConfig(), nil + return config.NewMockConfig(), nil }, Branch: func() (string, error) { return "main", nil @@ -353,7 +353,7 @@ func Test_checkoutRun(t *testing.T) { } }(), Config: func() (gh.Config, error) { - return config.NewBlankConfig(), nil + return config.NewMockConfig(), nil }, Branch: func() (string, error) { return "main", nil @@ -386,7 +386,7 @@ func Test_checkoutRun(t *testing.T) { } }(), Config: func() (gh.Config, error) { - return config.NewBlankConfig(), nil + return config.NewMockConfig(), nil }, Branch: func() (string, error) { return "main", nil @@ -417,7 +417,7 @@ func Test_checkoutRun(t *testing.T) { } }(), Config: func() (gh.Config, error) { - return config.NewBlankConfig(), nil + return config.NewMockConfig(), nil }, Branch: func() (string, error) { return "main", nil @@ -448,7 +448,7 @@ func Test_checkoutRun(t *testing.T) { } }(), Config: func() (gh.Config, error) { - return config.NewBlankConfig(), nil + return config.NewMockConfig(), nil }, Branch: func() (string, error) { return "main", nil @@ -477,7 +477,7 @@ func Test_checkoutRun(t *testing.T) { } }(), Config: func() (gh.Config, error) { - return config.NewBlankConfig(), nil + return config.NewMockConfig(), nil }, Branch: func() (string, error) { return "main", nil @@ -506,7 +506,7 @@ func Test_checkoutRun(t *testing.T) { } }(), Config: func() (gh.Config, error) { - return config.NewBlankConfig(), nil + return config.NewMockConfig(), nil }, Branch: func() (string, error) { return "main", nil @@ -538,7 +538,7 @@ func Test_checkoutRun(t *testing.T) { } }(), Config: func() (gh.Config, error) { - return config.NewBlankConfig(), nil + return config.NewMockConfig(), nil }, Branch: func() (string, error) { return "main", nil @@ -569,7 +569,7 @@ func Test_checkoutRun(t *testing.T) { } }(), Config: func() (gh.Config, error) { - return config.NewBlankConfig(), nil + return config.NewMockConfig(), nil }, Branch: func() (string, error) { return "main", nil @@ -601,7 +601,7 @@ func Test_checkoutRun(t *testing.T) { } }(), Config: func() (gh.Config, error) { - return config.NewBlankConfig(), nil + return config.NewMockConfig(), nil }, Branch: func() (string, error) { return "main", nil @@ -634,7 +634,7 @@ func Test_checkoutRun(t *testing.T) { } }(), Config: func() (gh.Config, error) { - return config.NewBlankConfig(), nil + return config.NewMockConfig(), nil }, Branch: func() (string, error) { return "main", nil @@ -666,7 +666,7 @@ func Test_checkoutRun(t *testing.T) { } }(), Config: func() (gh.Config, error) { - return config.NewBlankConfig(), nil + return config.NewMockConfig(), nil }, Branch: func() (string, error) { return "main", nil @@ -864,7 +864,7 @@ func runCommand(rt http.RoundTripper, remotes context.Remotes, branch string, cl return &http.Client{Transport: rt}, nil }, Config: func() (gh.Config, error) { - return config.NewBlankConfig(), nil + return config.NewMockConfig(), nil }, Remotes: func() (context.Remotes, error) { if remotes == nil { diff --git a/pkg/cmd/pr/create/create_test.go b/pkg/cmd/pr/create/create_test.go index a622b60c891..202cd01a79d 100644 --- a/pkg/cmd/pr/create/create_test.go +++ b/pkg/cmd/pr/create/create_test.go @@ -285,9 +285,9 @@ func TestNewCmdCreate(t *testing.T) { IOStreams: ios, Config: func() (gh.Config, error) { if tt.config != "" { - return config.NewFromString(tt.config), nil + return config.NewMockConfigFromString(tt.config), nil } - return config.NewBlankConfig(), nil + return config.NewMockConfig(), nil }, } @@ -1603,7 +1603,7 @@ func Test_createRun(t *testing.T) { return &http.Client{Transport: reg}, nil } opts.Config = func() (gh.Config, error) { - return config.NewBlankConfig(), nil + return config.NewMockConfig(), nil } opts.Remotes = func() (context.Remotes, error) { return context.Remotes{ @@ -2131,7 +2131,7 @@ func Test_createRun_GHES(t *testing.T) { return &http.Client{Transport: reg}, nil } opts.Config = func() (gh.Config, error) { - return config.NewBlankConfig(), nil + return config.NewMockConfig(), nil } opts.Remotes = func() (context.Remotes, error) { return context.Remotes{ @@ -2219,7 +2219,7 @@ func TestRemoteGuessing(t *testing.T) { return &http.Client{Transport: reg}, nil }, Config: func() (gh.Config, error) { - return config.NewBlankConfig(), nil + return config.NewMockConfig(), nil }, Browser: &browser.Stub{}, IO: ios, @@ -2294,7 +2294,7 @@ func TestNoRepoCanBeDetermined(t *testing.T) { return &http.Client{Transport: reg}, nil }, Config: func() (gh.Config, error) { - return config.NewBlankConfig(), nil + return config.NewMockConfig(), nil }, Browser: &browser.Stub{}, IO: ios, @@ -2816,7 +2816,7 @@ func TestProjectsV1Deprecation(t *testing.T) { return &http.Client{Transport: reg}, nil }, Config: func() (gh.Config, error) { - return config.NewBlankConfig(), nil + return config.NewMockConfig(), nil }, Browser: &browser.Stub{}, IO: ios, @@ -2911,7 +2911,7 @@ func TestProjectsV1Deprecation(t *testing.T) { return &http.Client{Transport: reg}, nil }, Config: func() (gh.Config, error) { - return config.NewBlankConfig(), nil + return config.NewMockConfig(), nil }, Browser: &browser.Stub{}, IO: ios, diff --git a/pkg/cmd/pr/review/review_test.go b/pkg/cmd/pr/review/review_test.go index 684617ca97a..e8cfa825d5e 100644 --- a/pkg/cmd/pr/review/review_test.go +++ b/pkg/cmd/pr/review/review_test.go @@ -178,7 +178,7 @@ func runCommand(rt http.RoundTripper, prompter prompter.Prompter, isTTY bool, cl return &http.Client{Transport: rt}, nil }, Config: func() (gh.Config, error) { - return config.NewBlankConfig(), nil + return config.NewMockConfig(), nil }, Prompter: prompter, } diff --git a/pkg/cmd/pr/status/status_test.go b/pkg/cmd/pr/status/status_test.go index 41c01e9150f..522967ec536 100644 --- a/pkg/cmd/pr/status/status_test.go +++ b/pkg/cmd/pr/status/status_test.go @@ -39,7 +39,7 @@ func runCommandWithDetector(rt http.RoundTripper, branch string, isTTY bool, cli return &http.Client{Transport: rt}, nil }, Config: func() (gh.Config, error) { - return config.NewBlankConfig(), nil + return config.NewMockConfig(), nil }, BaseRepo: func() (ghrepo.Interface, error) { return ghrepo.New("OWNER", "REPO"), nil diff --git a/pkg/cmd/project/link/link_test.go b/pkg/cmd/project/link/link_test.go index 23fcfb106bc..5b5c95f178c 100644 --- a/pkg/cmd/project/link/link_test.go +++ b/pkg/cmd/project/link/link_test.go @@ -280,7 +280,7 @@ func TestRunLink_Repo(t *testing.T) { return http.DefaultClient, nil }, config: func() (gh.Config, error) { - return config.NewBlankConfig(), nil + return config.NewMockConfig(), nil }, io: ios, } @@ -392,7 +392,7 @@ func TestRunLink_Team(t *testing.T) { return http.DefaultClient, nil }, config: func() (gh.Config, error) { - return config.NewBlankConfig(), nil + return config.NewMockConfig(), nil }, io: ios, } diff --git a/pkg/cmd/project/unlink/unlink_test.go b/pkg/cmd/project/unlink/unlink_test.go index 0846d786aa1..17959c52c05 100644 --- a/pkg/cmd/project/unlink/unlink_test.go +++ b/pkg/cmd/project/unlink/unlink_test.go @@ -280,7 +280,7 @@ func TestRunUnlink_Repo(t *testing.T) { return http.DefaultClient, nil }, config: func() (gh.Config, error) { - return config.NewBlankConfig(), nil + return config.NewMockConfig(), nil }, io: ios, } @@ -392,7 +392,7 @@ func TestRunUnlink_Team(t *testing.T) { return http.DefaultClient, nil }, config: func() (gh.Config, error) { - return config.NewBlankConfig(), nil + return config.NewMockConfig(), nil }, io: ios, } diff --git a/pkg/cmd/release/create/create_test.go b/pkg/cmd/release/create/create_test.go index eabb936758a..ef6b0f30407 100644 --- a/pkg/cmd/release/create/create_test.go +++ b/pkg/cmd/release/create/create_test.go @@ -1853,7 +1853,7 @@ func Test_createRun_interactive(t *testing.T) { } tt.opts.Config = func() (gh.Config, error) { - return config.NewBlankConfig(), nil + return config.NewMockConfig(), nil } tt.opts.Edit = func(_, _, val string, _ io.Reader, _, _ io.Writer) (string, error) { diff --git a/pkg/cmd/repo/clone/clone_test.go b/pkg/cmd/repo/clone/clone_test.go index bab2bd670bd..ea074242b7c 100644 --- a/pkg/cmd/repo/clone/clone_test.go +++ b/pkg/cmd/repo/clone/clone_test.go @@ -119,7 +119,7 @@ func runCloneCommand(httpClient *http.Client, cli string) (*test.CmdOut, error) return httpClient, nil }, Config: func() (gh.Config, error) { - return config.NewBlankConfig(), nil + return config.NewMockConfig(), nil }, GitClient: &git.Client{ GhPath: "some/path/gh", diff --git a/pkg/cmd/repo/create/create_test.go b/pkg/cmd/repo/create/create_test.go index 5f1f17e604b..7a02a765143 100644 --- a/pkg/cmd/repo/create/create_test.go +++ b/pkg/cmd/repo/create/create_test.go @@ -1051,7 +1051,7 @@ func Test_createRun(t *testing.T) { if tt.opts.Config == nil { tt.opts.Config = func() (gh.Config, error) { - return config.NewBlankConfig(), nil + return config.NewMockConfig(), nil } } diff --git a/pkg/cmd/repo/fork/fork_test.go b/pkg/cmd/repo/fork/fork_test.go index edf5f2763b9..4c58710b757 100644 --- a/pkg/cmd/repo/fork/fork_test.go +++ b/pkg/cmd/repo/fork/fork_test.go @@ -745,7 +745,7 @@ func TestRepoFork(t *testing.T) { return &http.Client{Transport: reg}, nil } - cfg, _ := config.NewIsolatedTestConfig(t) + cfg, _ := config.NewIsolatedTestConfig(t, "") if tt.cfgStubs != nil { tt.cfgStubs(t, cfg) } diff --git a/pkg/cmd/repo/gitignore/list/list_test.go b/pkg/cmd/repo/gitignore/list/list_test.go index 3a68ab511f4..864a98a10ea 100644 --- a/pkg/cmd/repo/gitignore/list/list_test.go +++ b/pkg/cmd/repo/gitignore/list/list_test.go @@ -162,7 +162,7 @@ func TestListRun(t *testing.T) { tt.httpStubs(t, reg) } tt.opts.Config = func() (gh.Config, error) { - return config.NewBlankConfig(), nil + return config.NewMockConfig(), nil } tt.opts.HTTPClient = func() (*http.Client, error) { return &http.Client{Transport: reg}, nil diff --git a/pkg/cmd/repo/gitignore/view/view_test.go b/pkg/cmd/repo/gitignore/view/view_test.go index 3ab1bb25b36..36fa77c2a13 100644 --- a/pkg/cmd/repo/gitignore/view/view_test.go +++ b/pkg/cmd/repo/gitignore/view/view_test.go @@ -95,7 +95,7 @@ func TestViewRun(t *testing.T) { tt.httpStubs(t, reg) } tt.opts.Config = func() (gh.Config, error) { - return config.NewBlankConfig(), nil + return config.NewMockConfig(), nil } tt.opts.HTTPClient = func() (*http.Client, error) { return &http.Client{Transport: reg}, nil diff --git a/pkg/cmd/repo/license/list/list_test.go b/pkg/cmd/repo/license/list/list_test.go index 1fee996c64b..da8571970ba 100644 --- a/pkg/cmd/repo/license/list/list_test.go +++ b/pkg/cmd/repo/license/list/list_test.go @@ -168,7 +168,7 @@ func TestListRun(t *testing.T) { tt.httpStubs(t, reg) } tt.opts.Config = func() (gh.Config, error) { - return config.NewBlankConfig(), nil + return config.NewMockConfig(), nil } tt.opts.HTTPClient = func() (*http.Client, error) { return &http.Client{Transport: reg}, nil diff --git a/pkg/cmd/repo/license/view/view_test.go b/pkg/cmd/repo/license/view/view_test.go index 0a282693d74..8ce359b6471 100644 --- a/pkg/cmd/repo/license/view/view_test.go +++ b/pkg/cmd/repo/license/view/view_test.go @@ -280,7 +280,7 @@ func TestViewRun(t *testing.T) { tt.httpStubs(reg) } tt.opts.Config = func() (gh.Config, error) { - return config.NewBlankConfig(), nil + return config.NewMockConfig(), nil } tt.opts.HTTPClient = func() (*http.Client, error) { return &http.Client{Transport: reg}, nil diff --git a/pkg/cmd/repo/list/list_test.go b/pkg/cmd/repo/list/list_test.go index 93b5a7ed720..e338e03b8dd 100644 --- a/pkg/cmd/repo/list/list_test.go +++ b/pkg/cmd/repo/list/list_test.go @@ -357,7 +357,7 @@ func runCommand(rt http.RoundTripper, isTTY bool, cli string) (*test.CmdOut, err return &http.Client{Transport: rt}, nil }, Config: func() (gh.Config, error) { - return config.NewBlankConfig(), nil + return config.NewMockConfig(), nil }, } @@ -400,7 +400,7 @@ func TestRepoList_nontty(t *testing.T) { return &http.Client{Transport: httpReg}, nil }, Config: func() (gh.Config, error) { - return config.NewBlankConfig(), nil + return config.NewMockConfig(), nil }, Now: func() time.Time { t, _ := time.Parse(time.RFC822, "19 Feb 21 15:00 UTC") @@ -441,7 +441,7 @@ func TestRepoList_tty(t *testing.T) { return &http.Client{Transport: httpReg}, nil }, Config: func() (gh.Config, error) { - return config.NewBlankConfig(), nil + return config.NewMockConfig(), nil }, Now: func() time.Time { t, _ := time.Parse(time.RFC822, "19 Feb 21 15:00 UTC") @@ -511,7 +511,7 @@ func TestRepoList_noVisibilityField(t *testing.T) { return &http.Client{Transport: reg}, nil }, Config: func() (gh.Config, error) { - return config.NewBlankConfig(), nil + return config.NewMockConfig(), nil }, Now: func() time.Time { t, _ := time.Parse(time.RFC822, "19 Feb 21 15:00 UTC") @@ -549,7 +549,7 @@ func TestRepoList_invalidOwner(t *testing.T) { return &http.Client{Transport: reg}, nil }, Config: func() (gh.Config, error) { - return config.NewBlankConfig(), nil + return config.NewMockConfig(), nil }, Now: func() time.Time { t, _ := time.Parse(time.RFC822, "19 Feb 21 15:00 UTC") diff --git a/pkg/cmd/repo/rename/rename_test.go b/pkg/cmd/repo/rename/rename_test.go index e68530be001..3fe8a7c7ca2 100644 --- a/pkg/cmd/repo/rename/rename_test.go +++ b/pkg/cmd/repo/rename/rename_test.go @@ -244,7 +244,7 @@ func TestRenameRun(t *testing.T) { } tt.opts.Config = func() (gh.Config, error) { - return config.NewBlankConfig(), nil + return config.NewMockConfig(), nil } tt.opts.Remotes = func() (context.Remotes, error) { diff --git a/pkg/cmd/repo/view/view_test.go b/pkg/cmd/repo/view/view_test.go index f07f9de187a..36bf3b0747b 100644 --- a/pkg/cmd/repo/view/view_test.go +++ b/pkg/cmd/repo/view/view_test.go @@ -605,7 +605,7 @@ func Test_ViewRun_WithoutUsername(t *testing.T) { }, IO: io, Config: func() (gh.Config, error) { - return config.NewBlankConfig(), nil + return config.NewMockConfig(), nil }, } diff --git a/pkg/cmd/root/extension_registration_test.go b/pkg/cmd/root/extension_registration_test.go index 61d73b1b9b9..f6c624d64bb 100644 --- a/pkg/cmd/root/extension_registration_test.go +++ b/pkg/cmd/root/extension_registration_test.go @@ -72,7 +72,7 @@ func TestNewCmdRoot_ExtensionRegistration(t *testing.T) { f := &cmdutil.Factory{ IOStreams: ios, Config: func() (gh.Config, error) { - return config.NewBlankConfig(), nil + return config.NewMockConfig(), nil }, Browser: &browser.Stub{}, ExtensionManager: em, diff --git a/pkg/cmd/root/help_test.go b/pkg/cmd/root/help_test.go index e7f04375845..0b73d7a438d 100644 --- a/pkg/cmd/root/help_test.go +++ b/pkg/cmd/root/help_test.go @@ -66,7 +66,7 @@ func TestKramdownCompatibleDocs(t *testing.T) { ios, _, _, _ := iostreams.Test() f := &cmdutil.Factory{ IOStreams: ios, - Config: func() (gh.Config, error) { return config.NewBlankConfig(), nil }, + Config: func() (gh.Config, error) { return config.NewMockConfig(), nil }, Browser: &browser.Stub{}, ExtensionManager: &extensions.ExtensionManagerMock{ ListFunc: func() []extensions.Extension { diff --git a/pkg/cmd/run/view/view_test.go b/pkg/cmd/run/view/view_test.go index c3ee9a54ad8..faf4ec60756 100644 --- a/pkg/cmd/run/view/view_test.go +++ b/pkg/cmd/run/view/view_test.go @@ -141,7 +141,7 @@ func TestNewCmdView(t *testing.T) { f := &cmdutil.Factory{ IOStreams: ios, Config: func() (gh.Config, error) { - return config.NewBlankConfig(), nil + return config.NewMockConfig(), nil }, } diff --git a/pkg/cmd/search/code/code_test.go b/pkg/cmd/search/code/code_test.go index 471a9d0cb3f..0a4632de7c9 100644 --- a/pkg/cmd/search/code/code_test.go +++ b/pkg/cmd/search/code/code_test.go @@ -327,7 +327,7 @@ func TestCodeRun(t *testing.T) { { name: "converts filename and extension qualifiers for github.com web search", opts: &CodeOptions{ - Config: func() (gh.Config, error) { return config.NewBlankConfig(), nil }, + Config: func() (gh.Config, error) { return config.NewMockConfig(), nil }, Query: search.Query{ Keywords: []string{"map"}, Kind: "code", @@ -345,7 +345,7 @@ func TestCodeRun(t *testing.T) { { name: "properly handles extension with dot prefix when converting to path qualifier", opts: &CodeOptions{ - Config: func() (gh.Config, error) { return config.NewBlankConfig(), nil }, + Config: func() (gh.Config, error) { return config.NewMockConfig(), nil }, Query: search.Query{ Keywords: []string{"map"}, Kind: "code", diff --git a/pkg/cmd/search/shared/shared_test.go b/pkg/cmd/search/shared/shared_test.go index bd8060943c2..f63d89f4e89 100644 --- a/pkg/cmd/search/shared/shared_test.go +++ b/pkg/cmd/search/shared/shared_test.go @@ -18,7 +18,7 @@ import ( func TestSearcher(t *testing.T) { f := &cmdutil.Factory{ Config: func() (gh.Config, error) { - return config.NewBlankConfig(), nil + return config.NewMockConfig(), nil }, HttpClient: func() (*http.Client, error) { return &http.Client{}, nil diff --git a/pkg/cmd/secret/delete/delete_test.go b/pkg/cmd/secret/delete/delete_test.go index 570df4615d5..8143f21cdfc 100644 --- a/pkg/cmd/secret/delete/delete_test.go +++ b/pkg/cmd/secret/delete/delete_test.go @@ -363,7 +363,7 @@ func Test_removeRun_repo(t *testing.T) { return &http.Client{Transport: reg}, nil } tt.opts.Config = func() (gh.Config, error) { - return config.NewBlankConfig(), nil + return config.NewMockConfig(), nil } tt.opts.BaseRepo = func() (ghrepo.Interface, error) { return ghrepo.FromFullNameWithHost("owner/repo", tt.host) @@ -424,7 +424,7 @@ func Test_removeRun_env(t *testing.T) { return &http.Client{Transport: reg}, nil } tt.opts.Config = func() (gh.Config, error) { - return config.NewBlankConfig(), nil + return config.NewMockConfig(), nil } err := removeRun(tt.opts) @@ -482,7 +482,7 @@ func Test_removeRun_org(t *testing.T) { ios, _, _, _ := iostreams.Test() tt.opts.Config = func() (gh.Config, error) { - return config.NewBlankConfig(), nil + return config.NewMockConfig(), nil } tt.opts.BaseRepo = func() (ghrepo.Interface, error) { return ghrepo.FromFullName("owner/repo") @@ -516,7 +516,7 @@ func Test_removeRun_user(t *testing.T) { return &http.Client{Transport: reg}, nil }, Config: func() (gh.Config, error) { - return config.NewBlankConfig(), nil + return config.NewMockConfig(), nil }, SecretName: "cool_secret", UserSecrets: true, diff --git a/pkg/cmd/secret/list/list_test.go b/pkg/cmd/secret/list/list_test.go index 7e6c88a0002..b1caf977ff2 100644 --- a/pkg/cmd/secret/list/list_test.go +++ b/pkg/cmd/secret/list/list_test.go @@ -628,7 +628,7 @@ func Test_listRun(t *testing.T) { return &http.Client{Transport: reg}, nil } tt.opts.Config = func() (gh.Config, error) { - return config.NewBlankConfig(), nil + return config.NewMockConfig(), nil } tt.opts.Now = func() time.Time { t, _ := time.Parse(time.RFC822, "15 Mar 23 00:00 UTC") @@ -821,7 +821,7 @@ func Test_listRun_populatesNumSelectedReposIfRequired(t *testing.T) { return &http.Client{Transport: reg}, nil } opts.Config = func() (gh.Config, error) { - return config.NewBlankConfig(), nil + return config.NewMockConfig(), nil } opts.Now = func() time.Time { t, _ := time.Parse(time.RFC822, "4 Apr 24 00:00 UTC") diff --git a/pkg/cmd/secret/set/set_test.go b/pkg/cmd/secret/set/set_test.go index 237bc70e1dc..6f09b21bd0e 100644 --- a/pkg/cmd/secret/set/set_test.go +++ b/pkg/cmd/secret/set/set_test.go @@ -469,7 +469,7 @@ func Test_setRun_repo(t *testing.T) { HttpClient: func() (*http.Client, error) { return &http.Client{Transport: reg}, nil }, - Config: func() (gh.Config, error) { return config.NewBlankConfig(), nil }, + Config: func() (gh.Config, error) { return config.NewMockConfig(), nil }, BaseRepo: func() (ghrepo.Interface, error) { return ghrepo.FromFullName("owner/repo") }, @@ -510,7 +510,7 @@ func Test_setRun_env(t *testing.T) { HttpClient: func() (*http.Client, error) { return &http.Client{Transport: reg}, nil }, - Config: func() (gh.Config, error) { return config.NewBlankConfig(), nil }, + Config: func() (gh.Config, error) { return config.NewMockConfig(), nil }, BaseRepo: func() (ghrepo.Interface, error) { return ghrepo.FromFullName("owner/repo") }, @@ -664,7 +664,7 @@ func Test_setRun_org(t *testing.T) { return &http.Client{Transport: reg}, nil } tt.opts.Config = func() (gh.Config, error) { - return config.NewBlankConfig(), nil + return config.NewMockConfig(), nil } tt.opts.IO = ios tt.opts.SecretName = "cool_secret" @@ -746,7 +746,7 @@ func Test_setRun_user(t *testing.T) { return &http.Client{Transport: reg}, nil } tt.opts.Config = func() (gh.Config, error) { - return config.NewBlankConfig(), nil + return config.NewMockConfig(), nil } tt.opts.IO = ios tt.opts.SecretName = "cool_secret" @@ -784,7 +784,7 @@ func Test_setRun_shouldNotStore(t *testing.T) { return &http.Client{Transport: reg}, nil }, Config: func() (gh.Config, error) { - return config.NewBlankConfig(), nil + return config.NewMockConfig(), nil }, BaseRepo: func() (ghrepo.Interface, error) { return ghrepo.FromFullName("owner/repo") diff --git a/pkg/cmd/send-telemetry/send_telemetry_test.go b/pkg/cmd/send-telemetry/send_telemetry_test.go index 8ec2f83c555..e25669a5039 100644 --- a/pkg/cmd/send-telemetry/send_telemetry_test.go +++ b/pkg/cmd/send-telemetry/send_telemetry_test.go @@ -78,7 +78,7 @@ func TestNewCmdSendTelemetry(t *testing.T) { f := &cmdutil.Factory{ IOStreams: ios, Config: func() (gh.Config, error) { - return config.NewBlankConfig(), nil + return config.NewMockConfig(), nil }, } diff --git a/pkg/cmd/skills/search/search_test.go b/pkg/cmd/skills/search/search_test.go index cf66ba4acb4..2b412f037ba 100644 --- a/pkg/cmd/skills/search/search_test.go +++ b/pkg/cmd/skills/search/search_test.go @@ -19,7 +19,7 @@ import ( func TestSearchRun_UnsupportedHost(t *testing.T) { ios, _, _, _ := iostreams.Test() - cfg := config.NewBlankConfig() + cfg := config.NewMockConfig() authCfg := cfg.Authentication() authCfg.SetDefaultHost("acme.ghes.com", "user") cfg.AuthenticationFunc = func() gh.AuthConfig { @@ -367,7 +367,7 @@ func TestSearchRun(t *testing.T) { return &http.Client{Transport: reg}, nil } tt.opts.Config = func() (gh.Config, error) { - return config.NewBlankConfig(), nil + return config.NewMockConfig(), nil } ios, _, stdout, stderr := iostreams.Test() @@ -623,7 +623,7 @@ func TestSearchRun_TelemetryRecordsInstallFromResults(t *testing.T) { err := searchRun(&SearchOptions{ IO: ios, HttpClient: func() (*http.Client, error) { return &http.Client{Transport: reg}, nil }, - Config: func() (gh.Config, error) { return config.NewBlankConfig(), nil }, + Config: func() (gh.Config, error) { return config.NewMockConfig(), nil }, Prompter: pm, Telemetry: recorder, ExecutablePath: "/nonexistent/gh", // install subprocess will fail; failures are logged, not fatal. diff --git a/pkg/cmd/skills/update/update_test.go b/pkg/cmd/skills/update/update_test.go index cb6caac6306..8046c63340c 100644 --- a/pkg/cmd/skills/update/update_test.go +++ b/pkg/cmd/skills/update/update_test.go @@ -355,7 +355,7 @@ func TestUpdateRun(t *testing.T) { ios.SetStdoutTTY(false) return &UpdateOptions{ IO: ios, - Config: func() (gh.Config, error) { return config.NewBlankConfig(), nil }, + Config: func() (gh.Config, error) { return config.NewMockConfig(), nil }, HttpClient: func() (*http.Client, error) { return &http.Client{Transport: reg}, nil }, @@ -371,7 +371,7 @@ func TestUpdateRun(t *testing.T) { ios.SetStdoutTTY(false) return &UpdateOptions{ IO: ios, - Config: func() (gh.Config, error) { return config.NewBlankConfig(), nil }, + Config: func() (gh.Config, error) { return config.NewMockConfig(), nil }, HttpClient: func() (*http.Client, error) { return &http.Client{Transport: reg}, nil }, @@ -401,7 +401,7 @@ func TestUpdateRun(t *testing.T) { ios.SetStdoutTTY(false) return &UpdateOptions{ IO: ios, - Config: func() (gh.Config, error) { return config.NewBlankConfig(), nil }, + Config: func() (gh.Config, error) { return config.NewMockConfig(), nil }, HttpClient: func() (*http.Client, error) { return &http.Client{Transport: reg}, nil }, @@ -434,7 +434,7 @@ func TestUpdateRun(t *testing.T) { ios.SetStderrTTY(true) return &UpdateOptions{ IO: ios, - Config: func() (gh.Config, error) { return config.NewBlankConfig(), nil }, + Config: func() (gh.Config, error) { return config.NewMockConfig(), nil }, HttpClient: func() (*http.Client, error) { return &http.Client{Transport: reg}, nil }, @@ -464,7 +464,7 @@ func TestUpdateRun(t *testing.T) { ios.SetStdinTTY(false) return &UpdateOptions{ IO: ios, - Config: func() (gh.Config, error) { return config.NewBlankConfig(), nil }, + Config: func() (gh.Config, error) { return config.NewMockConfig(), nil }, HttpClient: func() (*http.Client, error) { return &http.Client{Transport: reg}, nil }, @@ -494,7 +494,7 @@ func TestUpdateRun(t *testing.T) { ios.SetStderrTTY(true) return &UpdateOptions{ IO: ios, - Config: func() (gh.Config, error) { return config.NewBlankConfig(), nil }, + Config: func() (gh.Config, error) { return config.NewMockConfig(), nil }, HttpClient: func() (*http.Client, error) { return &http.Client{Transport: reg}, nil }, @@ -544,7 +544,7 @@ func TestUpdateRun(t *testing.T) { ios.SetStdoutTTY(false) return &UpdateOptions{ IO: ios, - Config: func() (gh.Config, error) { return config.NewBlankConfig(), nil }, + Config: func() (gh.Config, error) { return config.NewMockConfig(), nil }, HttpClient: func() (*http.Client, error) { return &http.Client{Transport: reg}, nil }, @@ -589,7 +589,7 @@ func TestUpdateRun(t *testing.T) { ios.SetStderrTTY(true) return &UpdateOptions{ IO: ios, - Config: func() (gh.Config, error) { return config.NewBlankConfig(), nil }, + Config: func() (gh.Config, error) { return config.NewMockConfig(), nil }, HttpClient: func() (*http.Client, error) { return &http.Client{Transport: reg}, nil }, @@ -637,7 +637,7 @@ func TestUpdateRun(t *testing.T) { ios.SetStdinTTY(false) return &UpdateOptions{ IO: ios, - Config: func() (gh.Config, error) { return config.NewBlankConfig(), nil }, + Config: func() (gh.Config, error) { return config.NewMockConfig(), nil }, HttpClient: func() (*http.Client, error) { return &http.Client{Transport: reg}, nil }, @@ -689,7 +689,7 @@ func TestUpdateRun(t *testing.T) { ios.SetStdoutTTY(false) return &UpdateOptions{ IO: ios, - Config: func() (gh.Config, error) { return config.NewBlankConfig(), nil }, + Config: func() (gh.Config, error) { return config.NewMockConfig(), nil }, HttpClient: func() (*http.Client, error) { return &http.Client{Transport: reg}, nil }, @@ -752,7 +752,7 @@ func TestUpdateRun(t *testing.T) { ios.SetStdoutTTY(false) return &UpdateOptions{ IO: ios, - Config: func() (gh.Config, error) { return config.NewBlankConfig(), nil }, + Config: func() (gh.Config, error) { return config.NewMockConfig(), nil }, HttpClient: func() (*http.Client, error) { return &http.Client{Transport: reg}, nil }, @@ -822,7 +822,7 @@ func TestUpdateRun(t *testing.T) { ios.SetStdoutTTY(false) return &UpdateOptions{ IO: ios, - Config: func() (gh.Config, error) { return config.NewBlankConfig(), nil }, + Config: func() (gh.Config, error) { return config.NewMockConfig(), nil }, HttpClient: func() (*http.Client, error) { return &http.Client{Transport: reg}, nil }, @@ -884,7 +884,7 @@ func TestUpdateRun(t *testing.T) { ios.SetStderrTTY(true) return &UpdateOptions{ IO: ios, - Config: func() (gh.Config, error) { return config.NewBlankConfig(), nil }, + Config: func() (gh.Config, error) { return config.NewMockConfig(), nil }, HttpClient: func() (*http.Client, error) { return &http.Client{Transport: reg}, nil }, @@ -939,7 +939,7 @@ func TestUpdateRun(t *testing.T) { ios.SetStderrTTY(true) return &UpdateOptions{ IO: ios, - Config: func() (gh.Config, error) { return config.NewBlankConfig(), nil }, + Config: func() (gh.Config, error) { return config.NewMockConfig(), nil }, HttpClient: func() (*http.Client, error) { return &http.Client{Transport: reg}, nil }, @@ -975,7 +975,7 @@ func TestUpdateRun(t *testing.T) { ios.SetStderrTTY(true) return &UpdateOptions{ IO: ios, - Config: func() (gh.Config, error) { return config.NewBlankConfig(), nil }, + Config: func() (gh.Config, error) { return config.NewMockConfig(), nil }, HttpClient: func() (*http.Client, error) { return &http.Client{Transport: reg}, nil }, @@ -1030,7 +1030,7 @@ func TestUpdateRun(t *testing.T) { ios.SetStderrTTY(true) return &UpdateOptions{ IO: ios, - Config: func() (gh.Config, error) { return config.NewBlankConfig(), nil }, + Config: func() (gh.Config, error) { return config.NewMockConfig(), nil }, HttpClient: func() (*http.Client, error) { return &http.Client{Transport: reg}, nil }, @@ -1098,7 +1098,7 @@ func TestUpdateRun(t *testing.T) { ios.SetStdoutTTY(false) return &UpdateOptions{ IO: ios, - Config: func() (gh.Config, error) { return config.NewBlankConfig(), nil }, + Config: func() (gh.Config, error) { return config.NewMockConfig(), nil }, HttpClient: func() (*http.Client, error) { return &http.Client{Transport: reg}, nil }, @@ -1139,7 +1139,7 @@ func TestUpdateRun(t *testing.T) { ios.SetStderrTTY(true) return &UpdateOptions{ IO: ios, - Config: func() (gh.Config, error) { return config.NewBlankConfig(), nil }, + Config: func() (gh.Config, error) { return config.NewMockConfig(), nil }, HttpClient: func() (*http.Client, error) { return &http.Client{Transport: reg}, nil }, @@ -1185,7 +1185,7 @@ func TestUpdateRun(t *testing.T) { ios.SetStderrTTY(true) return &UpdateOptions{ IO: ios, - Config: func() (gh.Config, error) { return config.NewBlankConfig(), nil }, + Config: func() (gh.Config, error) { return config.NewMockConfig(), nil }, HttpClient: func() (*http.Client, error) { return &http.Client{Transport: reg}, nil }, diff --git a/pkg/cmd/ssh-key/add/add_test.go b/pkg/cmd/ssh-key/add/add_test.go index d167d2fe6e9..c611c2d0da9 100644 --- a/pkg/cmd/ssh-key/add/add_test.go +++ b/pkg/cmd/ssh-key/add/add_test.go @@ -136,7 +136,7 @@ func Test_runAdd(t *testing.T) { tt.httpStubs(reg) } tt.opts.Config = func() (gh.Config, error) { - return config.NewBlankConfig(), nil + return config.NewMockConfig(), nil } t.Run(tt.name, func(t *testing.T) { diff --git a/pkg/cmd/ssh-key/delete/delete_test.go b/pkg/cmd/ssh-key/delete/delete_test.go index 8ec39f68449..afb684cb4d1 100644 --- a/pkg/cmd/ssh-key/delete/delete_test.go +++ b/pkg/cmd/ssh-key/delete/delete_test.go @@ -191,7 +191,7 @@ func Test_deleteRun(t *testing.T) { return &http.Client{Transport: reg}, nil } tt.opts.Config = func() (gh.Config, error) { - return config.NewBlankConfig(), nil + return config.NewMockConfig(), nil } ios, _, stdout, _ := iostreams.Test() ios.SetStdinTTY(tt.tty) diff --git a/pkg/cmd/ssh-key/list/list_test.go b/pkg/cmd/ssh-key/list/list_test.go index 77ee26600af..073c752ad97 100644 --- a/pkg/cmd/ssh-key/list/list_test.go +++ b/pkg/cmd/ssh-key/list/list_test.go @@ -234,7 +234,7 @@ func TestListRun(t *testing.T) { opts := tt.opts opts.IO = ios - opts.Config = func() (gh.Config, error) { return config.NewBlankConfig(), nil } + opts.Config = func() (gh.Config, error) { return config.NewMockConfig(), nil } err := listRun(&opts) if (err != nil) != tt.wantErr { diff --git a/pkg/cmd/status/status_test.go b/pkg/cmd/status/status_test.go index 685ad5be74b..e3f6d02dce9 100644 --- a/pkg/cmd/status/status_test.go +++ b/pkg/cmd/status/status_test.go @@ -61,7 +61,7 @@ func TestNewCmdStatus(t *testing.T) { f := &cmdutil.Factory{ IOStreams: ios, Config: func() (gh.Config, error) { - return config.NewBlankConfig(), nil + return config.NewMockConfig(), nil }, } t.Run(tt.name, func(t *testing.T) { diff --git a/pkg/cmd/variable/delete/delete_test.go b/pkg/cmd/variable/delete/delete_test.go index d00bef8fb73..b415e336ab9 100644 --- a/pkg/cmd/variable/delete/delete_test.go +++ b/pkg/cmd/variable/delete/delete_test.go @@ -165,7 +165,7 @@ func TestRemoveRun(t *testing.T) { return &http.Client{Transport: reg}, nil } tt.opts.Config = func() (gh.Config, error) { - return config.NewBlankConfig(), nil + return config.NewMockConfig(), nil } tt.opts.BaseRepo = func() (ghrepo.Interface, error) { return ghrepo.FromFullNameWithHost("owner/repo", tt.host) diff --git a/pkg/cmd/variable/get/get_test.go b/pkg/cmd/variable/get/get_test.go index 82b602c9e30..b6d546e122c 100644 --- a/pkg/cmd/variable/get/get_test.go +++ b/pkg/cmd/variable/get/get_test.go @@ -268,7 +268,7 @@ func Test_getRun(t *testing.T) { return &http.Client{Transport: reg}, nil } tt.opts.Config = func() (gh.Config, error) { - return config.NewBlankConfig(), nil + return config.NewMockConfig(), nil } if tt.jsonFields != nil { diff --git a/pkg/cmd/variable/list/list_test.go b/pkg/cmd/variable/list/list_test.go index 46c68b1f53e..3bb61da81a6 100644 --- a/pkg/cmd/variable/list/list_test.go +++ b/pkg/cmd/variable/list/list_test.go @@ -279,7 +279,7 @@ func Test_listRun(t *testing.T) { return &http.Client{Transport: reg}, nil } tt.opts.Config = func() (gh.Config, error) { - return config.NewBlankConfig(), nil + return config.NewMockConfig(), nil } tt.opts.Now = func() time.Time { t, _ := time.Parse(time.RFC822, "15 Mar 23 00:00 UTC") @@ -401,7 +401,7 @@ func Test_listRun_populatesNumSelectedReposIfRequired(t *testing.T) { return &http.Client{Transport: reg}, nil } opts.Config = func() (gh.Config, error) { - return config.NewBlankConfig(), nil + return config.NewMockConfig(), nil } opts.Now = func() time.Time { t, _ := time.Parse(time.RFC822, "4 Apr 24 00:00 UTC") diff --git a/pkg/cmd/variable/set/set_test.go b/pkg/cmd/variable/set/set_test.go index 4e77d5900f9..73c3c1a759c 100644 --- a/pkg/cmd/variable/set/set_test.go +++ b/pkg/cmd/variable/set/set_test.go @@ -211,7 +211,7 @@ func Test_setRun_repo(t *testing.T) { HttpClient: func() (*http.Client, error) { return &http.Client{Transport: reg}, nil }, - Config: func() (gh.Config, error) { return config.NewBlankConfig(), nil }, + Config: func() (gh.Config, error) { return config.NewMockConfig(), nil }, BaseRepo: func() (ghrepo.Interface, error) { return ghrepo.FromFullName("owner/repo") }, @@ -284,7 +284,7 @@ func Test_setRun_env(t *testing.T) { HttpClient: func() (*http.Client, error) { return &http.Client{Transport: reg}, nil }, - Config: func() (gh.Config, error) { return config.NewBlankConfig(), nil }, + Config: func() (gh.Config, error) { return config.NewMockConfig(), nil }, BaseRepo: func() (ghrepo.Interface, error) { return ghrepo.FromFullName("owner/repo") }, @@ -396,7 +396,7 @@ func Test_setRun_org(t *testing.T) { return &http.Client{Transport: reg}, nil } tt.opts.Config = func() (gh.Config, error) { - return config.NewBlankConfig(), nil + return config.NewMockConfig(), nil } tt.opts.IO = ios tt.opts.VariableName = "cool_variable" diff --git a/pkg/cmdutil/auth_check_test.go b/pkg/cmdutil/auth_check_test.go index 05eb0254a13..6df37a87867 100644 --- a/pkg/cmdutil/auth_check_test.go +++ b/pkg/cmdutil/auth_check_test.go @@ -42,7 +42,7 @@ func Test_CheckAuth(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - cfg, _ := config.NewIsolatedTestConfig(t) + cfg, _ := config.NewIsolatedTestConfig(t, "") if tt.cfgStubs != nil { tt.cfgStubs(t, cfg) }