Skip to content

Commit 03c1542

Browse files
Merge pull request #13 from ilanRosenbaum/feature/CLD-515
CLD-515
2 parents fcad187 + 117a199 commit 03c1542

File tree

7 files changed

+187
-22
lines changed

7 files changed

+187
-22
lines changed

go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ go 1.17
55
require (
66
github.com/gruntwork-io/terratest v0.40.6
77
github.com/stretchr/testify v1.7.0
8+
github.com/xinsnake/go-http-digest-auth-client v0.6.0
89
k8s.io/api v0.23.0
910
)
1011

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -783,6 +783,8 @@ github.com/xeipuuv/gojsonpointer v0.0.0-20180127040702-4e3ac2762d5f/go.mod h1:N2
783783
github.com/xeipuuv/gojsonreference v0.0.0-20180127040603-bd5ef7bd5415/go.mod h1:GwrjFmJcFw6At/Gs6z4yjiIwzuJ1/+UwLxMQDVQXShQ=
784784
github.com/xeipuuv/gojsonschema v0.0.0-20180618132009-1d523034197f/go.mod h1:5yf86TLmAcydyeJq5YvxkGPE2fm/u4myDekKRoLuqhs=
785785
github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2/go.mod h1:UETIi67q53MR2AWcXfiuqkDkRtnGDLqkBTpCHuJHxtU=
786+
github.com/xinsnake/go-http-digest-auth-client v0.6.0 h1:nrYFWDrB2F7VwYlNravXZS0nOtg9axlATH3Jns55/F0=
787+
github.com/xinsnake/go-http-digest-auth-client v0.6.0/go.mod h1:QK1t1v7ylyGb363vGWu+6Irh7gyFj+N7+UZzM0L6g8I=
786788
github.com/xordataexchange/crypt v0.0.3-0.20170626215501-b2862e3d0a77/go.mod h1:aYKd//L2LvnjZzWKhF00oedf4jCCReLcmhLdhm1A27Q=
787789
github.com/yuin/goldmark v1.1.25/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
788790
github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=

makefile

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,6 @@ test/e2e: install-go-modules
66
sh ./test/e2e/e2e.sh
77

88
test/template: install-go-modules
9-
go test -v ./test/template/...
9+
go test -v ./test/template/...
10+
11+
test: test/template test/e2e

test/e2e/clustering_test.go

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
package e2e
2+
3+
import (
4+
"fmt"
5+
"io/ioutil"
6+
"net/http"
7+
"path/filepath"
8+
"strings"
9+
"testing"
10+
"time"
11+
12+
"github.com/gruntwork-io/terratest/modules/helm"
13+
"github.com/gruntwork-io/terratest/modules/k8s"
14+
"github.com/gruntwork-io/terratest/modules/random"
15+
digest_auth "github.com/xinsnake/go-http-digest-auth-client"
16+
)
17+
18+
19+
func TestClusterJoin(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+
username := "admin"
26+
password := "admin"
27+
var resp *http.Response
28+
var body []byte
29+
var err error
30+
namespaceName := "marklogic-" + strings.ToLower(random.UniqueId())
31+
kubectlOptions := k8s.NewKubectlOptions("", "", namespaceName)
32+
options := &helm.Options{
33+
KubectlOptions: kubectlOptions,
34+
SetValues: map[string]string{
35+
"persistence.enabled": "false",
36+
"replicaCount": "2",
37+
"image.repository": "marklogic-centos/marklogic-server-centos",
38+
"image.tag": "10-internal",
39+
"auth.adminUsername": username,
40+
"auth.adminPassword": password,
41+
},
42+
}
43+
44+
t.Logf("====Creating namespace: " + namespaceName)
45+
k8s.CreateNamespace(t, kubectlOptions, namespaceName)
46+
47+
defer t.Logf("====Deleting namespace: " + namespaceName)
48+
defer k8s.DeleteNamespace(t, kubectlOptions, namespaceName)
49+
50+
t.Logf("====Installing Helm Chart")
51+
releaseName := "test-join"
52+
helm.Install(t, options, helmChartPath, releaseName)
53+
54+
podName := releaseName + "-marklogic-1"
55+
56+
// wait until the pod is in Ready status
57+
k8s.WaitUntilPodAvailable(t, kubectlOptions, podName, 10, 20*time.Second)
58+
tunnel := k8s.NewTunnel(
59+
kubectlOptions, k8s.ResourceTypePod, podName, 8002, 8002)
60+
defer tunnel.Close()
61+
tunnel.ForwardPort(t)
62+
endpoint := fmt.Sprintf("http://%s/manage/v2/hosts", tunnel.Endpoint())
63+
t.Logf(`Endpoint: %s`, endpoint)
64+
65+
dr := digest_auth.NewRequest(username, password, "GET", endpoint, "")
66+
67+
if resp, err = dr.Execute(); err != nil {
68+
t.Fatalf(err.Error())
69+
}
70+
defer resp.Body.Close()
71+
72+
if body, err = ioutil.ReadAll(resp.Body); err != nil {
73+
t.Fatalf(err.Error())
74+
}
75+
76+
t.Logf("Response:\n" + string(body))
77+
if !strings.Contains(string(body), "<list-count units=\"quantity\">2</list-count>") {
78+
t.Errorf("Wrong number of hosts")
79+
}
80+
}

