@@ -3,7 +3,6 @@ package e2e
3
3
import (
4
4
"fmt"
5
5
"io/ioutil"
6
- "net/http"
7
6
"os"
8
7
"path/filepath"
9
8
"strings"
@@ -13,15 +12,12 @@ import (
13
12
"github.com/gruntwork-io/terratest/modules/helm"
14
13
"github.com/gruntwork-io/terratest/modules/k8s"
15
14
"github.com/gruntwork-io/terratest/modules/random"
15
+ "github.com/stretchr/testify/assert"
16
16
"github.com/tidwall/gjson"
17
17
digestAuth "github.com/xinsnake/go-http-digest-auth-client"
18
18
)
19
19
20
20
func TestSeparateEDnode (t * testing.T ) {
21
- var resp * http.Response
22
- var body []byte
23
- var err error
24
-
25
21
username := "admin"
26
22
password := "admin"
27
23
imageRepo , repoPres := os .LookupEnv ("dockerRepository" )
@@ -86,11 +82,13 @@ func TestSeparateEDnode(t *testing.T) {
86
82
87
83
getHostsDR := digestAuth .NewRequest (username , password , "GET" , hostsEndpoint , "" )
88
84
89
- if resp , err = getHostsDR .Execute (); err != nil {
85
+ resp , err := getHostsDR .Execute ()
86
+ if err != nil {
90
87
t .Fatalf (err .Error ())
91
88
}
92
89
defer resp .Body .Close ()
93
- if body , err = ioutil .ReadAll (resp .Body ); err != nil {
90
+ body , err := ioutil .ReadAll (resp .Body )
91
+ if err != nil {
94
92
t .Fatalf (err .Error ())
95
93
}
96
94
t .Logf ("Get hosts response:\n " + string (body ))
@@ -149,12 +147,14 @@ func TestSeparateEDnode(t *testing.T) {
149
147
150
148
getEnodeDR := digestAuth .NewRequest (username , password , "GET" , enodeEndpoint , "" )
151
149
152
- if resp , err = getEnodeDR .Execute (); err != nil {
150
+ resp , err = getEnodeDR .Execute ()
151
+ if err != nil {
153
152
t .Fatalf (err .Error ())
154
153
}
155
154
defer resp .Body .Close ()
156
155
157
- if body , err = ioutil .ReadAll (resp .Body ); err != nil {
156
+ body , err = ioutil .ReadAll (resp .Body )
157
+ if err != nil {
158
158
t .Fatalf (err .Error ())
159
159
}
160
160
t .Logf ("Get enode group response:\n " + string (body ))
@@ -169,10 +169,6 @@ func TestSeparateEDnode(t *testing.T) {
169
169
}
170
170
171
171
func TestIncorrectBootsrapHostname (t * testing.T ) {
172
- var resp * http.Response
173
- var body []byte
174
- var err error
175
-
176
172
username := "admin"
177
173
password := "admin"
178
174
imageRepo , repoPres := os .LookupEnv ("dockerRepository" )
@@ -184,7 +180,7 @@ func TestIncorrectBootsrapHostname(t *testing.T) {
184
180
dnodePodName := dnodeReleaseName + "-marklogic-0"
185
181
186
182
// Incorrect boostrap hostname for negative test
187
- bootstrapHost := "Incorrect Host Name"
183
+ incorrectBootstrapHost := "Incorrect Host Name"
188
184
189
185
// Path to the helm chart we will test
190
186
helmChartPath , e := filepath .Abs ("../../charts" )
@@ -240,19 +236,19 @@ func TestIncorrectBootsrapHostname(t *testing.T) {
240
236
t .Logf (`Endpoint: %s` , hostsEndpoint )
241
237
242
238
getHostsRequest := digestAuth .NewRequest (username , password , "GET" , hostsEndpoint , "" )
243
-
244
- if resp , err = getHostsRequest . Execute (); err != nil {
239
+ resp , err := getHostsRequest . Execute ()
240
+ if err != nil {
245
241
t .Fatalf (err .Error ())
246
242
}
247
243
248
244
defer resp .Body .Close ()
249
245
250
- if body , err = ioutil .ReadAll (resp .Body ); err != nil {
246
+ body , err := ioutil .ReadAll (resp .Body )
247
+ if err != nil {
251
248
t .Fatalf (err .Error ())
252
249
}
253
250
254
- t .Logf ("Response:\n " + string (body ))
255
- t .Logf (`BootstrapHost: = %s` , bootstrapHost )
251
+ t .Logf (`BootstrapHost: = %s` , incorrectBootstrapHost )
256
252
257
253
// Helm options for enode creation
258
254
enodeOptions := & helm.Options {
@@ -265,7 +261,7 @@ func TestIncorrectBootsrapHostname(t *testing.T) {
265
261
"auth.adminUsername" : username ,
266
262
"auth.adminPassword" : password ,
267
263
"group.name" : "enode" ,
268
- "bootstrapHostName" : bootstrapHost ,
264
+ "bootstrapHostName" : incorrectBootstrapHost ,
269
265
"logCollection.enabled" : "false" ,
270
266
},
271
267
}
@@ -276,32 +272,34 @@ func TestIncorrectBootsrapHostname(t *testing.T) {
276
272
// Give pod time to fail before checking if it did
277
273
time .Sleep (20 * time .Second )
278
274
275
+ totalHostsJSON := gjson .Get (string (body ), "host-default-list.list-items.list-count.value" )
276
+
277
+ // Total hosts be one as second host should have failed to create
278
+ if totalHostsJSON .Num != 1 {
279
+ t .Errorf ("Wrong number of hosts: %v instead of 1" , totalHostsJSON .Num )
280
+ }
281
+
279
282
// Verify clustering failed given incorrect hostname
280
283
clusterStatusEndpoint := fmt .Sprintf ("http://%s/manage/v2?view=status" , tunnel .Endpoint ())
281
284
clusterStatus := digestAuth .NewRequest (username , password , "GET" , clusterStatusEndpoint , "" )
282
285
t .Logf (`clusterStatusEndpoint: %s` , clusterStatusEndpoint )
283
- if resp , err = clusterStatus .Execute (); err != nil {
286
+ resp , err = clusterStatus .Execute ()
287
+ if err != nil {
284
288
t .Fatalf (err .Error ())
285
289
}
286
- totalHostsJSON := gjson .Get (string (body ), "host-default-list.list-items.list-count.value" )
287
- // Total hosts be one as second host should have failed to create
288
- if totalHostsJSON .Num != 1 {
289
- t .Errorf ("Wrong number of hosts: %v instead of 1" , totalHostsJSON .Num )
290
+ _ , err = ioutil .ReadAll (resp .Body )
291
+ if err != nil {
292
+ t .Fatalf (err .Error ())
290
293
}
291
- t .Logf ("\n Cluster Status Response:\n \n " + string (body ))
292
294
293
295
// Verify enode group creation failed given incorrect hostname
294
296
enodeGroupStatusEndpoint := fmt .Sprintf ("http://%s/manage/v2/groups/enode" , tunnel .Endpoint ())
295
297
groupStatus := digestAuth .NewRequest (username , password , "GET" , enodeGroupStatusEndpoint , "" )
296
298
t .Logf (`enodeGroupStatusEndpoint: %s` , enodeGroupStatusEndpoint )
297
- if resp , err = groupStatus .Execute (); err != nil {
299
+ resp , err = groupStatus .Execute ()
300
+ if err != nil {
298
301
t .Fatalf (err .Error ())
299
302
}
300
- if body , err = ioutil .ReadAll (resp .Body ); err != nil {
301
- t .Fatalf (err .Error ())
302
- }
303
- if ! strings .Contains (string (body ), "404" ) {
304
- t .Errorf ("Enode group should not exist" )
305
- }
306
- t .Logf ("Enode group status response:\n " + string (body ))
303
+ // the request for enode should be 404
304
+ assert .Equal (t , 404 , resp .StatusCode )
307
305
}
0 commit comments