-
Notifications
You must be signed in to change notification settings - Fork 28
/
remote_test.go
149 lines (141 loc) · 3.67 KB
/
remote_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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
// Copyright 2014-Present Couchbase, Inc.
//
// Use of this software is governed by the Business Source License included
// in the file licenses/BSL-Couchbase.txt. As of the Change Date specified
// in that file, in accordance with the Business Source License, use of this
// software will be governed by the Apache License, Version 2.0, included in
// the file licenses/APL2.txt.
package cbft
import (
"net/http"
"reflect"
"testing"
)
func TestNegativeIndexClient(t *testing.T) {
bc := &IndexClient{}
if bc.Index("", nil) != indexClientUnimplementedErr {
t.Errorf("expected unimplemented")
}
if bc.Delete("") != indexClientUnimplementedErr {
t.Errorf("expected unimplemented")
}
if bc.Batch(nil) != indexClientUnimplementedErr {
t.Errorf("expected unimplemented")
}
d, err := bc.Document("")
if err != indexClientUnimplementedErr || d != nil {
t.Errorf("expected unimplemented")
}
c, err := bc.DocCount()
if err == nil || c != 0 {
t.Errorf("expected count error on empty CountURL")
}
sr, err := bc.Search(nil)
if err == nil || sr != nil {
t.Errorf("expected search error on empty QueryURL")
}
f, err := bc.Fields()
if err != indexClientUnimplementedErr || f != nil {
t.Errorf("expected unimplemented")
}
if bc.DumpAll() != nil {
t.Errorf("expected nil")
}
if bc.DumpDoc("") != nil {
t.Errorf("expected nil")
}
if bc.DumpFields() != nil {
t.Errorf("expected nil")
}
if bc.Close() != indexClientUnimplementedErr {
t.Errorf("expected unimplemented")
}
if bc.Mapping() != nil {
t.Errorf("expected nil")
}
if bc.Stats() != nil {
t.Errorf("expected nil")
}
val, err := bc.GetInternal(nil)
if err != indexClientUnimplementedErr || val != nil {
t.Errorf("expected unimplemented")
}
if bc.SetInternal(nil, nil) != indexClientUnimplementedErr {
t.Errorf("expected unimplemented")
}
if bc.DeleteInternal(nil) != indexClientUnimplementedErr {
t.Errorf("expected unimplemented")
}
}
func TestBadURLsIndexClient(t *testing.T) {
bc := &IndexClient{
CountURL: "bogus url",
QueryURL: "fake url",
httpClient: http.DefaultClient,
}
c, err := bc.DocCount()
if err == nil || c != 0 {
t.Errorf("expected count error on bad CountURL")
}
sr, err := bc.Search(nil)
if err == nil || sr != nil {
t.Errorf("expected search error on bad QueryURL")
}
}
func TestGroupIndexClientsByHostPort(t *testing.T) {
c0 := &IndexClient{
HostPort: "x",
IndexName: "indexA",
PIndexNames: []string{"a", "b"},
QueryURL: "foo",
httpClient: http.DefaultClient,
}
c1 := &IndexClient{
HostPort: "x",
IndexName: "indexA",
PIndexNames: []string{"c"},
QueryURL: "bar",
httpClient: http.DefaultClient,
}
c2 := &IndexClient{
HostPort: "y",
IndexName: "indexA",
PIndexNames: []string{"d"},
QueryURL: "baz",
httpClient: http.DefaultClient,
}
a, err := GroupIndexClientsByHostPort([]*IndexClient{c0, c1, c2})
if err != nil {
t.Errorf("expect nil err")
}
if len(a) != 2 {
t.Errorf("expect 2 hostPorts")
}
if a[0].HostPort != "x" ||
len(a[0].PIndexNames) != 3 ||
!reflect.DeepEqual(a[0].PIndexNames, []string{"a", "b", "c"}) {
t.Errorf("expect x has 3 pindexes")
}
if a[0].QueryURL != "http://x/api/index/indexA/query" {
t.Errorf("expect x query URL")
}
if a[1].HostPort != "y" ||
len(a[1].PIndexNames) != 1 ||
!reflect.DeepEqual(a[1].PIndexNames, []string{"d"}) {
t.Errorf("expect y has 1 pindexes")
}
a, err = GroupIndexClientsByHostPort([]*IndexClient{})
if err != nil {
t.Errorf("expect nil err")
}
if len(a) != 0 {
t.Errorf("expect 0 hostPorts")
}
a, err = GroupIndexClientsByHostPort(nil)
if err != nil {
t.Errorf("expect nil err")
}
if len(a) != 0 {
t.Errorf("expect 0 hostPorts")
}
}