-
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathmockhttp_test.go
57 lines (53 loc) · 998 Bytes
/
mockhttp_test.go
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
48
49
50
51
52
53
54
55
56
57
package sdk
import (
"net/http"
"reflect"
"testing"
)
func Test_authErrorResp(t *testing.T) {
type args struct {
req *http.Request
}
errResp := func(msg string) *http.Response {
o := Error{HTTPCode: http.StatusForbidden}
o.Message = msg
return o.httpResp()
}
tests := []struct {
name string
args args
want *http.Response
}{
{
name: "auth successful",
args: args{
req: &http.Request{
Header: http.Header{
"Authorization": []string{"Bearer validKey"},
},
},
},
want: nil,
},
{
name: "auth not successful",
args: args{
req: &http.Request{
Header: http.Header{
"Authorization": []string{"Bearer invalidApiKey"},
},
},
},
want: errResp("authorization failed"),
},
}
for _, tt := range tests {
t.Run(
tt.name, func(t *testing.T) {
if got := authErrorResp(tt.args.req); !reflect.DeepEqual(got, tt.want) {
t.Errorf("authErrorResp() = %v, want %v", got, tt.want)
}
},
)
}
}