-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Expand file tree
/
Copy pathclient_test.go
More file actions
47 lines (40 loc) · 969 Bytes
/
client_test.go
File metadata and controls
47 lines (40 loc) · 969 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package cloudapi
import (
"net/http"
"testing"
"time"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestPrepareHeaders(t *testing.T) {
t.Parallel()
tests := []struct {
name string
preset string
wantAuth string
}{
{
name: "respects preset authorization",
preset: "Bearer pre-set-token",
wantAuth: "Bearer pre-set-token",
},
{
name: "sets token auth when unset",
preset: "",
wantAuth: "Token mytoken",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
t.Parallel()
c := NewClient(nil, "mytoken", "http://example.com", "v0.1", 1*time.Second)
req, err := http.NewRequestWithContext(t.Context(), http.MethodGet, "http://example.com", nil)
require.NoError(t, err)
if tt.preset != "" {
req.Header.Set("Authorization", tt.preset)
}
c.prepareHeaders(req)
assert.Equal(t, tt.wantAuth, req.Header.Get("Authorization"))
})
}
}