Skip to content

Commit d5e4102

Browse files
committed
Update e2e tests to create a seperate namespace for each test
1 parent c5ee478 commit d5e4102

File tree

2 files changed

+49
-38
lines changed

2 files changed

+49
-38
lines changed

test/e2e/e2e.sh

Lines changed: 4 additions & 4 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"
1310
go test -v ./test/e2e/...
11+
12+
echo "=====Delete minikube cluster"
13+
minikube delete

test/e2e/e2e_test.go

Lines changed: 45 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -6,57 +6,38 @@ import (
66
"io/ioutil"
77
"log"
88
"net/http"
9-
"os"
109
"path/filepath"
1110
"strings"
1211
"testing"
1312
"time"
14-
13+
1514
"github.com/gruntwork-io/terratest/modules/helm"
1615
http_helper "github.com/gruntwork-io/terratest/modules/http-helper"
1716
"github.com/gruntwork-io/terratest/modules/k8s"
1817
"github.com/gruntwork-io/terratest/modules/random"
1918
digest_auth "github.com/judgegregg/go-http-digest-auth-client"
20-
"github.com/stretchr/testify/require"
2119
)
2220

2321
// Path to the helm chart we will test
2422
var helmChartPath, err = filepath.Abs("../../charts")
2523
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-
}
3724

38-
func TestMain(m *testing.M) {
39-
t := &testing.T{}
40-
require.NoError(t, err)
41-
log.Println("====Creating namespace: " + namespaceName)
25+
func TestHelmInstall(t *testing.T) {
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+
}
4237

43-
// create a new namespace for testing
38+
log.Println("====Creating namespace: " + namespaceName)
4439
k8s.CreateNamespace(t, kubectlOptions, namespaceName)
4540

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) {
6041
t.Logf("====Installing Helm Chart")
6142
releaseName := releaseName + "-install"
6243
helm.Install(t, options, helmChartPath, releaseName)
@@ -82,9 +63,27 @@ func TestHelmInstall(t *testing.T) {
8263
return statusCode == 200
8364
},
8465
)
66+
67+
log.Println("====Deleting namespace: " + namespaceName)
68+
k8s.DeleteNamespace(t, kubectlOptions, namespaceName)
8569
}
8670

8771
func TestHelmUpgrade(t *testing.T) {
72+
var namespaceName string = "marklogic-" + strings.ToLower(random.UniqueId())
73+
var kubectlOptions = k8s.NewKubectlOptions("", "", namespaceName)
74+
var options = &helm.Options{
75+
KubectlOptions: kubectlOptions,
76+
SetValues: map[string]string{
77+
"persistence.enabled": "false",
78+
"replicaCount": "1",
79+
"image.repository": "marklogic-centos/marklogic-server-centos",
80+
"image.tag": "10-internal",
81+
},
82+
}
83+
84+
log.Println("====Creating namespace: " + namespaceName)
85+
k8s.CreateNamespace(t, kubectlOptions, namespaceName)
86+
8887
t.Logf("====Installing Helm Chart")
8988
releaseName := releaseName + "-upgrade"
9089
helm.Install(t, options, helmChartPath, releaseName)
@@ -124,9 +123,14 @@ func TestHelmUpgrade(t *testing.T) {
124123
return statusCode == 200
125124
},
126125
)
126+
127+
log.Println("====Deleting namespace: " + namespaceName)
128+
k8s.DeleteNamespace(t, kubectlOptions, namespaceName)
127129
}
128130

129131
func TestClusterJoin(t *testing.T) {
132+
var namespaceName string = "marklogic-" + strings.ToLower(random.UniqueId())
133+
var kubectlOptions = k8s.NewKubectlOptions("", "", namespaceName)
130134
var username string = "admin"
131135
var password string = "admin"
132136
var resp *http.Response
@@ -144,6 +148,10 @@ func TestClusterJoin(t *testing.T) {
144148
"auth.adminPassword": password,
145149
},
146150
}
151+
152+
log.Println("====Creating namespace: " + namespaceName)
153+
k8s.CreateNamespace(t, kubectlOptions, namespaceName)
154+
147155
t.Logf("====Installing Helm Chart")
148156
releaseName := releaseName + "-join"
149157
helm.Install(t, options, helmChartPath, releaseName)
@@ -160,7 +168,7 @@ func TestClusterJoin(t *testing.T) {
160168
t.Logf(`Endpoint: %s`, endpoint)
161169

162170
dr := digest_auth.NewRequest(username, password, "GET", endpoint, "")
163-
171+
164172
if resp, err = dr.Execute(); err != nil {
165173
log.Fatalln(err)
166174
}
@@ -174,4 +182,7 @@ func TestClusterJoin(t *testing.T) {
174182
if !strings.Contains(string(body), "<list-count units=\"quantity\">2</list-count>") {
175183
t.Errorf("Wrong number of hosts")
176184
}
185+
186+
log.Println("====Deleting namespace: " + namespaceName)
187+
k8s.DeleteNamespace(t, kubectlOptions, namespaceName)
177188
}

0 commit comments

Comments
 (0)