-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathuser_test.go
68 lines (62 loc) · 1.4 KB
/
user_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
package smugmug_test
import (
"context"
"errors"
"net/http"
"net/http/httptest"
"testing"
"github.com/stretchr/testify/assert"
"github.com/bzimmer/smugmug"
)
func TestAuthUser(t *testing.T) {
t.Parallel()
a := assert.New(t)
tests := []struct {
name string
filename string
options []smugmug.APIOption
f func(user *smugmug.User, err error)
}{
{
name: "success",
filename: "testdata/user_cmac.json",
f: func(user *smugmug.User, err error) {
a.NoError(err)
a.NotNil(user)
},
},
{
name: "failed parse",
filename: "user_test.go",
f: func(user *smugmug.User, err error) {
a.Error(err)
a.Nil(user)
},
},
{
name: "failed options",
filename: "testdata/user_cmac.json",
options: []smugmug.APIOption{withError()},
f: func(user *smugmug.User, err error) {
a.Error(err)
a.True(errors.Is(err, errFail))
a.Nil(user)
},
},
}
for i := range tests {
tt := tests[i]
t.Run(tt.name, func(t *testing.T) {
t.Parallel()
svr := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
a.Equal("/!authuser", r.URL.Path)
http.ServeFile(w, r, tt.filename)
}))
defer svr.Close()
mg, err := smugmug.NewClient(smugmug.WithBaseURL(svr.URL), smugmug.WithPretty(false))
a.NoError(err)
user, err := mg.User.AuthUser(context.TODO(), tt.options...)
tt.f(user, err)
})
}
}