Skip to content

Commit 25e8db7

Browse files
MLE-4129: Create util function for ML readiness (#215)
* added util fn for marklogic ready check
1 parent fee5da6 commit 25e8db7

File tree

4 files changed

+57
-50
lines changed

4 files changed

+57
-50
lines changed

test/e2e/install_test.go

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import (
1010
"testing"
1111
"time"
1212

13-
http_helper "github.com/gruntwork-io/terratest/modules/http-helper"
1413
"github.com/gruntwork-io/terratest/modules/k8s"
1514
"github.com/gruntwork-io/terratest/modules/random"
1615
"github.com/marklogic/marklogic-kubernetes/test/testUtil"
@@ -57,26 +56,16 @@ func TestHelmInstall(t *testing.T) {
5756
defer k8s.DeleteNamespace(t, kubectlOptions, namespaceName)
5857

5958
podName = testUtil.HelmInstall(t, options, releaseName, kubectlOptions)
60-
6159
tlsConfig := tls.Config{}
60+
6261
// wait until the pod is in Ready status
6362
k8s.WaitUntilPodAvailable(t, kubectlOptions, podName, 15, 15*time.Second)
64-
tunnel7997 := k8s.NewTunnel(kubectlOptions, k8s.ResourceTypePod, podName, 7997, 7997)
65-
defer tunnel7997.Close()
66-
tunnel7997.ForwardPort(t)
67-
endpoint7997 := fmt.Sprintf("http://%s", tunnel7997.Endpoint())
68-
69-
// verify if 7997 health check endpoint returns 200
70-
http_helper.HttpGetWithRetryWithCustomValidation(
71-
t,
72-
endpoint7997,
73-
&tlsConfig,
74-
10,
75-
15*time.Second,
76-
func(statusCode int, body string) bool {
77-
return statusCode == 200
78-
},
79-
)
63+
64+
// verify MarkLogic is ready
65+
_, err = testUtil.MLReadyCheck(t, kubectlOptions, podName, &tlsConfig)
66+
if err != nil {
67+
t.Fatal("MarkLogic failed to start")
68+
}
8069

8170
t.Log("====Testing Generated Random Password====")
8271
secretName := releaseName + "-admin"

test/e2e/tls_test.go

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212
"time"
1313

1414
"github.com/imroc/req/v3"
15+
"github.com/marklogic/marklogic-kubernetes/test/testUtil"
1516
"github.com/stretchr/testify/assert"
1617
"github.com/tidwall/gjson"
1718

@@ -61,22 +62,12 @@ func TestTLSEnabledWithSelfSigned(t *testing.T) {
6162

6263
// wait until the pod is in Ready status
6364
k8s.WaitUntilPodAvailable(t, kubectlOptions, podName, 10, 20*time.Second)
64-
tunnel7997 := k8s.NewTunnel(kubectlOptions, k8s.ResourceTypePod, podName, 7997, 7997)
65-
defer tunnel7997.Close()
66-
tunnel7997.ForwardPort(t)
67-
endpoint7997 := fmt.Sprintf("http://%s", tunnel7997.Endpoint())
6865

69-
// verify if 7997 health check endpoint returns 200
70-
http_helper.HttpGetWithRetryWithCustomValidation(
71-
t,
72-
endpoint7997,
73-
&tlsConfig,
74-
10,
75-
15*time.Second,
76-
func(statusCode int, body string) bool {
77-
return statusCode == 200
78-
},
79-
)
66+
// verify MarkLogic is ready
67+
_, err := testUtil.MLReadyCheck(t, kubectlOptions, podName, &tlsConfig)
68+
if err != nil {
69+
t.Fatal("MarkLogic failed to start")
70+
}
8071

8172
tunnel := k8s.NewTunnel(
8273
kubectlOptions, k8s.ResourceTypePod, podName, 8002, 8002)

test/hugePages/huge_pages_test.go

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import (
99
"testing"
1010
"time"
1111

12-
http_helper "github.com/gruntwork-io/terratest/modules/http-helper"
1312
"github.com/gruntwork-io/terratest/modules/k8s"
1413
"github.com/gruntwork-io/terratest/modules/random"
1514
"github.com/marklogic/marklogic-kubernetes/test/testUtil"
@@ -73,22 +72,12 @@ func TestHugePagesSettings(t *testing.T) {
7372
// wait until the pod is in Ready status
7473
k8s.WaitUntilPodAvailable(t, kubectlOptions, podName, 10, 15*time.Second)
7574

76-
tunnel7997 := k8s.NewTunnel(kubectlOptions, k8s.ResourceTypePod, podName, 7997, 7997)
77-
defer tunnel7997.Close()
78-
tunnel7997.ForwardPort(t)
79-
endpoint7997 := fmt.Sprintf("http://%s", tunnel7997.Endpoint())
80-
81-
// verify if 7997 health check endpoint returns 200
82-
http_helper.HttpGetWithRetryWithCustomValidation(
83-
t,
84-
endpoint7997,
85-
&tlsConfig,
86-
10,
87-
15*time.Second,
88-
func(statusCode int, body string) bool {
89-
return statusCode == 200
90-
},
91-
)
75+
// verify MarkLogic is ready
76+
_, err = testUtil.MLReadyCheck(t, kubectlOptions, podName, &tlsConfig)
77+
if err != nil {
78+
t.Fatal("MarkLogic failed to start")
79+
}
80+
9281
tunnel8002 := k8s.NewTunnel(kubectlOptions, k8s.ResourceTypePod, podName, 8002, 8002)
9382
defer tunnel8002.Close()
9483
tunnel8002.ForwardPort(t)

test/testUtil/ml_ready_check.go

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
// Package testUtil contains utility functions for all the tests in this repo
2+
package testUtil
3+
4+
import (
5+
"crypto/tls"
6+
"fmt"
7+
"testing"
8+
"time"
9+
10+
http_helper "github.com/gruntwork-io/terratest/modules/http-helper"
11+
"github.com/gruntwork-io/terratest/modules/k8s"
12+
)
13+
14+
// MLReadyCheck : testUtil function to check if MarkLogic is ready for e2e tests
15+
func MLReadyCheck(t *testing.T, kubectlOpt *k8s.KubectlOptions, podName string, tlsConfig *tls.Config) (bool, error) {
16+
17+
tunnel7997 := k8s.NewTunnel(kubectlOpt, k8s.ResourceTypePod, podName, 7997, 7997)
18+
defer tunnel7997.Close()
19+
tunnel7997.ForwardPort(t)
20+
endpoint7997 := fmt.Sprintf("http://%s/LATEST/healthcheck", tunnel7997.Endpoint())
21+
22+
// verify if 7997 health check endpoint returns 200
23+
err := http_helper.HttpGetWithRetryWithCustomValidationE(
24+
t,
25+
endpoint7997,
26+
tlsConfig,
27+
10,
28+
15*time.Second,
29+
func(statusCode int, body string) bool {
30+
return statusCode == 200
31+
},
32+
)
33+
34+
if err != nil {
35+
return false, err
36+
}
37+
return true, nil
38+
}

0 commit comments

Comments
 (0)