@@ -8,12 +8,15 @@ import (
8
8
"strings"
9
9
"testing"
10
10
"time"
11
+ "io/ioutil"
11
12
12
13
"github.com/gruntwork-io/terratest/modules/helm"
13
14
http_helper "github.com/gruntwork-io/terratest/modules/http-helper"
14
15
"github.com/gruntwork-io/terratest/modules/k8s"
15
16
"github.com/gruntwork-io/terratest/modules/random"
16
17
"github.com/stretchr/testify/assert"
18
+ "github.com/tidwall/gjson"
19
+ digestAuth "github.com/xinsnake/go-http-digest-auth-client"
17
20
)
18
21
19
22
func TestHelmUpgrade (t * testing.T ) {
@@ -106,3 +109,85 @@ func TestHelmUpgrade(t *testing.T) {
106
109
passwordAfterUpgrade := string (passwordArr [:])
107
110
assert .Equal (t , passwordAfterUpgrade , passwordAfterInstall )
108
111
}
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