@@ -3,7 +3,7 @@ package e2e
33import (
44 "crypto/tls"
55 "fmt"
6- "io/ioutil "
6+ "io"
77 "os"
88 "path/filepath"
99 "regexp"
@@ -15,6 +15,7 @@ import (
1515 http_helper "github.com/gruntwork-io/terratest/modules/http-helper"
1616 "github.com/gruntwork-io/terratest/modules/k8s"
1717 "github.com/gruntwork-io/terratest/modules/random"
18+ "github.com/imroc/req/v3"
1819 "github.com/stretchr/testify/assert"
1920 "github.com/tidwall/gjson"
2021 digestAuth "github.com/xinsnake/go-http-digest-auth-client"
@@ -64,6 +65,8 @@ func TestHelmUpgrade(t *testing.T) {
6465 // save the generated password from first installation
6566 secretName := releaseName + "-admin"
6667 secret := k8s .GetSecret (t , kubectlOptions , secretName )
68+ usernameArr := secret .Data ["username" ]
69+ username := string (usernameArr )
6770 passwordArr := secret .Data ["password" ]
6871 passwordAfterInstall := string (passwordArr [:])
6972
@@ -82,12 +85,21 @@ func TestHelmUpgrade(t *testing.T) {
8285 helm .Upgrade (t , newOptions , helmChartPath , releaseName )
8386
8487 tlsConfig := tls.Config {}
85- podName := releaseName + "-1"
88+ podOneName := releaseName + "-1"
89+ podZeroName := releaseName + "-0"
8690
8791 // wait until the pod is in Ready status
88- k8s .WaitUntilPodAvailable (t , kubectlOptions , podName , 20 , 20 * time .Second )
92+ k8s .WaitUntilPodAvailable (t , kubectlOptions , podOneName , 20 , 20 * time .Second )
93+
94+ t .Log ("====Test password in secret should not change after upgrade====" )
95+ secret = k8s .GetSecret (t , kubectlOptions , secretName )
96+ passwordArr = secret .Data ["password" ]
97+ passwordAfterUpgrade := string (passwordArr [:])
98+ assert .Equal (t , passwordAfterUpgrade , passwordAfterInstall )
99+
89100 tunnel := k8s .NewTunnel (
90- kubectlOptions , k8s .ResourceTypePod , podName , 7997 , 7997 )
101+ kubectlOptions , k8s .ResourceTypePod , podZeroName , 7997 , 7997 )
102+
91103 defer tunnel .Close ()
92104 tunnel .ForwardPort (t )
93105 endpoint := fmt .Sprintf ("http://%s" , tunnel .Endpoint ())
@@ -97,20 +109,51 @@ func TestHelmUpgrade(t *testing.T) {
97109 t ,
98110 endpoint ,
99111 & tlsConfig ,
100- 10 ,
101- 15 * time .Second ,
112+ 15 ,
113+ 20 * time .Second ,
102114 func (statusCode int , body string ) bool {
103115 return statusCode == 200
104116 },
105117 )
106118
107- t .Log ("====Test password in secret should not change after upgrade====" )
108- secret = k8s .GetSecret (t , kubectlOptions , secretName )
109- passwordArr = secret .Data ["password" ]
110- passwordAfterUpgrade := string (passwordArr [:])
111- assert .Equal (t , passwordAfterUpgrade , passwordAfterInstall )
112- }
119+ tunnel8002 := k8s .NewTunnel (
120+ kubectlOptions , k8s .ResourceTypePod , podZeroName , 8002 , 8002 )
121+ defer tunnel8002 .Close ()
122+ tunnel8002 .ForwardPort (t )
123+
124+ hostsEndpoint := fmt .Sprintf ("http://%s/manage/v2/hosts?view=status&format=json" , tunnel8002 .Endpoint ())
125+ t .Logf (`Endpoint: %s` , hostsEndpoint )
126+
127+ totalHosts := 1
128+ client := req .C ().
129+ SetCommonDigestAuth (username , passwordAfterUpgrade ).
130+ SetCommonRetryCount (10 ).
131+ SetCommonRetryFixedInterval (10 * time .Second )
132+
133+ resp , err := client .R ().
134+ AddRetryCondition (func (resp * req.Response , err error ) bool {
135+ body , err := io .ReadAll (resp .Body )
136+ if err != nil {
137+ t .Logf ("error: %s" , err .Error ())
138+ }
139+ totalHosts = int (gjson .Get (string (body ), `host-status-list.status-list-summary.total-hosts.value` ).Num )
140+ if totalHosts != 2 {
141+ t .Log ("Waiting for second host to join MarkLogic cluster" )
142+ }
143+ return totalHosts != 2
144+ }).
145+ Get (hostsEndpoint )
113146
147+ if err != nil {
148+ t .Fatalf (err .Error ())
149+ }
150+ defer resp .Body .Close ()
151+
152+ if totalHosts != 2 {
153+ t .Errorf ("Incorrect number of MarkLogic hosts found after helm upgrade" )
154+ }
155+
156+ }
114157func TestMLupgrade (t * testing.T ) {
115158 // Path to the helm chart we will test
116159 helmChartPath , e := filepath .Abs ("../../charts" )
@@ -202,15 +245,15 @@ func TestMLupgrade(t *testing.T) {
202245 t .Fatalf (err .Error ())
203246 }
204247 defer resp .Body .Close ()
205- body , err := ioutil .ReadAll (resp .Body )
248+ body , err := io .ReadAll (resp .Body )
206249 if err != nil {
207250 t .Fatalf (err .Error ())
208251 }
209252 mlVersionPattern := regexp .MustCompile (`(\d+\.\d+)` )
210253 mlVersionResp := gjson .Get (string (body ), `local-cluster-default.version` )
211254 actualMlVersion := mlVersionPattern .FindStringSubmatch (mlVersionResp .Str )
212255 expectedMlVersion := mlVersionPattern .FindStringSubmatch (imageTag )
213- //expectedMlVersion := strings.Split(imageTag, "-centos")[0]
256+ // expectedMlVersion := strings.Split(imageTag, "-centos")[0]
214257 // verify latest MarkLogic version after upgrade
215258 assert .Equal (t , actualMlVersion , expectedMlVersion )
216259}
0 commit comments