@@ -3,48 +3,110 @@ package e2e
3
3
import (
4
4
"crypto/tls"
5
5
"fmt"
6
+ "io/ioutil"
7
+ "log"
8
+ "net/http"
9
+ "os"
6
10
"path/filepath"
7
11
"strings"
8
12
"testing"
9
13
"time"
10
-
14
+
11
15
"github.com/gruntwork-io/terratest/modules/helm"
12
16
http_helper "github.com/gruntwork-io/terratest/modules/http-helper"
13
17
"github.com/gruntwork-io/terratest/modules/k8s"
14
18
"github.com/gruntwork-io/terratest/modules/random"
19
+ digest_auth "github.com/judgegregg/go-http-digest-auth-client"
15
20
"github.com/stretchr/testify/require"
16
21
)
17
22
18
- func TestHelmInstall (t * testing.T ) {
19
- // Path to the helm chart we will test
20
- helmChartPath , err := filepath .Abs ("../../charts" )
21
- releaseName := "marklogic-test"
22
- t .Log (helmChartPath , releaseName )
23
+ // Path to the helm chart we will test
24
+ var helmChartPath , err = filepath .Abs ("../../charts" )
25
+ var releaseName string = "test"
26
+ var namespaceName string = "marklogic-" + strings .ToLower (random .UniqueId ())
27
+ var kubectlOptions = k8s .NewKubectlOptions ("" , "" , namespaceName )
28
+ var options = & helm.Options {
29
+ KubectlOptions : kubectlOptions ,
30
+ SetValues : map [string ]string {
31
+ "persistence.enabled" : "false" ,
32
+ "replicaCount" : "1" ,
33
+ "image.repository" : "marklogic-centos/marklogic-server-centos" ,
34
+ "image.tag" : "10-internal" ,
35
+ },
36
+ }
37
+
38
+ func TestMain (m * testing.M ) {
39
+ t := & testing.T {}
23
40
require .NoError (t , err )
24
- namespaceName := "marklogic-" + strings .ToLower (random .UniqueId ())
25
- t .Logf ("creating namespace: %s" , namespaceName )
26
- kubectlOptions := k8s .NewKubectlOptions ("" , "" , namespaceName )
41
+ log .Println ("====Creating namespace: " + namespaceName )
27
42
28
43
// create a new namespace for testing
29
44
k8s .CreateNamespace (t , kubectlOptions , namespaceName )
30
45
31
- defer k8s .DeleteNamespace (t , kubectlOptions , namespaceName )
32
- options := & helm.Options {
46
+ // anything before this runs before the tests run
47
+ exitVal := m .Run ()
48
+ // anything after this runs after the tests run
49
+ log .Println ("====Deleting Helm Releases: " + namespaceName )
50
+ helm .Delete (t , options , releaseName + "-upgrade" , true )
51
+ helm .Delete (t , options , releaseName + "-install" , true )
52
+ helm .Delete (t , options , releaseName + "-join" , true )
53
+ log .Println ("====Deleting namespace: " + namespaceName )
54
+ k8s .DeleteNamespace (t , kubectlOptions , namespaceName )
55
+
56
+ os .Exit (exitVal )
57
+ }
58
+
59
+ func TestHelmInstall (t * testing.T ) {
60
+ t .Logf ("====Installing Helm Chart" )
61
+ releaseName := releaseName + "-install"
62
+ helm .Install (t , options , helmChartPath , releaseName )
63
+
64
+ tlsConfig := tls.Config {}
65
+ podName := releaseName + "-marklogic-0"
66
+ // wait until the pod is in Ready status
67
+ k8s .WaitUntilPodAvailable (t , kubectlOptions , podName , 10 , 15 * time .Second )
68
+ tunnel := k8s .NewTunnel (
69
+ kubectlOptions , k8s .ResourceTypePod , podName , 7997 , 7997 )
70
+ defer tunnel .Close ()
71
+ tunnel .ForwardPort (t )
72
+ endpoint := fmt .Sprintf ("http://%s" , tunnel .Endpoint ())
73
+ t .Logf (`Endpoint: %s` , endpoint )
74
+
75
+ http_helper .HttpGetWithRetryWithCustomValidation (
76
+ t ,
77
+ endpoint ,
78
+ & tlsConfig ,
79
+ 10 ,
80
+ 15 * time .Second ,
81
+ func (statusCode int , body string ) bool {
82
+ return statusCode == 200
83
+ },
84
+ )
85
+ }
86
+
87
+ func TestHelmUpgrade (t * testing.T ) {
88
+ t .Logf ("====Installing Helm Chart" )
89
+ releaseName := releaseName + "-upgrade"
90
+ helm .Install (t , options , helmChartPath , releaseName )
91
+
92
+ newOptions := & helm.Options {
33
93
KubectlOptions : kubectlOptions ,
34
94
SetValues : map [string ]string {
35
95
"persistence.enabled" : "false" ,
96
+ "replicaCount" : "2" ,
97
+ "image.repository" : "marklogic-centos/marklogic-server-centos" ,
98
+ "image.tag" : "10-internal" ,
36
99
},
37
100
}
38
101
39
- defer helm .Delete (t , options , releaseName , true )
40
-
41
- //install Helm Chart for testing
42
- helm .Install (t , options , helmChartPath , releaseName )
102
+ t .Logf ("====Upgrading Helm Chart" )
103
+ helm .Upgrade (t , newOptions , helmChartPath , releaseName )
43
104
44
105
tlsConfig := tls.Config {}
45
- podName := "marklogic-0"
106
+ podName := releaseName + "-marklogic-1"
107
+
46
108
// wait until the pod is in Ready status
47
- k8s .WaitUntilPodAvailable (t , kubectlOptions , podName , 10 , 10 * time .Second )
109
+ k8s .WaitUntilPodAvailable (t , kubectlOptions , podName , 10 , 20 * time .Second )
48
110
tunnel := k8s .NewTunnel (
49
111
kubectlOptions , k8s .ResourceTypePod , podName , 7997 , 7997 )
50
112
defer tunnel .Close ()
@@ -63,3 +125,53 @@ func TestHelmInstall(t *testing.T) {
63
125
},
64
126
)
65
127
}
128
+
129
+ func TestClusterJoin (t * testing.T ) {
130
+ var username string = "admin"
131
+ var password string = "admin"
132
+ var resp * http.Response
133
+ var body []byte
134
+ var err error
135
+
136
+ options := & helm.Options {
137
+ KubectlOptions : kubectlOptions ,
138
+ SetValues : map [string ]string {
139
+ "persistence.enabled" : "false" ,
140
+ "replicaCount" : "2" ,
141
+ "image.repository" : "marklogic-centos/marklogic-server-centos" ,
142
+ "image.tag" : "10-internal" ,
143
+ "auth.adminUsername" : username ,
144
+ "auth.adminPassword" : password ,
145
+ },
146
+ }
147
+ t .Logf ("====Installing Helm Chart" )
148
+ releaseName := releaseName + "-join"
149
+ helm .Install (t , options , helmChartPath , releaseName )
150
+
151
+ podName := releaseName + "-marklogic-1"
152
+
153
+ // wait until the pod is in Ready status
154
+ k8s .WaitUntilPodAvailable (t , kubectlOptions , podName , 10 , 20 * time .Second )
155
+ tunnel := k8s .NewTunnel (
156
+ kubectlOptions , k8s .ResourceTypePod , podName , 8002 , 8002 )
157
+ defer tunnel .Close ()
158
+ tunnel .ForwardPort (t )
159
+ endpoint := fmt .Sprintf ("http://%s/manage/v2/hosts" , tunnel .Endpoint ())
160
+ t .Logf (`Endpoint: %s` , endpoint )
161
+
162
+ dr := digest_auth .NewRequest (username , password , "GET" , endpoint , "" )
163
+
164
+ if resp , err = dr .Execute (); err != nil {
165
+ log .Fatalln (err )
166
+ }
167
+ defer resp .Body .Close ()
168
+
169
+ if body , err = ioutil .ReadAll (resp .Body ); err != nil {
170
+ log .Fatalln (err )
171
+ }
172
+
173
+ t .Logf ("Response:\n " + string (body ))
174
+ if ! strings .Contains (string (body ), "<list-count units=\" quantity\" >2</list-count>" ) {
175
+ t .Errorf ("Wrong number of hosts" )
176
+ }
177
+ }
0 commit comments