Expand gh secret base repo tests
Building on top of the work done in commands to account for GH_REPO environment variable, this commit expands existing tests around handling base repo functions to include new test scenarios. These tests fail in the same way as reported on the issue when run against `trunk` without the other branch's changes, demonstrating they will help avoid regression.
This commit is contained in:
parent
d67d65e304
commit
23ea61d325
3 changed files with 44 additions and 6 deletions
|
|
@ -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)
|
||||
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue