@@ -18,19 +18,27 @@ import (
18
18
)
19
19
20
20
func TestSeparateEDnode (t * testing.T ) {
21
- // Path to the helm chart we will test
22
- helmChartPath , e := filepath .Abs ("../../charts" )
23
- if e != nil {
24
- t .Fatalf (e .Error ())
25
- }
26
- username := "admin"
27
- password := "admin"
28
21
var resp * http.Response
29
22
var body []byte
30
23
var err error
31
24
25
+ username := "admin"
26
+ password := "admin"
32
27
imageRepo , repoPres := os .LookupEnv ("dockerRepository" )
33
28
imageTag , tagPres := os .LookupEnv ("dockerVersion" )
29
+ namespaceName := "marklogic-" + strings .ToLower (random .UniqueId ())
30
+ kubectlOptions := k8s .NewKubectlOptions ("" , "" , namespaceName )
31
+ dnodeReleaseName := "test-dnode-group"
32
+ enodeReleaseName := "test-enode-group"
33
+ dnodePodName := dnodeReleaseName + "-marklogic-0"
34
+ enodePodName0 := enodeReleaseName + "-marklogic-0"
35
+ enodePodName1 := enodeReleaseName + "-marklogic-1"
36
+
37
+ // Path to the helm chart we will test
38
+ helmChartPath , e := filepath .Abs ("../../charts" )
39
+ if e != nil {
40
+ t .Fatalf (e .Error ())
41
+ }
34
42
35
43
if ! repoPres {
36
44
imageRepo = "marklogic-centos/marklogic-server-centos"
@@ -42,8 +50,6 @@ func TestSeparateEDnode(t *testing.T) {
42
50
t .Logf ("No imageTag variable present, setting to default value: " + imageTag )
43
51
}
44
52
45
- namespaceName := "marklogic-" + strings .ToLower (random .UniqueId ())
46
- kubectlOptions := k8s .NewKubectlOptions ("" , "" , namespaceName )
47
53
options := & helm.Options {
48
54
KubectlOptions : kubectlOptions ,
49
55
SetValues : map [string ]string {
@@ -64,37 +70,33 @@ func TestSeparateEDnode(t *testing.T) {
64
70
defer t .Logf ("====Deleting namespace: " + namespaceName )
65
71
defer k8s .DeleteNamespace (t , kubectlOptions , namespaceName )
66
72
67
- dnodeReleaseName := "test-dnode-group"
68
- t .Logf ("====Installing Helm Chart" + dnodeReleaseName )
73
+ t .Logf ("====Installing Helm Chart " + dnodeReleaseName )
69
74
helm .Install (t , options , helmChartPath , dnodeReleaseName )
70
75
71
- dnodePodName := dnodeReleaseName + "-marklogic-0"
72
-
73
- // wait until the pod is in Ready status
76
+ // wait until the pod is in ready status
74
77
k8s .WaitUntilPodAvailable (t , kubectlOptions , dnodePodName , 10 , 20 * time .Second )
75
78
76
- time .Sleep (10 * time .Second )
77
79
tunnel := k8s .NewTunnel (
78
80
kubectlOptions , k8s .ResourceTypePod , dnodePodName , 8002 , 8002 )
79
81
defer tunnel .Close ()
80
82
tunnel .ForwardPort (t )
83
+
81
84
hostsEndpoint := fmt .Sprintf ("http://%s/manage/v2/hosts?format=json" , tunnel .Endpoint ())
82
85
t .Logf (`Endpoint: %s` , hostsEndpoint )
83
86
84
- dr := digestAuth .NewRequest (username , password , "GET" , hostsEndpoint , "" )
87
+ getHostsDR := digestAuth .NewRequest (username , password , "GET" , hostsEndpoint , "" )
85
88
86
- if resp , err = dr .Execute (); err != nil {
89
+ if resp , err = getHostsDR .Execute (); err != nil {
87
90
t .Fatalf (err .Error ())
88
91
}
89
92
defer resp .Body .Close ()
90
-
91
93
if body , err = ioutil .ReadAll (resp .Body ); err != nil {
92
94
t .Fatalf (err .Error ())
93
95
}
94
- t .Logf ("Response:\n " + string (body ))
96
+ t .Logf ("Get hosts response:\n " + string (body ))
97
+
95
98
bootstrapHost := gjson .Get (string (body ), `host-default-list.list-items.list-item.#(roleref="bootstrap").nameref` )
96
99
t .Logf (`BootstrapHost: = %s` , bootstrapHost )
97
-
98
100
// verify bootstrap host exists on the cluster
99
101
if bootstrapHost .String () == "" {
100
102
t .Errorf ("Bootstrap does not exists on cluster" )
@@ -114,54 +116,48 @@ func TestSeparateEDnode(t *testing.T) {
114
116
"logCollection.enabled" : "false" ,
115
117
},
116
118
}
117
- enodeReleaseName := "test-enode-group"
118
119
t .Logf ("====Installing Helm Chart " + enodeReleaseName )
119
120
helm .Install (t , enodeOptions , helmChartPath , enodeReleaseName )
120
121
121
- enodePodName0 := enodeReleaseName + "-marklogic-0"
122
-
123
122
// wait until the first enode pod is in Ready status
124
123
k8s .WaitUntilPodAvailable (t , kubectlOptions , enodePodName0 , 45 , 20 * time .Second )
125
124
126
125
groupEndpoint := fmt .Sprintf ("http://%s/manage/v2/groups" , tunnel .Endpoint ())
127
126
t .Logf (`Endpoint: %s` , groupEndpoint )
128
127
129
- drGroups := digestAuth .NewRequest (username , password , "GET" , groupEndpoint , "" )
128
+ getGroupsDR := digestAuth .NewRequest (username , password , "GET" , groupEndpoint , "" )
130
129
131
- if resp , err = drGroups .Execute (); err != nil {
130
+ if resp , err = getGroupsDR .Execute (); err != nil {
132
131
t .Fatalf (err .Error ())
133
132
}
134
133
defer resp .Body .Close ()
135
-
136
134
if body , err = ioutil .ReadAll (resp .Body ); err != nil {
137
135
t .Fatalf (err .Error ())
138
136
}
139
- t .Logf ("Response :\n " + string (body ))
137
+ t .Logf ("Groups status response :\n " + string (body ))
140
138
141
139
// verify groups dnode, enode exists on the cluster
142
140
if ! strings .Contains (string (body ), "<nameref>dnode</nameref>" ) && ! strings .Contains (string (body ), "<nameref>enode</nameref>" ) {
143
141
t .Errorf ("Groups does not exists on cluster" )
144
142
}
145
143
146
- enodePodName1 := enodeReleaseName + "-marklogic-1"
147
-
148
144
// wait until the second enode pod is in Ready status
149
145
k8s .WaitUntilPodAvailable (t , kubectlOptions , enodePodName1 , 45 , 20 * time .Second )
150
146
151
147
enodeEndpoint := fmt .Sprintf ("http://%s/manage/v2/groups/enode?format=json" , tunnel .Endpoint ())
152
148
t .Logf (`Endpoint: %s` , enodeEndpoint )
153
149
154
- drEnode := digestAuth .NewRequest (username , password , "GET" , enodeEndpoint , "" )
150
+ getEnodeDR := digestAuth .NewRequest (username , password , "GET" , enodeEndpoint , "" )
155
151
156
- if resp , err = drEnode .Execute (); err != nil {
152
+ if resp , err = getEnodeDR .Execute (); err != nil {
157
153
t .Fatalf (err .Error ())
158
154
}
159
155
defer resp .Body .Close ()
160
156
161
157
if body , err = ioutil .ReadAll (resp .Body ); err != nil {
162
158
t .Fatalf (err .Error ())
163
159
}
164
- t .Logf ("Response :\n " + string (body ))
160
+ t .Logf ("Get enode group response :\n " + string (body ))
165
161
166
162
enodeHostCount := gjson .Get (string (body ), `group-default.relations.relation-group.#(typeref="hosts").relation-count.value` )
167
163
t .Logf (`enodeHostCount: = %s` , enodeHostCount )
@@ -228,7 +224,7 @@ func TestIncorrectBootsrapHostname(t *testing.T) {
228
224
defer t .Logf ("====Deleting namespace: " + namespaceName )
229
225
defer k8s .DeleteNamespace (t , kubectlOptions , namespaceName )
230
226
231
- t .Logf ("====Installing D Node Helm Chart" + dnodeReleaseName )
227
+ t .Logf ("====Installing D Node Helm Chart " + dnodeReleaseName )
232
228
helm .Install (t , options , helmChartPath , dnodeReleaseName )
233
229
234
230
// wait until the pod is in ready status
@@ -257,7 +253,7 @@ func TestIncorrectBootsrapHostname(t *testing.T) {
257
253
258
254
t .Logf ("Response:\n " + string (body ))
259
255
t .Logf (`BootstrapHost: = %s` , bootstrapHost )
260
-
256
+
261
257
// Helm options for enode creation
262
258
enodeOptions := & helm.Options {
263
259
KubectlOptions : kubectlOptions ,
@@ -274,13 +270,13 @@ func TestIncorrectBootsrapHostname(t *testing.T) {
274
270
},
275
271
}
276
272
277
- t .Logf ("====Installing E Node Helm Chart" + enodeReleaseName )
273
+ t .Logf ("====Installing E Node Helm Chart " + enodeReleaseName )
278
274
helm .Install (t , enodeOptions , helmChartPath , enodeReleaseName )
279
275
280
276
// Give pod time to fail before checking if it did
281
277
time .Sleep (20 * time .Second )
282
278
283
- // Verify clustering failed given incorrect hostname
279
+ // Verify clustering failed given incorrect hostname
284
280
clusterStatusEndpoint := fmt .Sprintf ("http://%s/manage/v2?view=status" , tunnel .Endpoint ())
285
281
clusterStatus := digestAuth .NewRequest (username , password , "GET" , clusterStatusEndpoint , "" )
286
282
t .Logf (`clusterStatusEndpoint: %s` , clusterStatusEndpoint )
@@ -289,12 +285,12 @@ func TestIncorrectBootsrapHostname(t *testing.T) {
289
285
}
290
286
totalHostsJson := gjson .Get (string (body ), "host-default-list.list-items.list-count.value" )
291
287
// Total hosts be one as second host should have failed to create
292
- if ( totalHostsJson .Num != 1 ) {
288
+ if totalHostsJson .Num != 1 {
293
289
t .Errorf ("Wrong number of hosts: %v instead of 1" , totalHostsJson .Num )
294
290
}
295
291
t .Logf ("\n Cluster Status Response:\n \n " + string (body ))
296
292
297
- // Verify enode group creation failed given incorrect hostname
293
+ // Verify enode group creation failed given incorrect hostname
298
294
enodeGroupStatusEndpoint := fmt .Sprintf ("http://%s/manage/v2/groups/enode" , tunnel .Endpoint ())
299
295
groupStatus := digestAuth .NewRequest (username , password , "GET" , enodeGroupStatusEndpoint , "" )
300
296
t .Logf (`enodeGroupStatusEndpoint: %s` , enodeGroupStatusEndpoint )
@@ -304,8 +300,91 @@ func TestIncorrectBootsrapHostname(t *testing.T) {
304
300
if body , err = ioutil .ReadAll (resp .Body ); err != nil {
305
301
t .Fatalf (err .Error ())
306
302
}
307
- if ( ! strings .Contains (string (body ), "404" ) ) {
303
+ if ! strings .Contains (string (body ), "404" ) {
308
304
t .Errorf ("Enode group should not exist" )
309
305
}
310
- t .Logf ("\n Enode Group Status Response:\n \n " + string (body ))
306
+ t .Logf ("Enode group status response:\n " + string (body ))
307
+ }
308
+
309
+ func TestDefaultGroup (t * testing.T ) {
310
+ var resp * http.Response
311
+ var body []byte
312
+ var err error
313
+
314
+ username := "admin"
315
+ password := "admin"
316
+ imageRepo , repoPres := os .LookupEnv ("dockerRepository" )
317
+ imageTag , tagPres := os .LookupEnv ("dockerVersion" )
318
+ namespaceName := "marklogic-" + strings .ToLower (random .UniqueId ())
319
+ kubectlOptions := k8s .NewKubectlOptions ("" , "" , namespaceName )
320
+ releaseName := "test-default-group"
321
+ podName := releaseName + "-marklogic-0"
322
+
323
+ // Path to the helm chart we will test
324
+ helmChartPath , e := filepath .Abs ("../../charts" )
325
+
326
+ if e != nil {
327
+ t .Fatalf (e .Error ())
328
+ }
329
+
330
+ if ! repoPres {
331
+ imageRepo = "marklogic-centos/marklogic-server-centos"
332
+ t .Logf ("No imageRepo variable present, setting to default value: " + imageRepo )
333
+ }
334
+
335
+ if ! tagPres {
336
+ imageTag = "10-internal"
337
+ t .Logf ("No imageTag variable present, setting to default value: " + imageTag )
338
+ }
339
+
340
+ // Helm options for enode creation
341
+ noGroupOptions := & helm.Options {
342
+ KubectlOptions : kubectlOptions ,
343
+ SetValues : map [string ]string {
344
+ "replicaCount" : "1" ,
345
+ "image.repository" : imageRepo ,
346
+ "image.tag" : imageTag ,
347
+ "auth.adminUsername" : username ,
348
+ "auth.adminPassword" : password ,
349
+ "logCollection.enabled" : "false" ,
350
+ },
351
+ }
352
+
353
+ t .Logf ("====Creating namespace: " + namespaceName )
354
+ k8s .CreateNamespace (t , kubectlOptions , namespaceName )
355
+
356
+ defer t .Logf ("====Deleting namespace: " + namespaceName )
357
+ defer k8s .DeleteNamespace (t , kubectlOptions , namespaceName )
358
+
359
+ t .Logf ("====Installing No Group Helm Chart " + releaseName )
360
+ helm .Install (t , noGroupOptions , helmChartPath , releaseName )
361
+
362
+ // wait until the pod is in ready status
363
+ k8s .WaitUntilPodAvailable (t , kubectlOptions , podName , 10 , 20 * time .Second )
364
+
365
+ tunnel := k8s .NewTunnel (
366
+ kubectlOptions , k8s .ResourceTypePod , podName , 8002 , 8002 )
367
+
368
+ defer tunnel .Close ()
369
+
370
+ tunnel .ForwardPort (t )
371
+
372
+ // Verify enode group creation failed given incorrect hostname
373
+ groupStatusEndpoint := fmt .Sprintf ("http://%s/manage/v2/groups?format=json" , tunnel .Endpoint ())
374
+ groupStatus := digestAuth .NewRequest (username , password , "GET" , groupStatusEndpoint , "" )
375
+ t .Logf (`groupStatusEndpoint: %s` , groupStatusEndpoint )
376
+ if resp , err = groupStatus .Execute (); err != nil {
377
+ t .Fatalf (err .Error ())
378
+ }
379
+ if body , err = ioutil .ReadAll (resp .Body ); err != nil {
380
+ t .Fatalf (err .Error ())
381
+ }
382
+ groupName := gjson .Get (string (body ), "group-default-list.list-items.list-item[0].nameref" )
383
+ groupQuantity := gjson .Get (string (body ), "group-default-list.list-items.list-count.value" )
384
+
385
+ if groupName .Str != "Default" && groupQuantity .Num != 1 {
386
+ t .Errorf ("Only group should exist and it should be the Default group, instead %v groups exist and the first group is named %v" , groupQuantity .Num , groupName .Str )
387
+ }
388
+
389
+ t .Logf ("Groups status response:\n " + string (body ))
311
390
}
0 commit comments