Skip to content

Commit 5853d24

Browse files
committed
CLD-656: Add test to make sure node is ready when as soon as it is marked as such
1 parent f3b2d40 commit 5853d24

File tree

3 files changed

+92
-3
lines changed

3 files changed

+92
-3
lines changed

makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ lint:
9393
minikube image load $(dockerImage)
9494

9595
@echo "=====Running e2e tests"
96-
$(if $(saveOutput),gotestsum --junitfile test/test_results/e2e-tests.xml ./test/e2e/... -count=1 -timeout 30m, go test -v -count=1 ./test/e2e/...)
96+
$(if $(saveOutput),gotestsum --junitfile test/test_results/e2e-tests.xml ./test/e2e/... -count=1 -timeout 30m, go test -v -count=1 -timeout 30m ./test/e2e/...)
9797

9898
@echo "=====Delete minikube cluster"
9999
minikube delete

test/e2e/clustering_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import (
1313
"github.com/gruntwork-io/terratest/modules/helm"
1414
"github.com/gruntwork-io/terratest/modules/k8s"
1515
"github.com/gruntwork-io/terratest/modules/random"
16-
digest_auth "github.com/xinsnake/go-http-digest-auth-client"
16+
digestAuth "github.com/xinsnake/go-http-digest-auth-client"
1717
)
1818

1919
func TestClusterJoin(t *testing.T) {
@@ -77,7 +77,7 @@ func TestClusterJoin(t *testing.T) {
7777
endpoint := fmt.Sprintf("http://%s/manage/v2/hosts", tunnel.Endpoint())
7878
t.Logf(`Endpoint: %s`, endpoint)
7979

80-
dr := digest_auth.NewRequest(username, password, "GET", endpoint, "")
80+
dr := digestAuth.NewRequest(username, password, "GET", endpoint, "")
8181

8282
if resp, err = dr.Execute(); err != nil {
8383
t.Fatalf(err.Error())

test/e2e/ready_test.go

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
package e2e
2+
3+
import (
4+
"fmt"
5+
"io/ioutil"
6+
"net/http"
7+
"os"
8+
"path/filepath"
9+
"strings"
10+
"testing"
11+
"time"
12+
13+
"github.com/gruntwork-io/terratest/modules/helm"
14+
"github.com/gruntwork-io/terratest/modules/k8s"
15+
"github.com/gruntwork-io/terratest/modules/random"
16+
digestAuth "github.com/xinsnake/go-http-digest-auth-client"
17+
)
18+
19+
func TestMarklogicReady(t *testing.T) {
20+
// Path to the helm chart we will test
21+
helmChartPath, e := filepath.Abs("../../charts")
22+
if e != nil {
23+
t.Fatalf(e.Error())
24+
}
25+
imageRepo, repoPres := os.LookupEnv("dockerRepository")
26+
imageTag, tagPres := os.LookupEnv("dockerVersion")
27+
username := "admin"
28+
password := "admin"
29+
var resp *http.Response
30+
var body []byte
31+
var err error
32+
33+
if !repoPres {
34+
imageRepo = "marklogic-centos/marklogic-server-centos"
35+
t.Logf("No imageRepo variable present, setting to default value: " + imageRepo)
36+
}
37+
38+
if !tagPres {
39+
imageTag = "10-internal"
40+
t.Logf("No imageTag variable present, setting to default value: " + imageTag)
41+
}
42+
43+
namespaceName := "marklogic-" + strings.ToLower(random.UniqueId())
44+
kubectlOptions := k8s.NewKubectlOptions("", "", namespaceName)
45+
options := &helm.Options{
46+
KubectlOptions: kubectlOptions,
47+
SetValues: map[string]string{
48+
"persistence.enabled": "false",
49+
"replicaCount": "2",
50+
"image.repository": imageRepo,
51+
"image.tag": imageTag,
52+
"auth.adminUsername": username,
53+
"auth.adminPassword": password,
54+
"logCollection.enabled": "false",
55+
},
56+
}
57+
58+
t.Logf("====Creating namespace: " + namespaceName)
59+
k8s.CreateNamespace(t, kubectlOptions, namespaceName)
60+
61+
defer t.Logf("====Deleting namespace: " + namespaceName)
62+
defer k8s.DeleteNamespace(t, kubectlOptions, namespaceName)
63+
64+
t.Logf("====Installing Helm Chart")
65+
releaseName := "test-install"
66+
helm.Install(t, options, helmChartPath, releaseName)
67+
68+
podName := releaseName + "-marklogic-0"
69+
// wait until the pod is in Ready status
70+
k8s.WaitUntilPodAvailable(t, kubectlOptions, podName, 10, 15*time.Second)
71+
tunnel := k8s.NewTunnel(
72+
kubectlOptions, k8s.ResourceTypePod, podName, 8001, 8001)
73+
defer tunnel.Close()
74+
tunnel.ForwardPort(t)
75+
endpoint := fmt.Sprintf("http://%s/admin/v1/timestamp", tunnel.Endpoint())
76+
t.Logf(`Endpoint: %s`, endpoint)
77+
78+
// Make request to server as soon as it is ready
79+
timestamp := digestAuth.NewRequest(username, password, "GET", endpoint, "")
80+
81+
if resp, err = timestamp.Execute(); err != nil {
82+
t.Fatalf(err.Error())
83+
}
84+
if body, err = ioutil.ReadAll(resp.Body); err != nil {
85+
t.Fatalf(err.Error())
86+
}
87+
88+
t.Logf("Timestamp response:\n" + string(body))
89+
}

0 commit comments

Comments
 (0)