Skip to content

Commit 70df390

Browse files
author
Barkha Choithani
committed
merged tests for upgrade and used a specific version for upgrade
1 parent d8ff9e4 commit 70df390

File tree

1 file changed

+85
-0
lines changed

1 file changed

+85
-0
lines changed

test/e2e/upgrade_test.go

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,15 @@ import (
88
"strings"
99
"testing"
1010
"time"
11+
"io/ioutil"
1112

1213
"github.com/gruntwork-io/terratest/modules/helm"
1314
http_helper "github.com/gruntwork-io/terratest/modules/http-helper"
1415
"github.com/gruntwork-io/terratest/modules/k8s"
1516
"github.com/gruntwork-io/terratest/modules/random"
1617
"github.com/stretchr/testify/assert"
18+
"github.com/tidwall/gjson"
19+
digestAuth "github.com/xinsnake/go-http-digest-auth-client"
1720
)
1821

1922
func TestHelmUpgrade(t *testing.T) {
@@ -106,3 +109,85 @@ func TestHelmUpgrade(t *testing.T) {
106109
passwordAfterUpgrade := string(passwordArr[:])
107110
assert.Equal(t, passwordAfterUpgrade, passwordAfterInstall)
108111
}
112+
113+
func TestMLupgrade(t *testing.T) {
114+
// Path to the helm chart we will test
115+
helmChartPath, e := filepath.Abs("../../charts")
116+
if e != nil {
117+
t.Fatalf(e.Error())
118+
}
119+
username := "admin"
120+
password := "admin"
121+
122+
namespaceName := "marklogic-" + strings.ToLower(random.UniqueId())
123+
kubectlOptions := k8s.NewKubectlOptions("", "", namespaceName)
124+
options := &helm.Options{
125+
KubectlOptions: kubectlOptions,
126+
SetValues: map[string]string{
127+
"persistence.enabled": "false",
128+
"replicaCount": "1",
129+
"image.repository": "marklogicdb/marklogic-db",
130+
"image.tag": "latest-10.0",
131+
"auth.adminUsername": username,
132+
"auth.adminPassword": password,
133+
},
134+
}
135+
136+
t.Logf("====Creating namespace: " + namespaceName)
137+
k8s.CreateNamespace(t, kubectlOptions, namespaceName)
138+
defer t.Logf("====Deleting namespace: " + namespaceName)
139+
defer k8s.DeleteNamespace(t, kubectlOptions, namespaceName)
140+
141+
t.Logf("====Installing Helm Chart")
142+
releaseName := "test-ml-upgrade"
143+
helm.Install(t, options, helmChartPath, releaseName)
144+
145+
podName := releaseName + "-marklogic-0"
146+
147+
// wait until second pod is in Ready status
148+
k8s.WaitUntilPodAvailable(t, kubectlOptions, podName, 20, 20*time.Second)
149+
150+
newOptions := &helm.Options{
151+
KubectlOptions: kubectlOptions,
152+
SetValues: map[string]string{
153+
"persistence.enabled": "false",
154+
"image.repository": "marklogicdb/marklogic-db",
155+
"image.tag": "latest-11.0",
156+
"logCollection.enabled": "false",
157+
},
158+
}
159+
160+
t.Logf("====Upgrading Helm Chart")
161+
helm.Upgrade(t, newOptions, helmChartPath, releaseName)
162+
163+
// Give time to change status of pod from running to terminate during upgrade
164+
time.Sleep(10 * time.Second)
165+
166+
// wait until second pod is in Ready status
167+
k8s.WaitUntilPodAvailable(t, kubectlOptions, podName, 15, 30*time.Second)
168+
169+
tunnel := k8s.NewTunnel(
170+
kubectlOptions, k8s.ResourceTypePod, podName, 8002, 8002)
171+
defer tunnel.Close()
172+
tunnel.ForwardPort(t)
173+
174+
clusterEndpoint := fmt.Sprintf("http://%s/manage/v2?format=json", tunnel.Endpoint())
175+
t.Logf(`Endpoint: %s`, clusterEndpoint)
176+
177+
getMLversion := digestAuth.NewRequest(username, password, "GET", clusterEndpoint, "")
178+
179+
resp, err := getMLversion.Execute()
180+
if err != nil {
181+
t.Fatalf(err.Error())
182+
}
183+
defer resp.Body.Close()
184+
body, err := ioutil.ReadAll(resp.Body)
185+
if err != nil {
186+
t.Fatalf(err.Error())
187+
}
188+
mlVersion := gjson.Get(string(body), `local-cluster-default.version`)
189+
190+
// verify latest MarkLogic version after upgrade
191+
assert.Equal(t, mlVersion.Str, "11.0.0")
192+
193+
}

0 commit comments

Comments
 (0)