solr.TestCollectionCreate   A
last analyzed

Complexity

Conditions 3

Size

Total Lines 17
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 13
nop 1
dl 0
loc 17
rs 9.75
c 0
b 0
f 0
1
package solr
2
3
import (
4
	"context"
5
	"testing"
6
)
7
8
func TestCollectionCreate(t *testing.T) {
9
	client := NewClient()
10
11
	response, err := client.Collection.Create(context.Background(), CollectionCreate{
12
		Name:                 "tests",
13
		RouterName:           "compositeId",
14
		NumShards:            1,
15
		ReplicationFactor:    1,
16
		CollectionConfigName: "_default",
17
		Async:                false,
18
	})
19
	if err != nil {
20
		t.Errorf("failed to create collection %v", err)
21
	}
22
23
	if response.ResponseHeader.Status != 0 {
24
		t.Errorf("failed to create collection %v", err)
25
	}
26
}
27
28
func TestCollectionReload(t *testing.T) {
29
	client := NewClient()
30
31
	response, err := client.Collection.Reload(context.Background(), CollectionReload{
32
		Name:  "tests",
33
		Async: false,
34
	})
35
	if err != nil {
36
		t.Errorf("failed to reload collection %v", err)
37
	}
38
39
	if response.ResponseHeader.Status != 0 {
40
		t.Errorf("failed to reload collection %v", err)
41
	}
42
}
43
44
func TestCollectionModify(t *testing.T) {
45
	client := NewClient()
46
47
	response, err := client.Collection.Modify(context.Background(), CollectionModifyCollection{
48
		Collection:       "tests",
49
		MaxShardsPerNode: 1,
50
	})
51
	if err != nil {
52
		t.Errorf("failed to modify collections %v", err)
53
	}
54
55
	if response.ResponseHeader.Status != 0 {
56
		t.Errorf("failed to modify collections %v", err)
57
	}
58
}
59
60
func TestCollectionList(t *testing.T) {
61
	client := NewClient()
62
63
	response, err := client.Collection.List(context.Background())
64
	if err != nil {
65
		t.Errorf("failed to list collections %v", err)
66
	}
67
68
	if response.ResponseHeader.Status != 0 {
69
		t.Errorf("failed to list collections %v", err)
70
	}
71
}
72
73
func TestCollectionProp(t *testing.T) {
74
	client := NewClient()
75
76
	response, err := client.Collection.CollectionProp(context.Background(), CollectionProp{
77
		Name:          "tests",
78
		PropertyName:  "timestamp",
79
		PropertyValue: "dateTime",
80
	})
81
	if err != nil {
82
		t.Errorf("failed to modify property %v", err)
83
	}
84
85
	if response.ResponseHeader.Status != 0 {
86
		t.Errorf("failed to modify property %v", err)
87
	}
88
}
89
90
func TestCollectionRename(t *testing.T) {
91
	client := NewClient()
92
93
	response, err := client.Collection.Rename(context.Background(), CollectionRename{
94
		Name:   "tests",
95
		Target: "tests",
96
	})
97
	if err != nil {
98
		t.Errorf("failed to rename collection %v", err)
99
	}
100
101
	if response.ResponseHeader.Status != 0 {
102
		t.Errorf("failed to rename collection %v", err)
103
	}
104
}
105
106
func TestCollectionMigrate(t *testing.T) {
107
	client := NewClient()
108
109
	response, err := client.Collection.Create(context.Background(), CollectionCreate{
110
		Name:                 "tests-migrate",
111
		NumShards:            1,
112
		ReplicationFactor:    1,
113
		CollectionConfigName: "_default",
114
		Async:                false,
115
	})
116
	if err != nil {
117
		t.Errorf("failed to create collection tests-migrate %v", err)
118
	}
119
120
	if response.ResponseHeader.Status != 0 {
121
		t.Errorf("failed to create collection tests-migrate %v", err)
122
	}
123
124
	response, err = client.Collection.Migrate(context.Background(), CollectionMigrate{
125
		Collection:       "tests",
126
		TargetCollection: "tests-migrate",
127
		SplitKey:         "a!",
128
		ForwardTimeout:   100000,
129
		Async:            false,
130
	})
131
	if err != nil {
132
		t.Errorf("failed to migrate collection %v", err)
133
	}
134
135
	if response.ResponseHeader.Status != 0 {
136
		t.Errorf("failed to migrate collection %v", err)
137
	}
138
}
139
140
//func TestCollectionBackup(t *testing.T) {
141
//
142
//	client := NewClient()
143
//
144
//	backupFilePath := fmt.Sprintf("bkp_%x", md5.Sum([]byte(time.Now().String())))[0:10]
145
//
146
//	client := NewClient(config)
147
//
148
//	response, err := client.Collection.Backup(context.Background(), CollectionBackup{
149
//		Collection:     "tests",
150
//		Name:           backupFilePath,
151
//		Location:       "/tmp",
152
//		Async:          false,
153
//	})
154
//
155
//	if err != nil {
156
//		t.Errorf("failed to backup collection %v", err)
157
//	}
158
//
159
//	if response.ResponseHeader.Status != 0 {
160
//		t.Errorf("failed to backup collection %v", response)
161
//	}
162
//}
163
164
//func TestCollectionRestore(t *testing.T) {
165
//	client := NewClient()
166
//
167
//	backupFilePath := fmt.Sprintf("bkp_%x", md5.Sum([]byte(time.Now().String())))[0:8]
168
//
169
//	client := NewClient(config)
170
//
171
//	response, err := client.Collection.Backup(context.Background(), CollectionBackup{
172
//		Collection:     "tests",
173
//		Name:           backupFilePath,
174
//		Location:       "/tmp/",
175
//		Async:          false,
176
//	})
177
//	if err != nil {
178
//		t.Errorf("failed to backup collection %v", err)
179
//	}
180
//
181
//	if response.ResponseHeader.Status != 0 {
182
//		t.Errorf("failed to backup collection %v", response)
183
//	}
184
//
185
//	response, err = client.Collection.Restore(context.Background(), CollectionRestore{
186
//		Collection:           backupFilePath,
187
//		Name:                 backupFilePath,
188
//		Location:       	  "/tmp/",
189
//		Async:                false,
190
//		ReplicationFactor:    1,
191
//	})
192
//	if err != nil {
193
//		t.Errorf("failed to restore collection %v", err)
194
//	}
195
//
196
//	if response.ResponseHeader.Status != 0 {
197
//		t.Errorf("failed to restore collection %v", response)
198
//	}
199
//}
200
201
func TestCollectionDelete(t *testing.T) {
202
	client := NewClient()
203
204
	response, err := client.Collection.Delete(context.Background(), CollectionDelete{
205
		Name:  "tests",
206
		Async: false,
207
	})
208
	if err != nil {
209
		t.Errorf("failed to delete collection %v", err)
210
	}
211
212
	if response.ResponseHeader.Status != 0 {
213
		t.Errorf("failed to delete collection %v", err)
214
	}
215
}
216
217
func TestCollectionDeleteMigrate(t *testing.T) {
218
	client := NewClient()
219
220
	response, err := client.Collection.Delete(context.Background(), CollectionDelete{
221
		Name:  "tests-migrate",
222
		Async: false,
223
	})
224
	if err != nil {
225
		t.Errorf("failed to delete collection migrate %v", err)
226
	}
227
228
	if response.ResponseHeader.Status != 0 {
229
		t.Errorf("failed to delete collection migrate %v", err)
230
	}
231
}
232