...
1
2
3
4
5
6
7
8
9
10
11
12
13 package cdb
14
15 import (
16 "testing"
17
18 "gitlab.com/flimzy/testy"
19
20 internal "github.com/go-kivik/kivik/v4/int/errors"
21 )
22
23 func TestNewRevision(t *testing.T) {
24 type tt struct {
25 i interface{}
26 status int
27 err string
28 }
29 tests := testy.NewTable()
30 tests.Add("simple", tt{
31 i: map[string]interface{}{
32 "_rev": "1-xxx",
33 "value": "foo",
34 },
35 })
36 tests.Add("with attachments", tt{
37 i: map[string]interface{}{
38 "_rev": "3-asdf",
39 "_attachments": map[string]interface{}{
40 "foo.txt": map[string]interface{}{
41 "content_type": "text/plain",
42 "data": []byte("This is some content"),
43 },
44 },
45 },
46 })
47
48 tests.Run(t, func(t *testing.T, tt tt) {
49 fs := &FS{}
50 rev, err := fs.NewRevision(tt.i)
51 if d := internal.StatusErrorDiff(tt.err, tt.status, err); d != "" {
52 t.Error(d)
53 }
54 rev.options = map[string]interface{}{
55 "revs": true,
56 "attachments": true,
57 "header:accept": "application/json",
58 }
59 if d := testy.DiffAsJSON(testy.Snapshot(t), rev); d != nil {
60 t.Error(d)
61 }
62 })
63 }
64
View as plain text