| 16 | ) |
| 17 | |
| 18 | func TestParseURL(t *testing.T) { |
| 19 | tests := []struct { |
| 20 | name string |
| 21 | arg string |
| 22 | wantRepo ghrepo.Interface |
| 23 | wantNum int |
| 24 | wantRest string |
| 25 | wantErr string |
| 26 | }{ |
| 27 | { |
| 28 | name: "valid HTTPS URL", |
| 29 | arg: "https://example.com/owner/repo/pull/123", |
| 30 | wantRepo: ghrepo.NewWithHost("owner", "repo", "example.com"), |
| 31 | wantNum: 123, |
| 32 | }, |
| 33 | { |
| 34 | name: "valid HTTP URL", |
| 35 | arg: "http://example.com/owner/repo/pull/123", |
| 36 | wantRepo: ghrepo.NewWithHost("owner", "repo", "example.com"), |
| 37 | wantNum: 123, |
| 38 | }, |
| 39 | { |
| 40 | name: "valid HTTP URL with rest", |
| 41 | arg: "http://example.com/owner/repo/pull/123/foo/bar", |
| 42 | wantRepo: ghrepo.NewWithHost("owner", "repo", "example.com"), |
| 43 | wantNum: 123, |
| 44 | wantRest: "/foo/bar", |
| 45 | }, |
| 46 | { |
| 47 | name: "valid HTTP URL with .patch as rest", |
| 48 | arg: "http://example.com/owner/repo/pull/123.patch", |
| 49 | wantRepo: ghrepo.NewWithHost("owner", "repo", "example.com"), |
| 50 | wantNum: 123, |
| 51 | wantRest: ".patch", |
| 52 | }, |
| 53 | { |
| 54 | name: "valid HTTP URL with a trailing slash", |
| 55 | arg: "http://example.com/owner/repo/pull/123/", |
| 56 | wantRepo: ghrepo.NewWithHost("owner", "repo", "example.com"), |
| 57 | wantNum: 123, |
| 58 | wantRest: "/", |
| 59 | }, |
| 60 | { |
| 61 | name: "empty URL", |
| 62 | wantErr: "invalid URL: \"\"", |
| 63 | }, |
| 64 | { |
| 65 | name: "no scheme", |
| 66 | arg: "github.com/owner/repo/pull/123", |
| 67 | wantErr: "invalid scheme: ", |
| 68 | }, |
| 69 | { |
| 70 | name: "invalid scheme", |
| 71 | arg: "ftp://github.com/owner/repo/pull/123", |
| 72 | wantErr: "invalid scheme: ftp", |
| 73 | }, |
| 74 | { |
| 75 | name: "no hostname", |