This repository has been archived by the owner on May 22, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
operations_insert_test.go
107 lines (91 loc) · 2.68 KB
/
operations_insert_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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
package bucket
import (
"context"
"encoding/json"
"fmt"
"strings"
"testing"
"github.com/stretchr/testify/assert"
"github.com/rs/xid"
)
func TestHandler_GetSubDocuments(t *testing.T) {
var ws = generate()
resultset := th.getSubDocuments("webshop", xid.New().String(), ws, nil)
for k, v := range resultset {
shit, _ := json.Marshal(v)
fmt.Printf("k: %s, v: %s\n", k, shit)
}
}
func TestHandler_Insert(t *testing.T) {
ws := generate()
_, id, err := th.Insert(context.Background(), "webshop", "", ws, 0)
if err != nil {
t.Fatal(err)
}
wsGet := webshop{}
if err := th.Get(context.Background(), "webshop", id, &wsGet); err != nil {
t.Fatal(err)
}
assert.Equal(t, ws, wsGet, "should be equal")
m, err := th.getMeta("webshop", id)
if err != nil {
t.Fatal(err)
}
if len(m.ChildDocuments) != 3 {
t.Errorf("Length of children should be 3, instead of %d", len(m.ChildDocuments))
}
if m.Type != "webshop" {
t.Errorf("Type should be 'webshop', instead of %s", m.Type)
}
if m.ParentDocument != nil {
t.Errorf("Parent should be nil, instead of %v", m.ParentDocument)
}
for _, child := range m.ChildDocuments {
parts := strings.Split(child.Key, "::")
if len(parts) != 2 {
t.Error("Invalid key")
}
if parts[0] != child.Type {
t.Errorf("First part of key should be equal with %s, instead of %s", child.Type, parts[0])
}
if parts[1] != child.ID {
t.Errorf("Second part of key should be equal with %s, instead of %s", child.ID, parts[1])
}
if id != child.ID {
t.Errorf("Second part of key should be equal with %s, instead of %s", id, child.ID)
}
}
pGet := product{}
if err := th.Get(context.Background(), "product", id, &pGet); err != nil {
t.Fatal(err)
}
assert.Equal(t, ws.Product, &pGet, "should be equal")
m, err = th.getMeta("product", id)
if err != nil {
t.Fatal(err)
}
if len(m.ChildDocuments) != 1 {
t.Errorf("Length of children should be 1, instead of %d", len(m.ChildDocuments))
}
if m.Type != "product" {
t.Errorf("Type should be 'product', instead of %s", m.Type)
}
if m.ParentDocument != nil && m.ParentDocument.Key != "webshop::"+id {
t.Errorf("Parent key should be %s, instead of %s", "webshop::"+id, m.ParentDocument.Key)
}
for _, child := range m.ChildDocuments {
parts := strings.Split(child.Key, "::")
if len(parts) != 2 {
t.Error("Invalid key")
}
if parts[0] != child.Type {
t.Errorf("First part of key should be equal with %s, instead of %s", child.Type, parts[0])
}
if parts[1] != child.ID {
t.Errorf("Second part of key should be equal with %s, instead of %s", child.ID, parts[1])
}
if id != child.ID {
t.Errorf("Second part of key should be equal with %s, instead of %s", id, child.ID)
}
}
}