(t *testing.T)
| 17 | ) |
| 18 | |
| 19 | func TestRequestResolvesPathAgainstHost(t *testing.T) { |
| 20 | tests := []struct { |
| 21 | name string |
| 22 | hostname string |
| 23 | path string |
| 24 | wantHostname string |
| 25 | wantPath string |
| 26 | }{ |
| 27 | { |
| 28 | name: "relative path resolves against github.com", |
| 29 | hostname: "github.com", |
| 30 | path: "repos/OWNER/REPO", |
| 31 | wantHostname: "api.github.com", |
| 32 | wantPath: "/repos/OWNER/REPO", |
| 33 | }, |
| 34 | { |
| 35 | name: "relative path resolves against an enterprise host", |
| 36 | hostname: "example.com", |
| 37 | path: "repos/OWNER/REPO", |
| 38 | wantHostname: "example.com", |
| 39 | wantPath: "/api/v3/repos/OWNER/REPO", |
| 40 | }, |
| 41 | { |
| 42 | // Absolute URLs are how API-supplied locations such as asset and upload URLs |
| 43 | // reach this method, so they must be requested exactly as given. |
| 44 | name: "absolute URL is requested as given", |
| 45 | hostname: "github.com", |
| 46 | path: "https://uploads.github.com/assets/1234", |
| 47 | wantHostname: "uploads.github.com", |
| 48 | wantPath: "/assets/1234", |
| 49 | }, |
| 50 | } |
| 51 | |
| 52 | for _, tt := range tests { |
| 53 | t.Run(tt.name, func(t *testing.T) { |
| 54 | reg := &httpmock.Registry{} |
| 55 | defer reg.Verify(t) |
| 56 | client := newTestClient(reg) |
| 57 | |
| 58 | reg.Register(httpmock.MatchAny, httpmock.StatusStringResponse(200, "{}")) |
| 59 | |
| 60 | resp, err := client.Request(tt.hostname, http.MethodGet, tt.path, nil) |
| 61 | require.NoError(t, err) |
| 62 | defer resp.Body.Close() |
| 63 | |
| 64 | assert.Equal(t, tt.wantHostname, reg.Requests[0].URL.Hostname()) |
| 65 | assert.Equal(t, tt.wantPath, reg.Requests[0].URL.Path) |
| 66 | }) |
| 67 | } |
| 68 | } |
| 69 | |
| 70 | func TestRequestWithHeader(t *testing.T) { |
| 71 | reg := &httpmock.Registry{} |
nothing calls this directly
no test coverage detected