test(api): improve NewHTTPClient test assertions
The assertions should check for header values instead of single string, because when getting a single header value, we get an empty string if the header is not set or is set to an empty string. So, to make sure a header is not set we should check the `Values` slice which is `nil` only if the header is missing. Signed-off-by: Babak K. Shandiz <babakks@github.com>
This commit is contained in:
parent
5eb6549dc7
commit
b9e04ef83d
1 changed files with 22 additions and 22 deletions
|
|
@ -26,7 +26,7 @@ func TestNewHTTPClient(t *testing.T) {
|
|||
name string
|
||||
args args
|
||||
host string
|
||||
wantHeader map[string]string
|
||||
wantHeader map[string][]string
|
||||
wantStderr string
|
||||
}{
|
||||
{
|
||||
|
|
@ -37,10 +37,10 @@ func TestNewHTTPClient(t *testing.T) {
|
|||
logVerboseHTTP: false,
|
||||
},
|
||||
host: "github.com",
|
||||
wantHeader: map[string]string{
|
||||
"authorization": "token MYTOKEN",
|
||||
"user-agent": "GitHub CLI v1.2.3",
|
||||
"accept": "application/vnd.github.merge-info-preview+json, application/vnd.github.nebula-preview",
|
||||
wantHeader: map[string][]string{
|
||||
"authorization": {"token MYTOKEN"},
|
||||
"user-agent": {"GitHub CLI v1.2.3"},
|
||||
"accept": {"application/vnd.github.merge-info-preview+json, application/vnd.github.nebula-preview"},
|
||||
},
|
||||
wantStderr: "",
|
||||
},
|
||||
|
|
@ -51,10 +51,10 @@ func TestNewHTTPClient(t *testing.T) {
|
|||
appVersion: "v1.2.3",
|
||||
},
|
||||
host: "example.com",
|
||||
wantHeader: map[string]string{
|
||||
"authorization": "token GHETOKEN",
|
||||
"user-agent": "GitHub CLI v1.2.3",
|
||||
"accept": "application/vnd.github.merge-info-preview+json, application/vnd.github.nebula-preview",
|
||||
wantHeader: map[string][]string{
|
||||
"authorization": {"token GHETOKEN"},
|
||||
"user-agent": {"GitHub CLI v1.2.3"},
|
||||
"accept": {"application/vnd.github.merge-info-preview+json, application/vnd.github.nebula-preview"},
|
||||
},
|
||||
wantStderr: "",
|
||||
},
|
||||
|
|
@ -66,10 +66,10 @@ func TestNewHTTPClient(t *testing.T) {
|
|||
logVerboseHTTP: false,
|
||||
},
|
||||
host: "github.com",
|
||||
wantHeader: map[string]string{
|
||||
"authorization": "",
|
||||
"user-agent": "GitHub CLI v1.2.3",
|
||||
"accept": "application/vnd.github.merge-info-preview+json, application/vnd.github.nebula-preview",
|
||||
wantHeader: map[string][]string{
|
||||
"authorization": nil, // should not be set
|
||||
"user-agent": {"GitHub CLI v1.2.3"},
|
||||
"accept": {"application/vnd.github.merge-info-preview+json, application/vnd.github.nebula-preview"},
|
||||
},
|
||||
wantStderr: "",
|
||||
},
|
||||
|
|
@ -81,10 +81,10 @@ func TestNewHTTPClient(t *testing.T) {
|
|||
logVerboseHTTP: false,
|
||||
},
|
||||
host: "example.com",
|
||||
wantHeader: map[string]string{
|
||||
"authorization": "",
|
||||
"user-agent": "GitHub CLI v1.2.3",
|
||||
"accept": "application/vnd.github.merge-info-preview+json, application/vnd.github.nebula-preview",
|
||||
wantHeader: map[string][]string{
|
||||
"authorization": nil, // should not be set
|
||||
"user-agent": {"GitHub CLI v1.2.3"},
|
||||
"accept": {"application/vnd.github.merge-info-preview+json, application/vnd.github.nebula-preview"},
|
||||
},
|
||||
wantStderr: "",
|
||||
},
|
||||
|
|
@ -96,10 +96,10 @@ func TestNewHTTPClient(t *testing.T) {
|
|||
logVerboseHTTP: true,
|
||||
},
|
||||
host: "github.com",
|
||||
wantHeader: map[string]string{
|
||||
"authorization": "token MYTOKEN",
|
||||
"user-agent": "GitHub CLI v1.2.3",
|
||||
"accept": "application/vnd.github.merge-info-preview+json, application/vnd.github.nebula-preview",
|
||||
wantHeader: map[string][]string{
|
||||
"authorization": {"token MYTOKEN"},
|
||||
"user-agent": {"GitHub CLI v1.2.3"},
|
||||
"accept": {"application/vnd.github.merge-info-preview+json, application/vnd.github.nebula-preview"},
|
||||
},
|
||||
wantStderr: heredoc.Doc(`
|
||||
* Request at <time>
|
||||
|
|
@ -148,7 +148,7 @@ func TestNewHTTPClient(t *testing.T) {
|
|||
require.NoError(t, err)
|
||||
|
||||
for name, value := range tt.wantHeader {
|
||||
assert.Equal(t, value, gotReq.Header.Get(name), name)
|
||||
assert.Equal(t, value, gotReq.Header.Values(name), name)
|
||||
}
|
||||
|
||||
assert.Equal(t, 204, res.StatusCode)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue