Skip to content

Commit 232aa0d

Browse files
committed
TEST: Add e2e test for errorfiles and patternfiles
1 parent 14110c5 commit 232aa0d

File tree

8 files changed

+249
-0
lines changed

8 files changed

+249
-0
lines changed

deploy/tests/config/4.ingress-controller.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ spec:
2929
- --default-backend-service=$(POD_NAMESPACE)/default-backend
3030
- --configmap=$(POD_NAMESPACE)/haproxy-configmap
3131
- --configmap-tcp-services=$(POD_NAMESPACE)/haproxy-configmap-tcp
32+
- --configmap-errorfiles=$(POD_NAMESPACE)/errorfiles
33+
- --configmap-patternfiles=$(POD_NAMESPACE)/patternfiles
3234
- --ingress.class=haproxy
3335
- --sync-period=1s
3436
securityContext:
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
---
2+
kind: Service
3+
apiVersion: v1
4+
metadata:
5+
name: http-echo
6+
spec:
7+
ports:
8+
- name: http
9+
protocol: TCP
10+
port: 80
11+
targetPort: http
12+
- name: https
13+
protocol: TCP
14+
port: 443
15+
targetPort: https
16+
selector:
17+
app: http-echo
18+
---
19+
kind: Ingress
20+
apiVersion: networking.k8s.io/v1beta1
21+
metadata:
22+
name: http-echo
23+
annotations:
24+
ingress.class: haproxy
25+
backend-config-snippet: http-after-response set-header result %[var(txn.path),ltrim(/),map(patterns/mapping)]
26+
spec:
27+
rules:
28+
- host: {{ .Host }}
29+
http:
30+
paths:
31+
- path: /
32+
backend:
33+
serviceName: http-echo
34+
servicePort: http
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
apiVersion: v1
2+
kind: ConfigMap
3+
metadata:
4+
name: errorfiles
5+
namespace: haproxy-controller
6+
data:
7+
503: |-
8+
HTTP/1.1 521 Web server is down
9+
Cache-Control: no-cache
10+
Connection: close
11+
Content-Type: text/html
12+
13+
<html><body><h1>Oops, that's embarrassing!</h1>
14+
There are no servers available to handle your request.
15+
</body></html>
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
apiVersion: v1
2+
kind: ConfigMap
3+
metadata:
4+
name: patternfiles
5+
namespace: haproxy-controller
6+
data:
7+
mapping: |
8+
H+DbITVEMAJDRS4EzVF4gVDfTmyUFB3RzEkCIST9 0
9+
GBxqv9YZHQ5dBLMjTjBbyjd4/wS0F0ETZtsnLsYI 1
10+
7tFRKRoboeFENmfTSHj+gjJKFjtOw2u+G+1d13rO 2
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
apiVersion: v1
2+
kind: ConfigMap
3+
metadata:
4+
name: patternfiles
5+
namespace: haproxy-controller
6+
data:
7+
mapping: |
8+
F3ITB+V5w0Yo8ZeS8LO3mkNlFBOxS3i9TDYfVjJv 0
9+
Yn9MvTzjAeLqp7MKE7g7thlf6jc2WRYTNoya+Cqb 1
10+
Y6FX16EEqxJr/B9M2Pzzt/NvivoDjZE2FTr4boBb 2
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
// Copyright 2019 HAProxy Technologies LLC
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
//go:build e2e_parallel
16+
17+
package haproxyfiles
18+
19+
import (
20+
"github.com/haproxytech/kubernetes-ingress/deploy/tests/e2e"
21+
)
22+
23+
func (suite *HAProxyFilesSuite) Test_ErrorFiles() {
24+
suite.Run("Enabled", func() {
25+
suite.NoError(suite.test.Apply("config/errorfiles.yaml", "", nil))
26+
suite.Require().Eventually(func() bool {
27+
res, cls, err := suite.client.Do()
28+
if res == nil {
29+
suite.T().Log(err)
30+
return false
31+
}
32+
defer cls()
33+
return res.StatusCode == 521
34+
}, e2e.WaitDuration, e2e.TickDuration)
35+
})
36+
37+
suite.Run("Disabled", func() {
38+
suite.NoError(suite.test.Delete("config/errorfiles.yaml"))
39+
suite.Require().Eventually(func() bool {
40+
res, cls, err := suite.client.Do()
41+
if res == nil {
42+
suite.T().Log(err)
43+
return false
44+
}
45+
defer cls()
46+
return res.StatusCode == 503
47+
}, e2e.WaitDuration, e2e.TickDuration)
48+
})
49+
}
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
// Copyright 2019 HAProxy Technologies LLC
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
//go:build e2e_parallel
16+
17+
package haproxyfiles
18+
19+
import (
20+
"github.com/haproxytech/kubernetes-ingress/deploy/tests/e2e"
21+
"strconv"
22+
)
23+
24+
var tests1 = []string{
25+
"H+DbITVEMAJDRS4EzVF4gVDfTmyUFB3RzEkCIST9",
26+
"GBxqv9YZHQ5dBLMjTjBbyjd4/wS0F0ETZtsnLsYI",
27+
"7tFRKRoboeFENmfTSHj+gjJKFjtOw2u+G+1d13rO",
28+
}
29+
30+
var tests2 = []string{
31+
"F3ITB+V5w0Yo8ZeS8LO3mkNlFBOxS3i9TDYfVjJv",
32+
"Yn9MvTzjAeLqp7MKE7g7thlf6jc2WRYTNoya+Cqb",
33+
"Y6FX16EEqxJr/B9M2Pzzt/NvivoDjZE2FTr4boBb",
34+
}
35+
36+
func (suite *HAProxyFilesSuite) Test_PatternFiles() {
37+
suite.Run("Enabled", func() {
38+
for i, path := range tests1 {
39+
suite.Require().Eventually(func() bool {
40+
return suite.testHeader(path, strconv.Itoa(i))
41+
}, e2e.WaitDuration, e2e.TickDuration)
42+
}
43+
})
44+
suite.Run("Updated", func() {
45+
suite.NoError(suite.test.Apply("config/patternfiles-2.yaml", "", nil))
46+
for i, path := range tests2 {
47+
suite.Require().Eventually(func() bool {
48+
return suite.testHeader(path, strconv.Itoa(i))
49+
}, e2e.WaitDuration, e2e.TickDuration)
50+
}
51+
})
52+
}
53+
54+
func (suite *HAProxyFilesSuite) testHeader(in, out string) bool {
55+
suite.client.Path = "/" + in
56+
res, cls, err := suite.client.Do()
57+
if res == nil {
58+
suite.T().Log(err)
59+
return false
60+
}
61+
defer cls()
62+
v, ok := res.Header["Result"]
63+
if !ok {
64+
suite.T().Logf("result header not found in %s", res.Header)
65+
return false
66+
}
67+
if v[0] != out {
68+
return false
69+
}
70+
return true
71+
}
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
// Copyright 2019 HAProxy Technologies LLC
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
//go:build e2e_parallel
16+
17+
package haproxyfiles
18+
19+
import (
20+
"testing"
21+
22+
"github.com/stretchr/testify/suite"
23+
24+
"github.com/haproxytech/kubernetes-ingress/deploy/tests/e2e"
25+
)
26+
27+
type HAProxyFilesSuite struct {
28+
suite.Suite
29+
test e2e.Test
30+
client *e2e.Client
31+
tmplData tmplData
32+
}
33+
34+
type tmplData struct {
35+
Host string
36+
}
37+
38+
func (suite *HAProxyFilesSuite) SetupSuite() {
39+
var err error
40+
suite.test, err = e2e.NewTest()
41+
suite.NoError(err)
42+
suite.tmplData = tmplData{Host: suite.test.GetNS() + ".test"}
43+
suite.client, err = e2e.NewHTTPClient(suite.tmplData.Host)
44+
suite.NoError(err)
45+
suite.NoError(suite.test.Apply("config/patternfiles-1.yaml", "", nil))
46+
suite.NoError(suite.test.Apply("config/deploy.yaml.tmpl", suite.test.GetNS(), suite.tmplData))
47+
}
48+
49+
func (suite *HAProxyFilesSuite) TearDownSuite() {
50+
err := suite.test.TearDown()
51+
if err != nil {
52+
suite.T().Error(err)
53+
}
54+
}
55+
56+
func TestHAProxyFilesSuite(t *testing.T) {
57+
suite.Run(t, new(HAProxyFilesSuite))
58+
}

0 commit comments

Comments
 (0)