@@ -3,7 +3,7 @@ package e2e
3
3
import (
4
4
"crypto/tls"
5
5
"fmt"
6
- "io/ioutil "
6
+ "io"
7
7
"os"
8
8
"path/filepath"
9
9
"regexp"
@@ -15,6 +15,7 @@ import (
15
15
http_helper "github.com/gruntwork-io/terratest/modules/http-helper"
16
16
"github.com/gruntwork-io/terratest/modules/k8s"
17
17
"github.com/gruntwork-io/terratest/modules/random"
18
+ "github.com/imroc/req/v3"
18
19
"github.com/stretchr/testify/assert"
19
20
"github.com/tidwall/gjson"
20
21
digestAuth "github.com/xinsnake/go-http-digest-auth-client"
@@ -64,6 +65,8 @@ func TestHelmUpgrade(t *testing.T) {
64
65
// save the generated password from first installation
65
66
secretName := releaseName + "-admin"
66
67
secret := k8s .GetSecret (t , kubectlOptions , secretName )
68
+ usernameArr := secret .Data ["username" ]
69
+ username := string (usernameArr )
67
70
passwordArr := secret .Data ["password" ]
68
71
passwordAfterInstall := string (passwordArr [:])
69
72
@@ -82,12 +85,21 @@ func TestHelmUpgrade(t *testing.T) {
82
85
helm .Upgrade (t , newOptions , helmChartPath , releaseName )
83
86
84
87
tlsConfig := tls.Config {}
85
- podName := releaseName + "-1"
88
+ podOneName := releaseName + "-1"
89
+ podZeroName := releaseName + "-0"
86
90
87
91
// 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
+
89
100
tunnel := k8s .NewTunnel (
90
- kubectlOptions , k8s .ResourceTypePod , podName , 7997 , 7997 )
101
+ kubectlOptions , k8s .ResourceTypePod , podZeroName , 7997 , 7997 )
102
+
91
103
defer tunnel .Close ()
92
104
tunnel .ForwardPort (t )
93
105
endpoint := fmt .Sprintf ("http://%s" , tunnel .Endpoint ())
@@ -97,20 +109,51 @@ func TestHelmUpgrade(t *testing.T) {
97
109
t ,
98
110
endpoint ,
99
111
& tlsConfig ,
100
- 10 ,
101
- 15 * time .Second ,
112
+ 15 ,
113
+ 20 * time .Second ,
102
114
func (statusCode int , body string ) bool {
103
115
return statusCode == 200
104
116
},
105
117
)
106
118
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 )
113
146
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
+ }
114
157
func TestMLupgrade (t * testing.T ) {
115
158
// Path to the helm chart we will test
116
159
helmChartPath , e := filepath .Abs ("../../charts" )
@@ -202,15 +245,15 @@ func TestMLupgrade(t *testing.T) {
202
245
t .Fatalf (err .Error ())
203
246
}
204
247
defer resp .Body .Close ()
205
- body , err := ioutil .ReadAll (resp .Body )
248
+ body , err := io .ReadAll (resp .Body )
206
249
if err != nil {
207
250
t .Fatalf (err .Error ())
208
251
}
209
252
mlVersionPattern := regexp .MustCompile (`(\d+\.\d+)` )
210
253
mlVersionResp := gjson .Get (string (body ), `local-cluster-default.version` )
211
254
actualMlVersion := mlVersionPattern .FindStringSubmatch (mlVersionResp .Str )
212
255
expectedMlVersion := mlVersionPattern .FindStringSubmatch (imageTag )
213
- //expectedMlVersion := strings.Split(imageTag, "-centos")[0]
256
+ // expectedMlVersion := strings.Split(imageTag, "-centos")[0]
214
257
// verify latest MarkLogic version after upgrade
215
258
assert .Equal (t , actualMlVersion , expectedMlVersion )
216
259
}
0 commit comments