-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathuser_test.go
More file actions
112 lines (92 loc) · 2.72 KB
/
user_test.go
File metadata and controls
112 lines (92 loc) · 2.72 KB
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
package sofa
import (
"fmt"
"testing"
"github.com/nbio/st"
"github.com/h2non/gock"
)
func TestCreateUser(t *testing.T) {
defer gock.Off()
gock.New(fmt.Sprintf("https://%s", globalTestConnections.Version1MockHost)).
Put("/_users/org.couchdb.user:Couchy McCouchface").
Reply(201).
JSON(map[string]interface{}{
"ok": true,
"id": "org.couchdb.user:Couchy McCouchface",
"rev": DefaultFirstRev,
}).
SetHeader("Etag", fmt.Sprintf(`"%s"`, DefaultFirstRev))
con := globalTestConnections.Version1(t, true)
rev, err := con.CreateUser(&UserDocument{
Name: "Couchy McCouchface",
Password: "example",
Roles: []string{"boat"},
TheType: "user",
})
if err != nil {
t.Fatal(err)
}
st.Assert(t, rev, DefaultFirstRev)
}
func TestUpdateUser(t *testing.T) {
defer gock.Off()
gock.New(fmt.Sprintf("https://%s", globalTestConnections.Version1MockHost)).
Get("/_users/org.couchdb.user:Couchy McCouchface").
Reply(200).
JSON(map[string]interface{}{
"_id": "org.couchdb.user:Couchy McCouchface",
"_rev": DefaultFirstRev,
"password_scheme": "pbkdf2",
"iterations": 10,
"name": "Couchy McCouchface",
"roles": []string{"boat"},
"type": "user",
"derived_key": "31aee83dcb20882eadcf455381164dbe605f29c0",
"salt": "b6be17ff6bae9d932428478de90eea05",
}).
SetHeader("Etag", fmt.Sprintf(`"%s"`, DefaultFirstRev))
gock.New(fmt.Sprintf("https://%s", globalTestConnections.Version1MockHost)).
Put("/_users/org.couchdb.user:Couchy McCouchface").
Reply(201).
JSON(map[string]interface{}{
"ok": true,
"id": "org.couchdb.user:Couchy McCouchface",
"rev": DefaultSecondRev,
}).
SetHeader("Etag", fmt.Sprintf(`"%s"`, DefaultSecondRev))
con := globalTestConnections.Version1(t, true)
user, err := con.User("Couchy McCouchface", "")
if err != nil {
t.Fatal(err)
}
user.Roles = append(user.Roles, "awesome")
rev, err := con.UpdateUser(&user)
if err != nil {
t.Fatal(err)
}
st.Assert(t, rev, DefaultSecondRev)
}
func TestDeleteUser(t *testing.T) {
defer gock.Off()
gock.New(fmt.Sprintf("https://%s", globalTestConnections.Version1MockHost)).
Delete("/_users/org.couchdb.user:Couchy McCouchface").
Reply(201).
JSON(map[string]interface{}{
"ok": true,
"id": "org.couchdb.user:Couchy McCouchface",
"rev": DefaultThirdRev,
}).
SetHeader("Etag", fmt.Sprintf(`"%s"`, DefaultThirdRev))
con := globalTestConnections.Version1(t, true)
rev, err := con.DeleteUser(&UserDocument{
DocumentMetadata: DocumentMetadata{
Rev: DefaultFirstRev,
ID: "org.couchdb.user:Couchy McCouchface",
},
Name: "Couchy McCouchface",
})
if err != nil {
t.Fatal(err)
}
st.Assert(t, rev, DefaultThirdRev)
}