Skip to content

Commit e63f599

Browse files
added e2e test for additional AppServer (#233)
1 parent 4fc9dfd commit e63f599

File tree

3 files changed

+139
-0
lines changed

3 files changed

+139
-0
lines changed

test/e2e/path_based_test.go

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313
"github.com/gruntwork-io/terratest/modules/k8s"
1414
"github.com/gruntwork-io/terratest/modules/random"
1515
"github.com/imroc/req/v3"
16+
"github.com/stretchr/testify/assert"
1617
"github.com/tidwall/gjson"
1718
)
1819

@@ -145,6 +146,110 @@ func TestPathBasedRouting(t *testing.T) {
145146
}
146147
}
147148

149+
func TestPathBasedRoutAppServers(t *testing.T) {
150+
// Path to the helm chart we will test
151+
helmChartPath, e := filepath.Abs("../../charts")
152+
if e != nil {
153+
t.Fatalf(e.Error())
154+
}
155+
username := "admin"
156+
password := "admin"
157+
158+
namespaceName := "ml-" + strings.ToLower(random.UniqueId())
159+
kubectlOptions := k8s.NewKubectlOptions("", "", namespaceName)
160+
161+
// Setup the args for helm install using custom values.yaml file
162+
options := &helm.Options{
163+
ValuesFiles: []string{"../test_data/values/tls_pbr_appser_values.yaml"},
164+
KubectlOptions: k8s.NewKubectlOptions("", "", namespaceName),
165+
}
166+
167+
t.Logf("====Creating namespace: " + namespaceName)
168+
k8s.CreateNamespace(t, kubectlOptions, namespaceName)
169+
170+
defer t.Logf("====Deleting namespace: " + namespaceName)
171+
defer k8s.DeleteNamespace(t, kubectlOptions, namespaceName)
172+
173+
t.Logf("====Installing Helm Chart")
174+
releaseName := "test-path"
175+
helm.Install(t, options, helmChartPath, releaseName)
176+
177+
podName := releaseName + "-1"
178+
svcName := releaseName + "-haproxy"
179+
180+
// wait until the pod is in Ready status
181+
k8s.WaitUntilPodAvailable(t, kubectlOptions, podName, 15, 20*time.Second)
182+
183+
tunnel := k8s.NewTunnel(
184+
kubectlOptions, k8s.ResourceTypeService, svcName, 8080, 80)
185+
defer tunnel.Close()
186+
tunnel.ForwardPort(t)
187+
188+
client := req.C().
189+
SetCommonBasicAuth(username, password).
190+
SetCommonRetryCount(10).
191+
SetCommonRetryFixedInterval(10 * time.Second)
192+
193+
endpoint := "http://localhost:8080/manage/manage/v2/servers?group-id=Default&server-type=http&format=json"
194+
fmt.Println(endpoint)
195+
testServerReq, err := os.ReadFile("../test_data/path_based_test_data/test-server.json")
196+
if err != nil {
197+
fmt.Print(err)
198+
}
199+
200+
//create new app server: test-server
201+
resp, err := client.R().
202+
SetHeader("Content-type", "application/json").
203+
SetBodyJsonString(string(testServerReq)).
204+
AddRetryCondition(func(resp *req.Response, err error) bool {
205+
if err != nil {
206+
t.Logf("error: %s", err.Error())
207+
}
208+
t.Logf("StatusCode: %d", resp.GetStatusCode())
209+
if resp.GetStatusCode() != 201 {
210+
t.Log("Waiting for MarkLogic cluster to be ready")
211+
}
212+
return resp.GetStatusCode() != 201
213+
}).
214+
Post(endpoint)
215+
if err != nil {
216+
t.Fatalf(err.Error())
217+
}
218+
defer resp.Body.Close()
219+
220+
//test the additional app servers path
221+
path := "test"
222+
endpoint = fmt.Sprintf("http://localhost:8080/%s", path)
223+
t.Logf("Verifying path based routing using %s", endpoint)
224+
resp, err = client.R().
225+
AddRetryCondition(func(resp *req.Response, err error) bool {
226+
if err != nil {
227+
t.Logf("error: %s", err.Error())
228+
}
229+
t.Logf("StatusCode: %d", resp.GetStatusCode())
230+
if resp.GetStatusCode() != 500 {
231+
t.Log("Waiting for MarkLogic cluster to be ready")
232+
}
233+
return resp.GetStatusCode() != 500
234+
}).
235+
Get(endpoint)
236+
237+
if err != nil {
238+
t.Errorf("Error routing to %s", path)
239+
t.Fatalf(err.Error())
240+
}
241+
defer resp.Body.Close()
242+
243+
//the response for test-server should be 500 and error message XDMP-MODNOTFOUND
244+
//because test-server exist and there is no app running on it
245+
assert.Equal(t, 500, resp.GetStatusCode())
246+
body, err := io.ReadAll(resp.Body)
247+
if err != nil {
248+
t.Fatalf(err.Error())
249+
}
250+
assert.Contains(t, string(body), "XDMP-MODNOTFOUND")
251+
}
252+
148253
func TestPathBasedRoutingWithTLS(t *testing.T) {
149254
// Path to the helm chart we will test
150255
helmChartPath, e := filepath.Abs("../../charts")
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"server-name":"test-server",
3+
"root":"/",
4+
"port":8010,
5+
"error-handler":"/error-switch.xqy",
6+
"content-database":"Documents",
7+
"authentication":"basic"
8+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# This is a custom values files for path based routing additional app servers e2e tests
2+
persistence:
3+
enabled: false
4+
5+
replicaCount: 2
6+
7+
image:
8+
repository: marklogicdb/marklogic-db
9+
tag: latest-11
10+
11+
auth:
12+
adminPassword: admin
13+
adminUsername: admin
14+
15+
haproxy:
16+
enabled: true
17+
replicaCount: 1
18+
frontendPort: 80
19+
pathbased:
20+
enabled: true
21+
additionalAppServers:
22+
- name: test-server
23+
type: HTTP
24+
port: 8010
25+
targetPort: 8010
26+
path: /test

0 commit comments

Comments
 (0)