diff --git a/pkg/cmd/secret/delete/delete_test.go b/pkg/cmd/secret/delete/delete_test.go index 377879cf2..2f6cad431 100644 --- a/pkg/cmd/secret/delete/delete_test.go +++ b/pkg/cmd/secret/delete/delete_test.go @@ -144,6 +144,7 @@ func TestNewCmdDeleteBaseRepoFuncs(t *testing.T) { tests := []struct { name string args string + env map[string]string prompterStubs func(*prompter.MockPrompter) wantRepo ghrepo.Interface wantErr error @@ -154,14 +155,22 @@ func TestNewCmdDeleteBaseRepoFuncs(t *testing.T) { wantRepo: ghrepo.New("owner", "repo"), }, { - name: "when there is no repo flag provided, and no prompting, the base func requiring no ambiguity is used", + name: "when GH_REPO env var is provided, the factory base repo func is used", + args: "SECRET_NAME", + env: map[string]string{ + "GH_REPO": "owner/repo", + }, + wantRepo: ghrepo.New("owner", "repo"), + }, + { + name: "when there is no repo flag or GH_REPO env var provided, and no prompting, the base func requiring no ambiguity is used", args: "SECRET_NAME", wantErr: shared.AmbiguousBaseRepoError{ Remotes: remotes, }, }, { - name: "when there is no repo flag provided, and can prompt, the base func resolving ambiguity is used", + name: "when there is no repo flag or GH_REPO env var provided, and can prompt, the base func resolving ambiguity is used", args: "SECRET_NAME", prompterStubs: func(pm *prompter.MockPrompter) { pm.RegisterSelect( @@ -199,6 +208,10 @@ func TestNewCmdDeleteBaseRepoFuncs(t *testing.T) { }, } + for k, v := range tt.env { + t.Setenv(k, v) + } + argv, err := shlex.Split(tt.args) assert.NoError(t, err) diff --git a/pkg/cmd/secret/list/list_test.go b/pkg/cmd/secret/list/list_test.go index 601de2572..f4ecde73e 100644 --- a/pkg/cmd/secret/list/list_test.go +++ b/pkg/cmd/secret/list/list_test.go @@ -124,6 +124,7 @@ func TestNewCmdListBaseRepoFuncs(t *testing.T) { tests := []struct { name string args string + env map[string]string prompterStubs func(*prompter.MockPrompter) wantRepo ghrepo.Interface wantErr error @@ -134,14 +135,21 @@ func TestNewCmdListBaseRepoFuncs(t *testing.T) { wantRepo: ghrepo.New("owner", "repo"), }, { - name: "when there is no repo flag provided, and no prompting, the base func requiring no ambiguity is used", + name: "when GH_REPO env var is provided, the factory base repo func is used", + env: map[string]string{ + "GH_REPO": "owner/repo", + }, + wantRepo: ghrepo.New("owner", "repo"), + }, + { + name: "when there is no repo flag or GH_REPO env var provided, and no prompting, the base func requiring no ambiguity is used", args: "", wantErr: shared.AmbiguousBaseRepoError{ Remotes: remotes, }, }, { - name: "when there is no repo flag provided, and can prompt, the base func resolving ambiguity is used", + name: "when there is no repo flag or GH_REPO env var provided, and can prompt, the base func resolving ambiguity is used", args: "", prompterStubs: func(pm *prompter.MockPrompter) { pm.RegisterSelect( @@ -179,6 +187,10 @@ func TestNewCmdListBaseRepoFuncs(t *testing.T) { }, } + for k, v := range tt.env { + t.Setenv(k, v) + } + argv, err := shlex.Split(tt.args) assert.NoError(t, err) diff --git a/pkg/cmd/secret/set/set_test.go b/pkg/cmd/secret/set/set_test.go index 99c8c6cbe..22c7aaab8 100644 --- a/pkg/cmd/secret/set/set_test.go +++ b/pkg/cmd/secret/set/set_test.go @@ -243,6 +243,7 @@ func TestNewCmdSetBaseRepoFuncs(t *testing.T) { tests := []struct { name string args string + env map[string]string prompterStubs func(*prompter.MockPrompter) wantRepo ghrepo.Interface wantErr error @@ -253,14 +254,22 @@ func TestNewCmdSetBaseRepoFuncs(t *testing.T) { wantRepo: ghrepo.New("owner", "repo"), }, { - name: "when there is no repo flag provided, and no prompting, the base func requiring no ambiguity is used", + name: "when GH_REPO env var is provided, the factory base repo func is used", + args: "SECRET_NAME", + env: map[string]string{ + "GH_REPO": "owner/repo", + }, + wantRepo: ghrepo.New("owner", "repo"), + }, + { + name: "when there is no repo flag or GH_REPO env var provided, and no prompting, the base func requiring no ambiguity is used", args: "SECRET_NAME", wantErr: shared.AmbiguousBaseRepoError{ Remotes: remotes, }, }, { - name: "when there is no repo flag provided, and can prompt, the base func resolving ambiguity is used", + name: "when there is no repo flag or GH_REPO env var provided, and can prompt, the base func resolving ambiguity is used", args: "SECRET_NAME", prompterStubs: func(pm *prompter.MockPrompter) { pm.RegisterSelect( @@ -298,6 +307,10 @@ func TestNewCmdSetBaseRepoFuncs(t *testing.T) { }, } + for k, v := range tt.env { + t.Setenv(k, v) + } + argv, err := shlex.Split(tt.args) assert.NoError(t, err)