(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 | wantErr bool |
| 28 | errMsg string |
| 29 | }{ |
| 30 | { |
| 31 | name: "no argument", |
| 32 | gitStubs: func(cs *run.CommandStubber) { |
| 33 | cs.Register(`git rev-parse --git-dir`, 0, ".git") |
| 34 | }, |
| 35 | input: "", |
| 36 | output: SetDefaultOptions{}, |
| 37 | }, |
| 38 | { |
| 39 | name: "repo argument", |
| 40 | gitStubs: func(cs *run.CommandStubber) { |
| 41 | cs.Register(`git rev-parse --git-dir`, 0, ".git") |
| 42 | }, |
| 43 | input: "cli/cli", |
| 44 | output: SetDefaultOptions{Repo: ghrepo.New("cli", "cli")}, |
| 45 | }, |
| 46 | { |
| 47 | name: "invalid repo argument", |
| 48 | gitStubs: func(cs *run.CommandStubber) { |
| 49 | cs.Register(`git rev-parse --git-dir`, 0, ".git") |
| 50 | }, |
| 51 | input: "some_invalid_format", |
| 52 | wantErr: true, |
| 53 | errMsg: `given arg is not a valid repo or git remote: expected the "[HOST/]OWNER/REPO" format, got "some_invalid_format"`, |
| 54 | }, |
| 55 | { |
| 56 | name: "view flag", |
| 57 | gitStubs: func(cs *run.CommandStubber) { |
| 58 | cs.Register(`git rev-parse --git-dir`, 0, ".git") |
| 59 | }, |
| 60 | input: "--view", |
| 61 | output: SetDefaultOptions{ViewMode: true}, |
| 62 | }, |
| 63 | { |
| 64 | name: "unset flag", |
| 65 | gitStubs: func(cs *run.CommandStubber) { |
| 66 | cs.Register(`git rev-parse --git-dir`, 0, ".git") |
| 67 | }, |
| 68 | input: "--unset", |
| 69 | output: SetDefaultOptions{UnsetMode: true}, |
| 70 | }, |
| 71 | { |
| 72 | name: "run from non-git directory", |
| 73 | gitStubs: func(cs *run.CommandStubber) { |
| 74 | cs.Register(`git rev-parse --git-dir`, 128, "") |
| 75 | }, |
| 76 | input: "", |
| 77 | wantErr: true, |
nothing calls this directly
no test coverage detected