| 8 | ) |
| 9 | |
| 10 | func Test_repoFromURL(t *testing.T) { |
| 11 | tests := []struct { |
| 12 | name string |
| 13 | input string |
| 14 | result string |
| 15 | host string |
| 16 | err error |
| 17 | }{ |
| 18 | { |
| 19 | name: "github.com URL", |
| 20 | input: "https://github.com/monalisa/octo-cat.git", |
| 21 | result: "monalisa/octo-cat", |
| 22 | host: "github.com", |
| 23 | err: nil, |
| 24 | }, |
| 25 | { |
| 26 | name: "github.com URL with trailing slash", |
| 27 | input: "https://github.com/monalisa/octo-cat/", |
| 28 | result: "monalisa/octo-cat", |
| 29 | host: "github.com", |
| 30 | err: nil, |
| 31 | }, |
| 32 | { |
| 33 | name: "www.github.com URL", |
| 34 | input: "http://www.GITHUB.com/monalisa/octo-cat.git", |
| 35 | result: "monalisa/octo-cat", |
| 36 | host: "github.com", |
| 37 | err: nil, |
| 38 | }, |
| 39 | { |
| 40 | name: "too many path components", |
| 41 | input: "https://github.com/monalisa/octo-cat/pulls", |
| 42 | result: "", |
| 43 | host: "", |
| 44 | err: errors.New("invalid path: /monalisa/octo-cat/pulls"), |
| 45 | }, |
| 46 | { |
| 47 | name: "non-GitHub hostname", |
| 48 | input: "https://example.com/one/two", |
| 49 | result: "one/two", |
| 50 | host: "example.com", |
| 51 | err: nil, |
| 52 | }, |
| 53 | { |
| 54 | name: "filesystem path", |
| 55 | input: "/path/to/file", |
| 56 | result: "", |
| 57 | host: "", |
| 58 | err: errors.New("no hostname detected"), |
| 59 | }, |
| 60 | { |
| 61 | name: "filesystem path with scheme", |
| 62 | input: "file:///path/to/file", |
| 63 | result: "", |
| 64 | host: "", |
| 65 | err: errors.New("no hostname detected"), |
| 66 | }, |
| 67 | { |