(t *testing.T)
| 57 | } |
| 58 | |
| 59 | func TestNewCmdTransfer(t *testing.T) { |
| 60 | tests := []struct { |
| 61 | name string |
| 62 | cli string |
| 63 | wants TransferOptions |
| 64 | wantBaseRepo ghrepo.Interface |
| 65 | wantErr bool |
| 66 | }{ |
| 67 | { |
| 68 | name: "no argument", |
| 69 | cli: "", |
| 70 | wantErr: true, |
| 71 | }, |
| 72 | { |
| 73 | name: "issue number argument", |
| 74 | cli: "--repo cli/repo 23 OWNER/REPO", |
| 75 | wants: TransferOptions{ |
| 76 | IssueNumber: 23, |
| 77 | DestRepoSelector: "OWNER/REPO", |
| 78 | }, |
| 79 | wantBaseRepo: ghrepo.New("cli", "repo"), |
| 80 | }, |
| 81 | { |
| 82 | name: "argument is hash prefixed number", |
| 83 | // Escaping is required here to avoid what I think is shellex treating it as a comment. |
| 84 | cli: "--repo cli/repo \\#23 OWNER/REPO", |
| 85 | wants: TransferOptions{ |
| 86 | IssueNumber: 23, |
| 87 | DestRepoSelector: "OWNER/REPO", |
| 88 | }, |
| 89 | wantBaseRepo: ghrepo.New("cli", "repo"), |
| 90 | }, |
| 91 | { |
| 92 | name: "argument is a URL", |
| 93 | cli: "https://github.com/cli/cli/issues/23 OWNER/REPO", |
| 94 | wants: TransferOptions{ |
| 95 | IssueNumber: 23, |
| 96 | DestRepoSelector: "OWNER/REPO", |
| 97 | }, |
| 98 | wantBaseRepo: ghrepo.New("cli", "cli"), |
| 99 | }, |
| 100 | { |
| 101 | name: "argument cannot be parsed to an issue", |
| 102 | cli: "unparseable OWNER/REPO", |
| 103 | wantErr: true, |
| 104 | }, |
| 105 | } |
| 106 | |
| 107 | for _, tt := range tests { |
| 108 | t.Run(tt.name, func(t *testing.T) { |
| 109 | f := &cmdutil.Factory{} |
| 110 | |
| 111 | argv, err := shlex.Split(tt.cli) |
| 112 | assert.NoError(t, err) |
| 113 | |
| 114 | var gotOpts *TransferOptions |
| 115 | cmd := NewCmdTransfer(f, func(opts *TransferOptions) error { |
| 116 | gotOpts = opts |
nothing calls this directly
no test coverage detected