(t *testing.T)
| 12 | ) |
| 13 | |
| 14 | func TestParseIssuesFromArgs(t *testing.T) { |
| 15 | tests := []struct { |
| 16 | behavior string |
| 17 | args []string |
| 18 | expectedIssueNumbers []int |
| 19 | expectedRepo o.Option[ghrepo.Interface] |
| 20 | expectedErr bool |
| 21 | }{ |
| 22 | { |
| 23 | behavior: "when given issue numbers, returns them with no repo", |
| 24 | args: []string{"1", "2"}, |
| 25 | expectedIssueNumbers: []int{1, 2}, |
| 26 | expectedRepo: o.None[ghrepo.Interface](), |
| 27 | }, |
| 28 | { |
| 29 | behavior: "when given # prefixed issue numbers, returns them with no repo", |
| 30 | args: []string{"#1", "#2"}, |
| 31 | expectedIssueNumbers: []int{1, 2}, |
| 32 | expectedRepo: o.None[ghrepo.Interface](), |
| 33 | }, |
| 34 | { |
| 35 | behavior: "when given URLs, returns them with the repo", |
| 36 | args: []string{ |
| 37 | "https://github.com/OWNER/REPO/issues/1", |
| 38 | "https://github.com/OWNER/REPO/issues/2", |
| 39 | }, |
| 40 | expectedIssueNumbers: []int{1, 2}, |
| 41 | expectedRepo: o.Some(ghrepo.New("OWNER", "REPO")), |
| 42 | }, |
| 43 | { |
| 44 | behavior: "when given URLs in different repos, errors", |
| 45 | args: []string{ |
| 46 | "https://github.com/OWNER/REPO/issues/1", |
| 47 | "https://github.com/OWNER/OTHERREPO/issues/2", |
| 48 | }, |
| 49 | expectedErr: true, |
| 50 | }, |
| 51 | { |
| 52 | behavior: "when given an unparseable argument, errors", |
| 53 | args: []string{"://"}, |
| 54 | expectedErr: true, |
| 55 | }, |
| 56 | { |
| 57 | behavior: "when given a URL that isn't an issue or PR url, errors", |
| 58 | args: []string{"https://github.com"}, |
| 59 | expectedErr: true, |
| 60 | }, |
| 61 | } |
| 62 | |
| 63 | for _, tc := range tests { |
| 64 | t.Run(tc.behavior, func(t *testing.T) { |
| 65 | issueNumbers, repo, err := ParseIssuesFromArgs(tc.args) |
| 66 | |
| 67 | if tc.expectedErr { |
| 68 | require.Error(t, err) |
| 69 | return |
| 70 | } |
| 71 |
nothing calls this directly
no test coverage detected