test/e2e/e2e.sh

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
#!/bin/bash
22

3-
echo "=====Delete minikube cluster"
4-
minikube delete
5-
63
echo "=====Installing minikube cluster"
74
minikube start --driver=docker -n=1
85

96
echo "=====Loading marklogc images to minikube cluster"
10-
minikube image load store/marklogicdb/marklogic-server:10.0-9-centos-1.0.0-ea4
7+
minikube image load marklogic-centos/marklogic-server-centos:10-internal
118

129
echo "=====Running tests"
13-
go test -v ./test/e2e/...
10+
go test -v -count=1 ./test/e2e/...
11+
12+
echo "=====Delete minikube cluster"
13+
minikube delete

test/e2e/e2e_test.go renamed to test/e2e/install_test.go

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -12,39 +12,40 @@ import (
1212
http_helper "github.com/gruntwork-io/terratest/modules/http-helper"
1313
"github.com/gruntwork-io/terratest/modules/k8s"
1414
"github.com/gruntwork-io/terratest/modules/random"
15-
"github.com/stretchr/testify/require"
1615
)
1716

1817
func TestHelmInstall(t *testing.T) {
19-
// Path to the helm chart we will test
20-
helmChartPath, err := filepath.Abs("../../charts")
21-
releaseName := "marklogic-test"
22-
t.Log(helmChartPath, releaseName)
23-
require.NoError(t, err)
18+
// Path to the helm chart we will test
19+
helmChartPath, e := filepath.Abs("../../charts")
20+
if (e != nil) {
21+
t.Fatalf(e.Error())
22+
}
2423
namespaceName := "marklogic-" + strings.ToLower(random.UniqueId())
25-
t.Logf("creating namespace: %s", namespaceName)
2624
kubectlOptions := k8s.NewKubectlOptions("", "", namespaceName)
27-
28-
// create a new namespace for testing
29-
k8s.CreateNamespace(t, kubectlOptions, namespaceName)
30-
31-
defer k8s.DeleteNamespace(t, kubectlOptions, namespaceName)
3225
options := &helm.Options{
3326
KubectlOptions: kubectlOptions,
3427
SetValues: map[string]string{
3528
"persistence.enabled": "false",
29+
"replicaCount": "1",
30+
"image.repository": "marklogic-centos/marklogic-server-centos",
31+
"image.tag": "10-internal",
3632
},
3733
}
3834

39-
defer helm.Delete(t, options, releaseName, true)
35+
t.Logf("====Creating namespace: " + namespaceName)
36+
k8s.CreateNamespace(t, kubectlOptions, namespaceName)
37+
38+
defer t.Logf("====Deleting namespace: " + namespaceName)
39+
defer k8s.DeleteNamespace(t, kubectlOptions, namespaceName)
4040

41-
//install Helm Chart for testing
41+
t.Logf("====Installing Helm Chart")
42+
releaseName := "test-install"
4243
helm.Install(t, options, helmChartPath, releaseName)
4344

4445
tlsConfig := tls.Config{}
45-
podName := "marklogic-0"
46+
podName := releaseName + "-marklogic-0"
4647
// wait until the pod is in Ready status
47-
k8s.WaitUntilPodAvailable(t, kubectlOptions, podName, 10, 10*time.Second)
48+
k8s.WaitUntilPodAvailable(t, kubectlOptions, podName, 10, 15*time.Second)
4849
tunnel := k8s.NewTunnel(
4950
kubectlOptions, k8s.ResourceTypePod, podName, 7997, 7997)
5051
defer tunnel.Close()

test/e2e/upgrade_test.go

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
package e2e
2+
3+
import (
4+
"crypto/tls"
5+
"fmt"
6+
"path/filepath"
7+
"strings"
8+
"testing"
9+
"time"
10+
11+
"github.com/gruntwork-io/terratest/modules/helm"
12+
http_helper "github.com/gruntwork-io/terratest/modules/http-helper"
13+
"github.com/gruntwork-io/terratest/modules/k8s"
14+
"github.com/gruntwork-io/terratest/modules/random"
15+
)
16+
17+
func TestHelmUpgrade(t *testing.T) {
18+
// Path to the helm chart we will test
19+
helmChartPath, e := filepath.Abs("../../charts")
20+
if (e != nil) {
21+
t.Fatalf(e.Error())
22+
}
23+
namespaceName := "marklogic-" + strings.ToLower(random.UniqueId())
24+
kubectlOptions := k8s.NewKubectlOptions("", "", namespaceName)
25+
options := &helm.Options{
26+
KubectlOptions: kubectlOptions,
27+
SetValues: map[string]string{
28+
"persistence.enabled": "false",
29+
"replicaCount": "1",
30+
"image.repository": "marklogic-centos/marklogic-server-centos",
31+
"image.tag": "10-internal",
32+
},
33+
}
34+
35+
t.Logf("====Creating namespace: " + namespaceName)
36+
k8s.CreateNamespace(t, kubectlOptions, namespaceName)
37+
defer t.Logf("====Deleting namespace: " + namespaceName)
38+
defer k8s.DeleteNamespace(t, kubectlOptions, namespaceName)
39+
40+
t.Logf("====Installing Helm Chart")
41+
releaseName := "test-upgrade"
42+
helm.Install(t, options, helmChartPath, releaseName)
43+
44+
newOptions := &helm.Options{
45+
KubectlOptions: kubectlOptions,
46+
SetValues: map[string]string{
47+
"persistence.enabled": "false",
48+
"replicaCount": "2",
49+
"image.repository": "marklogic-centos/marklogic-server-centos",
50+
"image.tag": "10-internal",
51+
},
52+
}
53+
54+
t.Logf("====Upgrading Helm Chart")
55+
helm.Upgrade(t, newOptions, helmChartPath, releaseName)
56+
57+
tlsConfig := tls.Config{}
58+
podName := releaseName + "-marklogic-1"
59+
60+
// wait until the pod is in Ready status
61+
k8s.WaitUntilPodAvailable(t, kubectlOptions, podName, 10, 20*time.Second)
62+
tunnel := k8s.NewTunnel(
63+
kubectlOptions, k8s.ResourceTypePod, podName, 7997, 7997)
64+
defer tunnel.Close()
65+
tunnel.ForwardPort(t)
66+
endpoint := fmt.Sprintf("http://%s", tunnel.Endpoint())
67+
t.Logf(`Endpoint: %s`, endpoint)
68+
69+
http_helper.HttpGetWithRetryWithCustomValidation(
70+
t,
71+
endpoint,
72+
&tlsConfig,
73+
10,
74+
15*time.Second,
75+
func(statusCode int, body string) bool {
76+
return statusCode == 200
77+
},
78+
)
79+
}

0 commit comments

Comments
 (0)