(t *testing.T)
| 18 | ) |
| 19 | |
| 20 | func TestNewCmdSetDefault(t *testing.T) { |
| 21 | tests := []struct { |
| 22 | name string |
| 23 | gitStubs func(*run.CommandStubber) |
| 24 | remotes func() (context.Remotes, error) |
| 25 | input string |
| 26 | output SetDefaultOptions |
| 27 | nonTTY bool |
| 28 | wantErr bool |
| 29 | errMsg string |
| 30 | }{ |
| 31 | { |
| 32 | name: "no argument", |
| 33 | gitStubs: func(cs *run.CommandStubber) { |
| 34 | cs.Register(`git rev-parse --git-dir`, 0, ".git") |
| 35 | }, |
| 36 | input: "", |
| 37 | output: SetDefaultOptions{}, |
| 38 | }, |
| 39 | { |
| 40 | name: "repo argument", |
| 41 | gitStubs: func(cs *run.CommandStubber) { |
| 42 | cs.Register(`git rev-parse --git-dir`, 0, ".git") |
| 43 | }, |
| 44 | input: "cli/cli", |
| 45 | output: SetDefaultOptions{Repo: ghrepo.New("cli", "cli")}, |
| 46 | }, |
| 47 | { |
| 48 | name: "invalid repo argument", |
| 49 | gitStubs: func(cs *run.CommandStubber) { |
| 50 | cs.Register(`git rev-parse --git-dir`, 0, ".git") |
| 51 | }, |
| 52 | input: "some_invalid_format", |
| 53 | wantErr: true, |
| 54 | errMsg: `given arg is not a valid repo or git remote: expected the "[HOST/]OWNER/REPO" format, got "some_invalid_format"`, |
| 55 | }, |
| 56 | { |
| 57 | name: "view flag", |
| 58 | gitStubs: func(cs *run.CommandStubber) { |
| 59 | cs.Register(`git rev-parse --git-dir`, 0, ".git") |
| 60 | }, |
| 61 | input: "--view", |
| 62 | output: SetDefaultOptions{ViewMode: true}, |
| 63 | nonTTY: true, |
| 64 | }, |
| 65 | { |
| 66 | name: "unset flag", |
| 67 | gitStubs: func(cs *run.CommandStubber) { |
| 68 | cs.Register(`git rev-parse --git-dir`, 0, ".git") |
| 69 | }, |
| 70 | input: "--unset", |
| 71 | output: SetDefaultOptions{UnsetMode: true}, |
| 72 | nonTTY: true, |
| 73 | }, |
| 74 | { |
| 75 | name: "no argument when not running interactively", |
| 76 | gitStubs: func(cs *run.CommandStubber) { |
| 77 | cs.Register(`git rev-parse --git-dir`, 0, ".git") |
nothing calls this directly
no test coverage detected