-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdocument_list_test.go
52 lines (43 loc) · 1.25 KB
/
document_list_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
package sofa
import (
"fmt"
"testing"
"github.com/nbio/st"
"github.com/h2non/gock"
)
func TestDocumentList(t *testing.T) {
defer gock.Off()
gock.New(fmt.Sprintf("https://%s", globalTestConnections.Version1MockHost)).
Post("/test_db/_all_docs").
MatchParam("include_docs", "^true$").
Reply(200).
JSON(map[string]interface{}{
"total_rows": 3,
"offset": 0,
"rows": []map[string]interface{}{
{"id": "joel", "key": "joel", "value": map[string]string{
"rev": "1-f75c2efff6baeed9e202d0cf58b8bd60",
}},
{"id": "bob", "key": "bob", "value": map[string]string{
"rev": "1-2de76086df68b0d3840f20dff114a000",
}},
{"id": "jane", "key": "jane", "value": map[string]string{
"rev": "10-6bf653103ec443a04119fde156189078",
}},
},
})
con := globalTestConnections.Version1(t, true)
db := con.Database("test_db")
allDocs, err := db.Documents()
if err != nil {
t.Fatal(err)
}
st.Assert(t, allDocs.TotalRows, float64(3))
st.Assert(t, allDocs.Offset, float64(0))
st.Assert(t, allDocs.Rows[0].ID, "joel")
st.Assert(t, allDocs.Rows[1].ID, "bob")
st.Assert(t, allDocs.Rows[2].ID, "jane")
st.Assert(t, allDocs.Rows[0].Key, "joel")
st.Assert(t, allDocs.Rows[1].Key, "bob")
st.Assert(t, allDocs.Rows[2].Key, "jane")
}