Skip to content

Commit c5ee478

Browse files
committed
CLD-515: Add aditional test cases
1 parent 175e017 commit c5ee478

File tree

3 files changed

+132
-17
lines changed

3 files changed

+132
-17
lines changed

go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ require (
3131
github.com/imdario/mergo v0.3.12 // indirect
3232
github.com/jmespath/go-jmespath v0.4.0 // indirect
3333
github.com/json-iterator/go v1.1.12 // indirect
34+
github.com/judgegregg/go-http-digest-auth-client v0.6.1
3435
github.com/mattn/go-zglob v0.0.2-0.20190814121620-e3c945676326 // indirect
3536
github.com/mitchellh/go-homedir v1.1.0 // indirect
3637
github.com/moby/spdystream v0.2.0 // indirect

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -514,6 +514,8 @@ github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHm
514514
github.com/jstemmer/go-junit-report v0.0.0-20190106144839-af01ea7f8024/go.mod h1:6v2b51hI/fHJwM22ozAgKL4VKDeJcHhJFhtBdhmNjmU=
515515
github.com/jstemmer/go-junit-report v0.9.1/go.mod h1:Brl9GWCQeLvo8nXZwPNNblvFj/XSXhF0NWZEnDohbsk=
516516
github.com/jtolds/gls v4.20.0+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfVYBRgL+9YlvaHOwJU=
517+
github.com/judgegregg/go-http-digest-auth-client v0.6.1 h1:r2N/KgSd0uS18kyoKSVSI3RQ+Rr6Wynk4iaaZUnjqq4=
518+
github.com/judgegregg/go-http-digest-auth-client v0.6.1/go.mod h1:Eq3vslaiSqDvLLWgenX2mpHiZHG0ZQSKT1Li5Vo5iaQ=
517519
github.com/julienschmidt/httprouter v1.2.0/go.mod h1:SYymIcj16QtmaHHD7aYtjjsJG7VTCxuUUipMqKk8s4w=
518520
github.com/kisielk/errcheck v1.1.0/go.mod h1:EZBBE59ingxPouuu3KfxchcWSUPOHkagtvWXihfKN4Q=
519521
github.com/kisielk/errcheck v1.2.0/go.mod h1:/BMXB+zMLi60iA8Vv6Ksmxu/1UDYcXs4uQLJ+jE2L00=

test/e2e/e2e_test.go

Lines changed: 129 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,48 +3,110 @@ package e2e
33
import (
44
"crypto/tls"
55
"fmt"
6+
"io/ioutil"
7+
"log"
8+
"net/http"
9+
"os"
610
"path/filepath"
711
"strings"
812
"testing"
913
"time"
10-
14+
1115
"github.com/gruntwork-io/terratest/modules/helm"
1216
http_helper "github.com/gruntwork-io/terratest/modules/http-helper"
1317
"github.com/gruntwork-io/terratest/modules/k8s"
1418
"github.com/gruntwork-io/terratest/modules/random"
19+
digest_auth "github.com/judgegregg/go-http-digest-auth-client"
1520
"github.com/stretchr/testify/require"
1621
)
1722

18-
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+
// Path to the helm chart we will test
24+
var helmChartPath, err = filepath.Abs("../../charts")
25+
var releaseName string = "test"
26+
var namespaceName string = "marklogic-" + strings.ToLower(random.UniqueId())
27+
var kubectlOptions = k8s.NewKubectlOptions("", "", namespaceName)
28+
var options = &helm.Options{
29+
KubectlOptions: kubectlOptions,
30+
SetValues: map[string]string{
31+
"persistence.enabled": "false",
32+
"replicaCount": "1",
33+
"image.repository": "marklogic-centos/marklogic-server-centos",
34+
"image.tag": "10-internal",
35+
},
36+
}
37+
38+
func TestMain(m *testing.M) {
39+
t := &testing.T{}
2340
require.NoError(t, err)
24-
namespaceName := "marklogic-" + strings.ToLower(random.UniqueId())
25-
t.Logf("creating namespace: %s", namespaceName)
26-
kubectlOptions := k8s.NewKubectlOptions("", "", namespaceName)
41+
log.Println("====Creating namespace: " + namespaceName)
2742

2843
// create a new namespace for testing
2944
k8s.CreateNamespace(t, kubectlOptions, namespaceName)
3045

31-
defer k8s.DeleteNamespace(t, kubectlOptions, namespaceName)
32-
options := &helm.Options{
46+
// anything before this runs before the tests run
47+
exitVal := m.Run()
48+
// anything after this runs after the tests run
49+
log.Println("====Deleting Helm Releases: " + namespaceName)
50+
helm.Delete(t, options, releaseName+"-upgrade", true)
51+
helm.Delete(t, options, releaseName+"-install", true)
52+
helm.Delete(t, options, releaseName+"-join", true)
53+
log.Println("====Deleting namespace: " + namespaceName)
54+
k8s.DeleteNamespace(t, kubectlOptions, namespaceName)
55+
56+
os.Exit(exitVal)
57+
}
58+
59+
func TestHelmInstall(t *testing.T) {
60+
t.Logf("====Installing Helm Chart")
61+
releaseName := releaseName + "-install"
62+
helm.Install(t, options, helmChartPath, releaseName)
63+
64+
tlsConfig := tls.Config{}
65+
podName := releaseName + "-marklogic-0"
66+
// wait until the pod is in Ready status
67+
k8s.WaitUntilPodAvailable(t, kubectlOptions, podName, 10, 15*time.Second)
68+
tunnel := k8s.NewTunnel(
69+
kubectlOptions, k8s.ResourceTypePod, podName, 7997, 7997)
70+
defer tunnel.Close()
71+
tunnel.ForwardPort(t)
72+
endpoint := fmt.Sprintf("http://%s", tunnel.Endpoint())
73+
t.Logf(`Endpoint: %s`, endpoint)
74+
75+
http_helper.HttpGetWithRetryWithCustomValidation(
76+
t,
77+
endpoint,
78+
&tlsConfig,
79+
10,
80+
15*time.Second,
81+
func(statusCode int, body string) bool {
82+
return statusCode == 200
83+
},
84+
)
85+
}
86+
87+
func TestHelmUpgrade(t *testing.T) {
88+
t.Logf("====Installing Helm Chart")
89+
releaseName := releaseName + "-upgrade"
90+
helm.Install(t, options, helmChartPath, releaseName)
91+
92+
newOptions := &helm.Options{
3393
KubectlOptions: kubectlOptions,
3494
SetValues: map[string]string{
3595
"persistence.enabled": "false",
96+
"replicaCount": "2",
97+
"image.repository": "marklogic-centos/marklogic-server-centos",
98+
"image.tag": "10-internal",
3699
},
37100
}
38101

39-
defer helm.Delete(t, options, releaseName, true)
40-
41-
//install Helm Chart for testing
42-
helm.Install(t, options, helmChartPath, releaseName)
102+
t.Logf("====Upgrading Helm Chart")
103+
helm.Upgrade(t, newOptions, helmChartPath, releaseName)
43104

44105
tlsConfig := tls.Config{}
45-
podName := "marklogic-0"
106+
podName := releaseName + "-marklogic-1"
107+
46108
// wait until the pod is in Ready status
47-
k8s.WaitUntilPodAvailable(t, kubectlOptions, podName, 10, 10*time.Second)
109+
k8s.WaitUntilPodAvailable(t, kubectlOptions, podName, 10, 20*time.Second)
48110
tunnel := k8s.NewTunnel(
49111
kubectlOptions, k8s.ResourceTypePod, podName, 7997, 7997)
50112
defer tunnel.Close()
@@ -63,3 +125,53 @@ func TestHelmInstall(t *testing.T) {
63125
},
64126
)
65127
}
128+
129+
func TestClusterJoin(t *testing.T) {
130+
var username string = "admin"
131+
var password string = "admin"
132+
var resp *http.Response
133+
var body []byte
134+
var err error
135+
136+
options := &helm.Options{
137+
KubectlOptions: kubectlOptions,
138+
SetValues: map[string]string{
139+
"persistence.enabled": "false",
140+
"replicaCount": "2",
141+
"image.repository": "marklogic-centos/marklogic-server-centos",
142+
"image.tag": "10-internal",
143+
"auth.adminUsername": username,
144+
"auth.adminPassword": password,
145+
},
146+
}
147+
t.Logf("====Installing Helm Chart")
148+
releaseName := releaseName + "-join"
149+
helm.Install(t, options, helmChartPath, releaseName)
150+
151+
podName := releaseName + "-marklogic-1"
152+
153+
// wait until the pod is in Ready status
154+
k8s.WaitUntilPodAvailable(t, kubectlOptions, podName, 10, 20*time.Second)
155+
tunnel := k8s.NewTunnel(
156+
kubectlOptions, k8s.ResourceTypePod, podName, 8002, 8002)
157+
defer tunnel.Close()
158+
tunnel.ForwardPort(t)
159+
endpoint := fmt.Sprintf("http://%s/manage/v2/hosts", tunnel.Endpoint())
160+
t.Logf(`Endpoint: %s`, endpoint)
161+
162+
dr := digest_auth.NewRequest(username, password, "GET", endpoint, "")
163+
164+
if resp, err = dr.Execute(); err != nil {
165+
log.Fatalln(err)
166+
}
167+
defer resp.Body.Close()
168+
169+
if body, err = ioutil.ReadAll(resp.Body); err != nil {
170+
log.Fatalln(err)
171+
}
172+
173+
t.Logf("Response:\n" + string(body))
174+
if !strings.Contains(string(body), "<list-count units=\"quantity\">2</list-count>") {
175+
t.Errorf("Wrong number of hosts")
176+
}
177+
}

0 commit comments

Comments
 (0)