@@ -6,57 +6,38 @@ import (
6
6
"io/ioutil"
7
7
"log"
8
8
"net/http"
9
- "os"
10
9
"path/filepath"
11
10
"strings"
12
11
"testing"
13
12
"time"
14
-
13
+
15
14
"github.com/gruntwork-io/terratest/modules/helm"
16
15
http_helper "github.com/gruntwork-io/terratest/modules/http-helper"
17
16
"github.com/gruntwork-io/terratest/modules/k8s"
18
17
"github.com/gruntwork-io/terratest/modules/random"
19
18
digest_auth "github.com/judgegregg/go-http-digest-auth-client"
20
- "github.com/stretchr/testify/require"
21
19
)
22
20
23
21
// Path to the helm chart we will test
24
22
var helmChartPath , err = filepath .Abs ("../../charts" )
25
23
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
24
38
- func TestMain (m * testing.M ) {
39
- t := & testing.T {}
40
- require .NoError (t , err )
41
- log .Println ("====Creating namespace: " + namespaceName )
25
+ func TestHelmInstall (t * testing.T ) {
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
+ }
42
37
43
- // create a new namespace for testing
38
+ log . Println ( "====Creating namespace: " + namespaceName )
44
39
k8s .CreateNamespace (t , kubectlOptions , namespaceName )
45
40
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
41
t .Logf ("====Installing Helm Chart" )
61
42
releaseName := releaseName + "-install"
62
43
helm .Install (t , options , helmChartPath , releaseName )
@@ -82,9 +63,27 @@ func TestHelmInstall(t *testing.T) {
82
63
return statusCode == 200
83
64
},
84
65
)
66
+
67
+ log .Println ("====Deleting namespace: " + namespaceName )
68
+ k8s .DeleteNamespace (t , kubectlOptions , namespaceName )
85
69
}
86
70
87
71
func TestHelmUpgrade (t * testing.T ) {
72
+ var namespaceName string = "marklogic-" + strings .ToLower (random .UniqueId ())
73
+ var kubectlOptions = k8s .NewKubectlOptions ("" , "" , namespaceName )
74
+ var options = & helm.Options {
75
+ KubectlOptions : kubectlOptions ,
76
+ SetValues : map [string ]string {
77
+ "persistence.enabled" : "false" ,
78
+ "replicaCount" : "1" ,
79
+ "image.repository" : "marklogic-centos/marklogic-server-centos" ,
80
+ "image.tag" : "10-internal" ,
81
+ },
82
+ }
83
+
84
+ log .Println ("====Creating namespace: " + namespaceName )
85
+ k8s .CreateNamespace (t , kubectlOptions , namespaceName )
86
+
88
87
t .Logf ("====Installing Helm Chart" )
89
88
releaseName := releaseName + "-upgrade"
90
89
helm .Install (t , options , helmChartPath , releaseName )
@@ -124,9 +123,14 @@ func TestHelmUpgrade(t *testing.T) {
124
123
return statusCode == 200
125
124
},
126
125
)
126
+
127
+ log .Println ("====Deleting namespace: " + namespaceName )
128
+ k8s .DeleteNamespace (t , kubectlOptions , namespaceName )
127
129
}
128
130
129
131
func TestClusterJoin (t * testing.T ) {
132
+ var namespaceName string = "marklogic-" + strings .ToLower (random .UniqueId ())
133
+ var kubectlOptions = k8s .NewKubectlOptions ("" , "" , namespaceName )
130
134
var username string = "admin"
131
135
var password string = "admin"
132
136
var resp * http.Response
@@ -144,6 +148,10 @@ func TestClusterJoin(t *testing.T) {
144
148
"auth.adminPassword" : password ,
145
149
},
146
150
}
151
+
152
+ log .Println ("====Creating namespace: " + namespaceName )
153
+ k8s .CreateNamespace (t , kubectlOptions , namespaceName )
154
+
147
155
t .Logf ("====Installing Helm Chart" )
148
156
releaseName := releaseName + "-join"
149
157
helm .Install (t , options , helmChartPath , releaseName )
@@ -160,7 +168,7 @@ func TestClusterJoin(t *testing.T) {
160
168
t .Logf (`Endpoint: %s` , endpoint )
161
169
162
170
dr := digest_auth .NewRequest (username , password , "GET" , endpoint , "" )
163
-
171
+
164
172
if resp , err = dr .Execute (); err != nil {
165
173
log .Fatalln (err )
166
174
}
@@ -174,4 +182,7 @@ func TestClusterJoin(t *testing.T) {
174
182
if ! strings .Contains (string (body ), "<list-count units=\" quantity\" >2</list-count>" ) {
175
183
t .Errorf ("Wrong number of hosts" )
176
184
}
185
+
186
+ log .Println ("====Deleting namespace: " + namespaceName )
187
+ k8s .DeleteNamespace (t , kubectlOptions , namespaceName )
177
188
}
0 commit comments