Skip to content

Commit dbe369c

Browse files
committed
Add test to verify "The group should not be updated if the Default group is passed"
1 parent a8107b9 commit dbe369c

File tree

1 file changed

+119
-40
lines changed

1 file changed

+119
-40
lines changed

test/e2e/separate_nodes_test.go

Lines changed: 119 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -18,19 +18,27 @@ import (
1818
)
1919

2020
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"
2821
var resp *http.Response
2922
var body []byte
3023
var err error
3124

25+
username := "admin"
26+
password := "admin"
3227
imageRepo, repoPres := os.LookupEnv("dockerRepository")
3328
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+
}
3442

3543
if !repoPres {
3644
imageRepo = "marklogic-centos/marklogic-server-centos"
@@ -42,8 +50,6 @@ func TestSeparateEDnode(t *testing.T) {
4250
t.Logf("No imageTag variable present, setting to default value: " + imageTag)
4351
}
4452

45-
namespaceName := "marklogic-" + strings.ToLower(random.UniqueId())
46-
kubectlOptions := k8s.NewKubectlOptions("", "", namespaceName)
4753
options := &helm.Options{
4854
KubectlOptions: kubectlOptions,
4955
SetValues: map[string]string{
@@ -64,37 +70,33 @@ func TestSeparateEDnode(t *testing.T) {
6470
defer t.Logf("====Deleting namespace: " + namespaceName)
6571
defer k8s.DeleteNamespace(t, kubectlOptions, namespaceName)
6672

67-
dnodeReleaseName := "test-dnode-group"
68-
t.Logf("====Installing Helm Chart" + dnodeReleaseName)
73+
t.Logf("====Installing Helm Chart " + dnodeReleaseName)
6974
helm.Install(t, options, helmChartPath, dnodeReleaseName)
7075

71-
dnodePodName := dnodeReleaseName + "-marklogic-0"
72-
73-
// wait until the pod is in Ready status
76+
// wait until the pod is in ready status
7477
k8s.WaitUntilPodAvailable(t, kubectlOptions, dnodePodName, 10, 20*time.Second)
7578

76-
time.Sleep(10 * time.Second)
7779
tunnel := k8s.NewTunnel(
7880
kubectlOptions, k8s.ResourceTypePod, dnodePodName, 8002, 8002)
7981
defer tunnel.Close()
8082
tunnel.ForwardPort(t)
83+
8184
hostsEndpoint := fmt.Sprintf("http://%s/manage/v2/hosts?format=json", tunnel.Endpoint())
8285
t.Logf(`Endpoint: %s`, hostsEndpoint)
8386

84-
dr := digestAuth.NewRequest(username, password, "GET", hostsEndpoint, "")
87+
getHostsDR := digestAuth.NewRequest(username, password, "GET", hostsEndpoint, "")
8588

86-
if resp, err = dr.Execute(); err != nil {
89+
if resp, err = getHostsDR.Execute(); err != nil {
8790
t.Fatalf(err.Error())
8891
}
8992
defer resp.Body.Close()
90-
9193
if body, err = ioutil.ReadAll(resp.Body); err != nil {
9294
t.Fatalf(err.Error())
9395
}
94-
t.Logf("Response:\n" + string(body))
96+
t.Logf("Get hosts response:\n" + string(body))
97+
9598
bootstrapHost := gjson.Get(string(body), `host-default-list.list-items.list-item.#(roleref="bootstrap").nameref`)
9699
t.Logf(`BootstrapHost: = %s`, bootstrapHost)
97-
98100
// verify bootstrap host exists on the cluster
99101
if bootstrapHost.String() == "" {
100102
t.Errorf("Bootstrap does not exists on cluster")
@@ -114,54 +116,48 @@ func TestSeparateEDnode(t *testing.T) {
114116
"logCollection.enabled": "false",
115117
},
116118
}
117-
enodeReleaseName := "test-enode-group"
118119
t.Logf("====Installing Helm Chart " + enodeReleaseName)
119120
helm.Install(t, enodeOptions, helmChartPath, enodeReleaseName)
120121

121-
enodePodName0 := enodeReleaseName + "-marklogic-0"
122-
123122
// wait until the first enode pod is in Ready status
124123
k8s.WaitUntilPodAvailable(t, kubectlOptions, enodePodName0, 45, 20*time.Second)
125124

126125
groupEndpoint := fmt.Sprintf("http://%s/manage/v2/groups", tunnel.Endpoint())
127126
t.Logf(`Endpoint: %s`, groupEndpoint)
128127

129-
drGroups := digestAuth.NewRequest(username, password, "GET", groupEndpoint, "")
128+
getGroupsDR := digestAuth.NewRequest(username, password, "GET", groupEndpoint, "")
130129

131-
if resp, err = drGroups.Execute(); err != nil {
130+
if resp, err = getGroupsDR.Execute(); err != nil {
132131
t.Fatalf(err.Error())
133132
}
134133
defer resp.Body.Close()
135-
136134
if body, err = ioutil.ReadAll(resp.Body); err != nil {
137135
t.Fatalf(err.Error())
138136
}
139-
t.Logf("Response:\n" + string(body))
137+
t.Logf("Groups status response:\n" + string(body))
140138

141139
// verify groups dnode, enode exists on the cluster
142140
if !strings.Contains(string(body), "<nameref>dnode</nameref>") && !strings.Contains(string(body), "<nameref>enode</nameref>") {
143141
t.Errorf("Groups does not exists on cluster")
144142
}
145143

146-
enodePodName1 := enodeReleaseName + "-marklogic-1"
147-
148144
// wait until the second enode pod is in Ready status
149145
k8s.WaitUntilPodAvailable(t, kubectlOptions, enodePodName1, 45, 20*time.Second)
150146

151147
enodeEndpoint := fmt.Sprintf("http://%s/manage/v2/groups/enode?format=json", tunnel.Endpoint())
152148
t.Logf(`Endpoint: %s`, enodeEndpoint)
153149

154-
drEnode := digestAuth.NewRequest(username, password, "GET", enodeEndpoint, "")
150+
getEnodeDR := digestAuth.NewRequest(username, password, "GET", enodeEndpoint, "")
155151

156-
if resp, err = drEnode.Execute(); err != nil {
152+
if resp, err = getEnodeDR.Execute(); err != nil {
157153
t.Fatalf(err.Error())
158154
}
159155
defer resp.Body.Close()
160156

161157
if body, err = ioutil.ReadAll(resp.Body); err != nil {
162158
t.Fatalf(err.Error())
163159
}
164-
t.Logf("Response:\n" + string(body))
160+
t.Logf("Get enode group response:\n" + string(body))
165161

166162
enodeHostCount := gjson.Get(string(body), `group-default.relations.relation-group.#(typeref="hosts").relation-count.value`)
167163
t.Logf(`enodeHostCount: = %s`, enodeHostCount)
@@ -228,7 +224,7 @@ func TestIncorrectBootsrapHostname(t *testing.T) {
228224
defer t.Logf("====Deleting namespace: " + namespaceName)
229225
defer k8s.DeleteNamespace(t, kubectlOptions, namespaceName)
230226

231-
t.Logf("====Installing D Node Helm Chart" + dnodeReleaseName)
227+
t.Logf("====Installing D Node Helm Chart " + dnodeReleaseName)
232228
helm.Install(t, options, helmChartPath, dnodeReleaseName)
233229

234230
// wait until the pod is in ready status
@@ -257,7 +253,7 @@ func TestIncorrectBootsrapHostname(t *testing.T) {
257253

258254
t.Logf("Response:\n" + string(body))
259255
t.Logf(`BootstrapHost: = %s`, bootstrapHost)
260-
256+
261257
// Helm options for enode creation
262258
enodeOptions := &helm.Options{
263259
KubectlOptions: kubectlOptions,
@@ -274,13 +270,13 @@ func TestIncorrectBootsrapHostname(t *testing.T) {
274270
},
275271
}
276272

277-
t.Logf("====Installing E Node Helm Chart" + enodeReleaseName)
273+
t.Logf("====Installing E Node Helm Chart " + enodeReleaseName)
278274
helm.Install(t, enodeOptions, helmChartPath, enodeReleaseName)
279275

280276
// Give pod time to fail before checking if it did
281277
time.Sleep(20 * time.Second)
282278

283-
// Verify clustering failed given incorrect hostname
279+
// Verify clustering failed given incorrect hostname
284280
clusterStatusEndpoint := fmt.Sprintf("http://%s/manage/v2?view=status", tunnel.Endpoint())
285281
clusterStatus := digestAuth.NewRequest(username, password, "GET", clusterStatusEndpoint, "")
286282
t.Logf(`clusterStatusEndpoint: %s`, clusterStatusEndpoint)
@@ -289,12 +285,12 @@ func TestIncorrectBootsrapHostname(t *testing.T) {
289285
}
290286
totalHostsJson := gjson.Get(string(body), "host-default-list.list-items.list-count.value")
291287
// Total hosts be one as second host should have failed to create
292-
if (totalHostsJson.Num != 1) {
288+
if totalHostsJson.Num != 1 {
293289
t.Errorf("Wrong number of hosts: %v instead of 1", totalHostsJson.Num)
294290
}
295291
t.Logf("\nCluster Status Response:\n\n" + string(body))
296292

297-
// Verify enode group creation failed given incorrect hostname
293+
// Verify enode group creation failed given incorrect hostname
298294
enodeGroupStatusEndpoint := fmt.Sprintf("http://%s/manage/v2/groups/enode", tunnel.Endpoint())
299295
groupStatus := digestAuth.NewRequest(username, password, "GET", enodeGroupStatusEndpoint, "")
300296
t.Logf(`enodeGroupStatusEndpoint: %s`, enodeGroupStatusEndpoint)
@@ -304,8 +300,91 @@ func TestIncorrectBootsrapHostname(t *testing.T) {
304300
if body, err = ioutil.ReadAll(resp.Body); err != nil {
305301
t.Fatalf(err.Error())
306302
}
307-
if (!strings.Contains(string(body), "404")) {
303+
if !strings.Contains(string(body), "404") {
308304
t.Errorf("Enode group should not exist")
309305
}
310-
t.Logf("\nEnode 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))
311390
}

0 commit comments

Comments
 (0)