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
/
state_test.go
109 lines (91 loc) · 2.31 KB
/
state_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
108
109
package bucket
import (
"testing"
"github.com/rs/xid"
)
func TestUpdateState(t *testing.T) {
s, err := newState(&Configuration{
Username: "Administrator",
Password: "password",
BucketName: "company",
BucketPassword: "",
ConnectionString: "couchbase://localhost",
Separator: "::",
})
if err != nil {
t.Fatal(err)
}
s.setType("cache", "cache")
var s2 state
_, err = s.bucket.Get(stateDocumentKey, &s2)
if err != nil {
t.Fatal(err)
}
if s2.DocumentTypes["cache"] != "cache::" {
t.Errorf("Document key should be 'cache::', instead of %s", s2.DocumentTypes["cache"])
}
}
func TestValidate(t *testing.T) {
_, err := th.ValidateState()
if err != nil {
t.Fatal(err)
}
}
func TestValidateExpectError(t *testing.T) {
_ = th.state.updateState()
delete(th.state.DocumentTypes, "webshop")
if _, err := th.state.validate(); err == nil {
t.Error("Err should be not nil")
}
_ = th.state.updateState()
}
func TestLoad(t *testing.T) {
_ = th.state.updateState()
if err := th.state.load(); err != nil {
t.Error(err)
}
}
func TestInspect(t *testing.T) {
th.state.setType("tsinspect", "tsinspect")
if b := th.state.inspect("tsinspect"); !b {
t.Error("type not found")
}
_ = th.state.deleteType("webshop")
}
func TestSetType(t *testing.T) {
th.state.setType("webshop", "webshop")
}
func TestDeleteType(t *testing.T) {
err := th.state.deleteType("webshop")
if err != nil {
t.Error(err)
}
th.state.setType("webshop", "webshop")
}
func TestDeleteTypeErrDocumentTypeDoesntExists(t *testing.T) {
err := th.state.deleteType("webshop")
if err != nil {
t.Error(err)
}
err = th.state.deleteType("webshop")
if err != ErrDocumentTypeDoesntExists {
t.Error(err)
}
th.state.setType("webshop", "webshop")
}
func TestFetchDocIdentifierEmptyDocumentKey(t *testing.T) {
if s := th.state.fetchDocumentIdentifier(""); s != "" {
t.Errorf("error should be %s instead of %s", "", s)
}
}
func TestFetchDocIdentifier(t *testing.T) {
id := xid.New().String()
if s := th.state.fetchDocumentIdentifier("ws::" + id); s != id {
t.Errorf("error should be %s instead of %s", id, s)
}
}
func TestCreateEmptyIndexExpectError(t *testing.T) {
if err := createFullTextSearchIndex("", true, "webshop"); err != ErrEmptyIndex {
t.Errorf("error should be %s instead of %s", ErrEmptyIndex, err)
}
}