(t *testing.T)
| 8 | ) |
| 9 | |
| 10 | func TestParseAPIHost(t *testing.T) { |
| 11 | tests := []struct { |
| 12 | name string |
| 13 | input string |
| 14 | wantRestURL string |
| 15 | wantErr bool |
| 16 | }{ |
| 17 | { |
| 18 | name: "empty string defaults to dotcom", |
| 19 | input: "", |
| 20 | wantRestURL: "https://api.github.com/", |
| 21 | }, |
| 22 | { |
| 23 | name: "github.com hostname", |
| 24 | input: "https://github.com", |
| 25 | wantRestURL: "https://api.github.com/", |
| 26 | }, |
| 27 | { |
| 28 | name: "subdomain of github.com", |
| 29 | input: "https://foo.github.com", |
| 30 | wantRestURL: "https://api.github.com/", |
| 31 | }, |
| 32 | { |
| 33 | name: "hostname ending in github.com but not a subdomain", |
| 34 | input: "https://mycompanygithub.com", |
| 35 | wantRestURL: "https://mycompanygithub.com/api/v3/", |
| 36 | }, |
| 37 | { |
| 38 | name: "hostname ending in notgithub.com", |
| 39 | input: "https://notgithub.com", |
| 40 | wantRestURL: "https://notgithub.com/api/v3/", |
| 41 | }, |
| 42 | { |
| 43 | name: "ghe.com hostname", |
| 44 | input: "https://ghe.com", |
| 45 | wantRestURL: "https://api.ghe.com/", |
| 46 | }, |
| 47 | { |
| 48 | name: "subdomain of ghe.com", |
| 49 | input: "https://mycompany.ghe.com", |
| 50 | wantRestURL: "https://api.mycompany.ghe.com/", |
| 51 | }, |
| 52 | { |
| 53 | name: "hostname ending in ghe.com but not a subdomain", |
| 54 | input: "https://myghe.com", |
| 55 | wantRestURL: "https://myghe.com/api/v3/", |
| 56 | }, |
| 57 | { |
| 58 | name: "missing scheme", |
| 59 | input: "github.com", |
| 60 | wantErr: true, |
| 61 | }, |
| 62 | } |
| 63 | |
| 64 | for _, tc := range tests { |
| 65 | t.Run(tc.name, func(t *testing.T) { |
| 66 | host, err := parseAPIHost(tc.input) |
| 67 | if tc.wantErr { |
nothing calls this directly
no test coverage detected