-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathprofile_test.go
88 lines (82 loc) · 1.79 KB
/
profile_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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
package kanka
import (
"net/http"
"os"
"testing"
"github.com/google/go-cmp/cmp"
)
const testProfileGet string = "test_data/profile_get.json"
func TestProfileService_Get(t *testing.T) {
prof := &Profile{
ID: 111,
Name: "Henry",
Avatar: "https://some-aws-server.com/some_avatar.png",
AvatarThumb: "https://some-aws-server.com/some_thumbnail.png",
Locale: "en-US",
Timezone: "UTC",
DateFormat: "m/d/Y",
DefaultPagination: 45,
LastCampaignID: 5272,
IsPatreon: false,
}
tests := []struct {
name string
status int
file string
want *Profile
wantErr bool
}{
{
name: "StatusOK, valid response",
status: http.StatusOK,
file: testProfileGet,
want: prof,
wantErr: false,
},
{
name: "Status OK, empty response",
status: http.StatusOK,
file: testFileEmpty,
want: nil,
wantErr: true,
},
{
name: "StatusUnauthorized",
status: http.StatusUnauthorized,
file: testFileEmpty,
want: nil,
wantErr: true,
},
{
name: "StatusForbidden",
status: http.StatusForbidden,
file: testFileEmpty,
want: nil,
wantErr: true,
},
{
name: "StatusNotFound",
status: http.StatusNotFound,
file: testFileEmpty,
want: nil,
wantErr: true,
},
}
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
f, err := os.Open(test.file)
if err != nil {
t.Fatal(err)
}
defer f.Close()
c, _ := testClient(test.status, f)
got, err := c.Profiles.Get()
if (err != nil) != test.wantErr {
t.Fatalf("got: <%v>, want error: <%v>", err, test.wantErr)
}
if diff := cmp.Diff(got, test.want); diff != "" {
t.Errorf("mismatch (-want +got):\n%s", diff)
}
})
}
}