1
+ package e2e
2
+
3
+ import (
4
+ "fmt"
5
+ "io/ioutil"
6
+ "net/http"
7
+ "path/filepath"
8
+ "strings"
9
+ "testing"
10
+ "time"
11
+
12
+ "github.com/gruntwork-io/terratest/modules/helm"
13
+ "github.com/gruntwork-io/terratest/modules/k8s"
14
+ "github.com/gruntwork-io/terratest/modules/random"
15
+ digest_auth "github.com/xinsnake/go-http-digest-auth-client"
16
+ "github.com/tidwall/gjson"
17
+ )
18
+
19
+ func TestSeparateEDnode (t * testing.T ) {
20
+ // Path to the helm chart we will test
21
+ helmChartPath , e := filepath .Abs ("../../charts" )
22
+ if (e != nil ) {
23
+ t .Fatalf (e .Error ())
24
+ }
25
+ username := "admin"
26
+ password := "admin"
27
+ var resp * http.Response
28
+ var body []byte
29
+ var err error
30
+
31
+ namespaceName := "marklogic-" + strings .ToLower (random .UniqueId ())
32
+ kubectlOptions := k8s .NewKubectlOptions ("" , "" , namespaceName )
33
+ options := & helm.Options {
34
+ KubectlOptions : kubectlOptions ,
35
+ SetValues : map [string ]string {
36
+ "persistence.enabled" : "false" ,
37
+ "replicaCount" : "1" ,
38
+ "image.repository" : "marklogic-centos/marklogic-server-centos" ,
39
+ "image.tag" : "10-internal" ,
40
+ "auth.adminUsername" : username ,
41
+ "auth.adminPassword" : password ,
42
+ "group.name" : "dnode" ,
43
+ "logCollection.enabled" : "false" ,
44
+ },
45
+ }
46
+
47
+ t .Logf ("====Creating namespace: " + namespaceName )
48
+ k8s .CreateNamespace (t , kubectlOptions , namespaceName )
49
+
50
+ defer t .Logf ("====Deleting namespace: " + namespaceName )
51
+ defer k8s .DeleteNamespace (t , kubectlOptions , namespaceName )
52
+
53
+ releaseName := "test-dnode-group"
54
+ t .Logf ("====Installing Helm Chart" + releaseName )
55
+ helm .Install (t , options , helmChartPath , releaseName )
56
+
57
+ podName := releaseName + "-marklogic-0"
58
+
59
+ // wait until the pod is in Ready status
60
+ k8s .WaitUntilPodAvailable (t , kubectlOptions , podName , 10 , 20 * time .Second )
61
+
62
+ time .Sleep (10 * time .Second )
63
+ tunnel := k8s .NewTunnel (
64
+ kubectlOptions , k8s .ResourceTypePod , podName , 8002 , 8002 )
65
+ defer tunnel .Close ()
66
+ tunnel .ForwardPort (t )
67
+ hosts_endpoint := fmt .Sprintf ("http://%s/manage/v2/hosts?format=json" , tunnel .Endpoint ())
68
+ t .Logf (`Endpoint: %s` , hosts_endpoint )
69
+
70
+ dr := digest_auth .NewRequest (username , password , "GET" , hosts_endpoint , "" )
71
+
72
+ if resp , err = dr .Execute (); err != nil {
73
+ t .Fatalf (err .Error ())
74
+ }
75
+ defer resp .Body .Close ()
76
+
77
+ if body , err = ioutil .ReadAll (resp .Body ); err != nil {
78
+ t .Fatalf (err .Error ())
79
+ }
80
+ t .Logf ("Response:\n " + string (body ))
81
+ bootstrapHost := gjson .Get (string (body ), `host-default-list.list-items.list-item.#(roleref="bootstrap").nameref` )
82
+ t .Logf (`BootstrapHost: = %s` , bootstrapHost )
83
+
84
+ enodeOptions := & helm.Options {
85
+ KubectlOptions : kubectlOptions ,
86
+ SetValues : map [string ]string {
87
+ "persistence.enabled" : "false" ,
88
+ "replicaCount" : "2" ,
89
+ "image.repository" : "marklogic-centos/marklogic-server-centos" ,
90
+ "image.tag" : "10-internal" ,
91
+ "auth.adminUsername" : username ,
92
+ "auth.adminPassword" : password ,
93
+ "group.name" : "enode" ,
94
+ "bootstrapHostName" : bootstrapHost .String (),
95
+ "logCollection.enabled" : "false" ,
96
+ },
97
+ }
98
+ releaseName2 := "test-enode-group"
99
+ t .Logf ("====Installing Helm Chart " + releaseName2 )
100
+ helm .Install (t , enodeOptions , helmChartPath , releaseName2 )
101
+
102
+ enodePodName := releaseName2 + "-marklogic-0"
103
+
104
+ // wait until the pod is in Ready status
105
+ k8s .WaitUntilPodAvailable (t , kubectlOptions , enodePodName , 15 , 20 * time .Second )
106
+
107
+ group_endpoint := fmt .Sprintf ("http://%s/manage/v2/groups" , tunnel .Endpoint ())
108
+ t .Logf (`Endpoint: %s` , group_endpoint )
109
+
110
+ dr_groups := digest_auth .NewRequest (username , password , "GET" , group_endpoint , "" )
111
+
112
+ if resp , err = dr_groups .Execute (); err != nil {
113
+ t .Fatalf (err .Error ())
114
+ }
115
+ defer resp .Body .Close ()
116
+
117
+ if body , err = ioutil .ReadAll (resp .Body ); err != nil {
118
+ t .Fatalf (err .Error ())
119
+ }
120
+ t .Logf ("Response:\n " + string (body ))
121
+
122
+ // verify groups dnode, enode exists on the cluster
123
+ if ! strings .Contains (string (body ), "<nameref>dnode</nameref>" ) && ! strings .Contains (string (body ), "<nameref>enode</nameref>" ) {
124
+ t .Errorf ("Groups does not exists on cluster" )
125
+ }
126
+
127
+ }
0 commit comments