@@ -87,7 +87,7 @@ func DeleteDocs(client *req.Client, deleteEndpoint string) (string, error) {
87
87
return result , err
88
88
}
89
89
90
- func RunRequests (client * req.Client , dbReq string , hostsEndpoint string ) (string , error ) {
90
+ func RunRequests (t * testing. T , client * req.Client , dbReq string , hostsEndpoint string ) (string , error ) {
91
91
var err error
92
92
var body []byte
93
93
headerMap := map [string ]string {
@@ -99,11 +99,11 @@ func RunRequests(client *req.Client, dbReq string, hostsEndpoint string) (string
99
99
operation := (gjson .Get (dbReq , `operation` )).Str
100
100
var retryFn = (func (resp * req.Response , err error ) bool {
101
101
if err != nil {
102
- fmt . Println (err .Error ())
102
+ t . Fatalf (err .Error ())
103
103
}
104
104
body , err = io .ReadAll (resp .Body )
105
105
if err != nil {
106
- fmt . Println (err .Error ())
106
+ t . Fatalf (err .Error ())
107
107
}
108
108
result = (string (body ))
109
109
return true
@@ -112,7 +112,7 @@ func RunRequests(client *req.Client, dbReq string, hostsEndpoint string) (string
112
112
if operation == "backup-status" {
113
113
retryFn = (func (resp * req.Response , err error ) bool {
114
114
if err != nil {
115
- fmt . Printf ( "error: %s" , err .Error ())
115
+ t . Fatalf ( err .Error ())
116
116
}
117
117
body , _ := io .ReadAll (resp .Body )
118
118
status = (gjson .Get (string (body ), `status` )).Str
@@ -130,7 +130,7 @@ func RunRequests(client *req.Client, dbReq string, hostsEndpoint string) (string
130
130
SetBodyString (dbReq ).
131
131
Post (hostsEndpoint )
132
132
if err != nil {
133
- return "" , err
133
+ t . Fatalf ( err . Error ())
134
134
}
135
135
defer resp .Body .Close ()
136
136
@@ -158,7 +158,7 @@ func TestMlDbBackupRestore(t *testing.T) {
158
158
}
159
159
160
160
if ! tagPres {
161
- imageTag = "11.1 .0-centos-1.1.2 "
161
+ imageTag = "11.3 .0-ubi-rootless "
162
162
t .Logf ("No imageTag variable present, setting to default value: " + imageTag )
163
163
}
164
164
@@ -167,18 +167,20 @@ func TestMlDbBackupRestore(t *testing.T) {
167
167
168
168
namespaceName := "ml-" + strings .ToLower (random .UniqueId ())
169
169
kubectlOptions := k8s .NewKubectlOptions ("" , "" , namespaceName )
170
+ valuesMap := map [string ]string {
171
+ "persistence.enabled" : "true" ,
172
+ "replicaCount" : "1" ,
173
+ "image.repository" : imageRepo ,
174
+ "image.tag" : imageTag ,
175
+ "auth.adminUsername" : username ,
176
+ "auth.adminPassword" : password ,
177
+ "logCollection.enabled" : "false" ,
178
+ }
179
+
170
180
options := & helm.Options {
171
181
KubectlOptions : kubectlOptions ,
172
- SetValues : map [string ]string {
173
- "persistence.enabled" : "true" ,
174
- "replicaCount" : "1" ,
175
- "image.repository" : imageRepo ,
176
- "image.tag" : imageTag ,
177
- "auth.adminUsername" : username ,
178
- "auth.adminPassword" : password ,
179
- "logCollection.enabled" : "false" ,
180
- },
181
- Version : initialChartVersion ,
182
+ SetValues : valuesMap ,
183
+ Version : initialChartVersion ,
182
184
}
183
185
184
186
t .Logf ("====Installing Helm Chart" )
@@ -198,6 +200,8 @@ func TestMlDbBackupRestore(t *testing.T) {
198
200
//add the helm chart repo and install the last helm chart release from repository
199
201
//to test and upgrade this chart to the latest one to be released
200
202
if runUpgradeTest {
203
+ delete (valuesMap , "image.repository" )
204
+ delete (valuesMap , "image.tag" )
201
205
helm .AddRepo (t , options , "marklogic" , "https://marklogic.github.io/marklogic-kubernetes/" )
202
206
defer helm .RemoveRepo (t , options , "marklogic" )
203
207
helmChartPath = "marklogic/marklogic"
@@ -236,6 +240,15 @@ func TestMlDbBackupRestore(t *testing.T) {
236
240
testUtil .HelmUpgrade (t , helmUpgradeOptions , releaseName , kubectlOptions , []string {podName }, initialChartVersion )
237
241
}
238
242
243
+ // wait until the pod is in Running status
244
+ output , err := testUtil .WaitUntilPodRunning (t , kubectlOptions , podName , 10 , 15 * time .Second )
245
+ if err != nil {
246
+ t .Error (err .Error ())
247
+ }
248
+ if output != "Running" {
249
+ t .Error (output )
250
+ }
251
+
239
252
//create backup directories and setup permissions
240
253
k8s .RunKubectl (t , kubectlOptions , "exec" , podName , "--" , "/bin/bash" , "-c" , "cd /tmp && mkdir backup && chmod 777 backup && mkdir backup/incrBackup && chmod 777 backup/incrBackup" )
241
254
@@ -287,8 +300,9 @@ func TestMlDbBackupRestore(t *testing.T) {
287
300
IncludeReplicas : "true" }
288
301
bkupReqRes , _ := json .Marshal (bkupReq )
289
302
303
+ t .Log ("====Full backup for Documents DB" )
290
304
//full backup for Documents DB
291
- result , err = RunRequests (client , string (bkupReqRes ), manageEndpoint )
305
+ result , err = RunRequests (t , client , string (bkupReqRes ), manageEndpoint )
292
306
if err != nil {
293
307
t .Fatalf (err .Error ())
294
308
}
@@ -302,7 +316,7 @@ func TestMlDbBackupRestore(t *testing.T) {
302
316
bkupStatusReqRes , _ := json .Marshal (bkupStatusReq )
303
317
304
318
//get status of full backup job
305
- result , err = RunRequests (client , string (bkupStatusReqRes ), manageEndpoint )
319
+ result , err = RunRequests (t , client , string (bkupStatusReqRes ), manageEndpoint )
306
320
if err != nil {
307
321
t .Fatalf (err .Error ())
308
322
}
@@ -311,10 +325,12 @@ func TestMlDbBackupRestore(t *testing.T) {
311
325
//verify full backup is completed
312
326
assert .Equal (t , "completed" , bkupStatus )
313
327
328
+ t .Log ("====Delete a document from Documents DB" )
314
329
deleteEndpoint := fmt .Sprintf ("http://%s/v1/documents?database=Documents&uri=%s" , tunnel8000 .Endpoint (), docs [1 ])
315
330
fmt .Println (deleteEndpoint )
316
331
317
332
//incremental backup
333
+ t .Log ("====Incremental backup for Documents DB" )
318
334
incrBkupReq := & BackupRestoreReq {
319
335
Operation : "backup-database" ,
320
336
BackupDir : "/tmp/backup" ,
@@ -324,7 +340,7 @@ func TestMlDbBackupRestore(t *testing.T) {
324
340
incrBkupReqRes , _ := json .Marshal (incrBkupReq )
325
341
326
342
//incremnetal backup for Documents DB
327
- result , err = RunRequests (client , string (incrBkupReqRes ), manageEndpoint )
343
+ result , err = RunRequests (t , client , string (incrBkupReqRes ), manageEndpoint )
328
344
if err != nil {
329
345
t .Fatalf (err .Error ())
330
346
}
@@ -338,7 +354,7 @@ func TestMlDbBackupRestore(t *testing.T) {
338
354
incrBkupStatusReqRes , _ := json .Marshal (incrBkupStatusReq )
339
355
340
356
//get status of backup job
341
- result , err = RunRequests (client , string (incrBkupStatusReqRes ), manageEndpoint )
357
+ result , err = RunRequests (t , client , string (incrBkupStatusReqRes ), manageEndpoint )
342
358
if err != nil {
343
359
t .Fatalf (err .Error ())
344
360
}
@@ -361,7 +377,7 @@ func TestMlDbBackupRestore(t *testing.T) {
361
377
brstrReqRes , _ := json .Marshal (rstrReq )
362
378
363
379
//restore Documents DB from incremental backup
364
- result , err = RunRequests (client , string (brstrReqRes ), manageEndpoint )
380
+ result , err = RunRequests (t , client , string (brstrReqRes ), manageEndpoint )
365
381
if err != nil {
366
382
t .Fatalf (err .Error ())
367
383
}
0 commit comments