Pre-auth call sites supply their own token because it is not yet in config, so an explicit Authorization header must survive rather than be replaced by the transport.
(t *testing.T)
| 102 | // Pre-auth call sites supply their own token because it is not yet in config, so an explicit |
| 103 | // Authorization header must survive rather than be replaced by the transport. |
| 104 | func TestRequestExplicitAuthorizationHeaderIsPreserved(t *testing.T) { |
| 105 | reg := &httpmock.Registry{} |
| 106 | defer reg.Verify(t) |
| 107 | |
| 108 | httpClient := &http.Client{} |
| 109 | httpmock.ReplaceTripper(httpClient, reg) |
| 110 | httpClient.Transport = AddAuthTokenHeader(httpClient.Transport, tinyConfig{"github.com:oauth_token": "config-token"}) |
| 111 | client := NewClientFromHTTP(httpClient) |
| 112 | |
| 113 | reg.Register(httpmock.MatchAny, httpmock.StatusStringResponse(200, "{}")) |
| 114 | |
| 115 | resp, err := client.Request("github.com", http.MethodGet, "user", nil, |
| 116 | WithHeader("Authorization", "token explicit-token")) |
| 117 | require.NoError(t, err) |
| 118 | defer resp.Body.Close() |
| 119 | |
| 120 | assert.Equal(t, "token explicit-token", reg.Requests[0].Header.Get("Authorization")) |
| 121 | } |
| 122 | |
| 123 | func TestRequestReturnsBodyUnread(t *testing.T) { |
| 124 | reg := &httpmock.Registry{} |
nothing calls this directly
no test coverage detected