(t *testing.T)
| 179 | } |
| 180 | |
| 181 | func Test_checkoutRun(t *testing.T) { |
| 182 | tests := []struct { |
| 183 | name string |
| 184 | opts *CheckoutOptions |
| 185 | |
| 186 | httpStubs func(*httpmock.Registry) |
| 187 | runStubs func(*run.CommandStubber) |
| 188 | promptStubs func(*prompter.MockPrompter) |
| 189 | |
| 190 | remotes map[string]string |
| 191 | stdoutTTY bool |
| 192 | wantStdout string |
| 193 | wantStderr string |
| 194 | wantErr bool |
| 195 | errMsg string |
| 196 | }{ |
| 197 | { |
| 198 | name: "checkout with ssh remote URL", |
| 199 | opts: &CheckoutOptions{ |
| 200 | PRResolver: func() PRResolver { |
| 201 | baseRepo, pr := stubPR("OWNER/REPO:master", "OWNER/REPO:feature") |
| 202 | return &stubPRResolver{ |
| 203 | pr: pr, |
| 204 | baseRepo: baseRepo, |
| 205 | } |
| 206 | }(), |
| 207 | Config: func() (gh.Config, error) { |
| 208 | return config.NewMockConfig(), nil |
| 209 | }, |
| 210 | Branch: func() (string, error) { |
| 211 | return "main", nil |
| 212 | }, |
| 213 | }, |
| 214 | remotes: map[string]string{ |
| 215 | "origin": "OWNER/REPO", |
| 216 | }, |
| 217 | runStubs: func(cs *run.CommandStubber) { |
| 218 | cs.Register(`git show-ref --verify -- refs/heads/feature`, 1, "") |
| 219 | cs.Register(`git fetch origin \+refs/heads/feature:refs/remotes/origin/feature --no-tags`, 0, "") |
| 220 | cs.Register(`git checkout -b feature --track origin/feature`, 0, "") |
| 221 | }, |
| 222 | }, |
| 223 | { |
| 224 | name: "fork repo was deleted", |
| 225 | opts: &CheckoutOptions{ |
| 226 | PRResolver: func() PRResolver { |
| 227 | baseRepo, pr := stubPR("OWNER/REPO:master", "OWNER/REPO:feature") |
| 228 | pr.MaintainerCanModify = true |
| 229 | pr.HeadRepository = nil |
| 230 | return &stubPRResolver{ |
| 231 | pr: pr, |
| 232 | baseRepo: baseRepo, |
| 233 | } |
| 234 | }(), |
| 235 | Config: func() (gh.Config, error) { |
| 236 | return config.NewMockConfig(), nil |
| 237 | }, |
| 238 | Branch: func() (string, error) { |
nothing calls this directly
no test coverage detected