Skip to content

Commit 58719f2

Browse files
CLD-868: Create deployment function for K8s test framework (#148)
* added test util function for e2e tests * changed folder same as pkg name for testUtil
1 parent 8768daa commit 58719f2

File tree

2 files changed

+48
-23
lines changed

2 files changed

+48
-23
lines changed

test/e2e/install_test.go

Lines changed: 15 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -6,31 +6,26 @@ import (
66
"io/ioutil"
77
"net/http"
88
"os"
9-
"path/filepath"
109
"strings"
1110
"testing"
1211
"time"
1312

14-
"github.com/gruntwork-io/terratest/modules/helm"
1513
http_helper "github.com/gruntwork-io/terratest/modules/http-helper"
1614
"github.com/gruntwork-io/terratest/modules/k8s"
1715
"github.com/gruntwork-io/terratest/modules/random"
16+
"github.com/marklogic/marklogic-kubernetes/test/testUtil"
1817
"github.com/stretchr/testify/assert"
1918
"github.com/tidwall/gjson"
2019
digestAuth "github.com/xinsnake/go-http-digest-auth-client"
2120
)
2221

2322
func TestHelmInstall(t *testing.T) {
24-
// Path to the helm chart we will test
25-
helmChartPath, e := filepath.Abs("../../charts")
26-
if e != nil {
27-
t.Fatalf(e.Error())
28-
}
29-
imageRepo, repoPres := os.LookupEnv("dockerRepository")
30-
imageTag, tagPres := os.LookupEnv("dockerVersion")
3123
var resp *http.Response
3224
var body []byte
3325
var err error
26+
var podName string
27+
imageRepo, repoPres := os.LookupEnv("dockerRepository")
28+
imageTag, tagPres := os.LookupEnv("dockerVersion")
3429

3530
if !repoPres {
3631
imageRepo = "marklogic-centos/marklogic-server-centos"
@@ -42,31 +37,28 @@ func TestHelmInstall(t *testing.T) {
4237
t.Logf("No imageTag variable present, setting to default value: " + imageTag)
4338
}
4439

40+
options := map[string]string{
41+
"persistence.enabled": "false",
42+
"replicaCount": "2",
43+
"image.repository": imageRepo,
44+
"image.tag": imageTag,
45+
"logCollection.enabled": "false",
46+
}
47+
t.Logf("====Installing Helm Chart")
48+
releaseName := "test-install"
49+
4550
namespaceName := "marklogic-" + strings.ToLower(random.UniqueId())
4651
kubectlOptions := k8s.NewKubectlOptions("", "", namespaceName)
47-
options := &helm.Options{
48-
KubectlOptions: kubectlOptions,
49-
SetValues: map[string]string{
50-
"persistence.enabled": "false",
51-
"replicaCount": "2",
52-
"image.repository": imageRepo,
53-
"image.tag": imageTag,
54-
"logCollection.enabled": "false",
55-
},
56-
}
5752

5853
t.Logf("====Creating namespace: " + namespaceName)
5954
k8s.CreateNamespace(t, kubectlOptions, namespaceName)
6055

6156
defer t.Logf("====Deleting namespace: " + namespaceName)
6257
defer k8s.DeleteNamespace(t, kubectlOptions, namespaceName)
6358

64-
t.Logf("====Installing Helm Chart")
65-
releaseName := "test-install"
66-
helm.Install(t, options, helmChartPath, releaseName)
59+
podName = testUtil.HelmInstall(t, options, releaseName, kubectlOptions)
6760

6861
tlsConfig := tls.Config{}
69-
podName := releaseName + "-marklogic-0"
7062
// wait until the pod is in Ready status
7163
k8s.WaitUntilPodAvailable(t, kubectlOptions, podName, 10, 15*time.Second)
7264
tunnel7997 := k8s.NewTunnel(kubectlOptions, k8s.ResourceTypePod, podName, 7997, 7997)

test/testUtil/helm_install.go

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
// Package testUtil contains utility functions for all the tests in this repo
2+
package testUtil
3+
4+
import (
5+
"path/filepath"
6+
"testing"
7+
"time"
8+
9+
"github.com/gruntwork-io/terratest/modules/helm"
10+
"github.com/gruntwork-io/terratest/modules/k8s"
11+
)
12+
13+
// HelmInstall : testUtil function to install helm chart for e2e tests
14+
func HelmInstall(t *testing.T, options map[string]string, releaseName string, kubectlOpt *k8s.KubectlOptions) string {
15+
16+
// Path to the helm chart we will test
17+
helmChartPath, e := filepath.Abs("../../charts")
18+
if e != nil {
19+
t.Fatalf(e.Error())
20+
}
21+
22+
helmOptions := &helm.Options{
23+
KubectlOptions: kubectlOpt,
24+
SetValues: options,
25+
}
26+
27+
helm.Install(t, helmOptions, helmChartPath, releaseName)
28+
29+
podName := releaseName + "-marklogic-0"
30+
// wait until the pod is in Ready status
31+
k8s.WaitUntilPodAvailable(t, kubectlOpt, podName, 10, 15*time.Second)
32+
return podName
33+
}

0 commit comments

Comments
 (0)