Skip to content

Commit fe52769

Browse files
committed
TEST/MINOR: fix some unit tests and e2e tests random failures
1 parent 541c418 commit fe52769

File tree

7 files changed

+34
-2
lines changed

7 files changed

+34
-2
lines changed

deploy/tests/e2e/crd-tcp/suite_test.go

+16-1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ import (
2121
"io"
2222
"strings"
2323

24+
"github.com/google/go-cmp/cmp"
25+
"github.com/google/go-cmp/cmp/cmpopts"
26+
2427
"github.com/stretchr/testify/suite"
2528

2629
parser "github.com/haproxytech/config-parser/v5"
@@ -81,7 +84,19 @@ func (suite *CRDTCPSuite) BeforeTest(suiteName, testName string) {
8184
func (suite *CRDTCPSuite) checkFrontend(p parser.Parser, frontendName, param string, value common.ParserData) {
8285
v, err := p.Get(parser.Frontends, frontendName, param)
8386
suite.Require().NoError(err, "Could not get Haproxy config parser Frontend %s param %s", frontendName, param)
84-
suite.Equal(value, v, fmt.Sprintf("Frontend param %s should be equal to %v but is %v", param, value, v))
87+
88+
// Sort functions for map[string]XXX
89+
sortBinds := cmpopts.SortSlices(func(a, b types.Bind) bool {
90+
return a.Path < b.Path
91+
})
92+
areEqual := cmp.Equal(v, value, sortBinds)
93+
94+
if !areEqual {
95+
diff := cmp.Diff(v, value, sortBinds)
96+
suite.T().Log(diff)
97+
}
98+
99+
suite.Equal(areEqual, true, fmt.Sprintf("Frontend param %s should be equal to %v but is %v", param, value, v))
85100
}
86101

87102
func (suite *CRDTCPSuite) checkBackend(p parser.Parser, backendName, param string, value common.ParserData) {

deploy/tests/integration/config-snippet/suite_test.go

+3
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
package configsnippet_test
1616

1717
import (
18+
"os"
1819
"testing"
1920

2021
"github.com/haproxytech/kubernetes-ingress/deploy/tests/integration"
@@ -44,6 +45,8 @@ func (suite *DisableConfigSnippetSuite) BeforeTest(suiteName, testName string) {
4445
suite.BaseSuite.BeforeTest(suiteName, testName)
4546
// Add any needed update to the controller setting
4647
// by updating suite.TestControllers[suite.T().Name()].XXXXX
48+
os.Unsetenv("POD_NAME")
49+
os.Unsetenv("POD_NAMESPACE")
4750
testController := suite.TestControllers[suite.T().Name()]
4851
testController.OSArgs.ConfigMap.Name = configMapName
4952
testController.OSArgs.ConfigMap.Namespace = configMapNamespace

deploy/tests/integration/pod-maxconn/suite_test.go

+3
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
package podmaxconn
1616

1717
import (
18+
"os"
1819
"testing"
1920

2021
"github.com/haproxytech/kubernetes-ingress/deploy/tests/integration"
@@ -44,6 +45,8 @@ func (suite *PodMaxConnSuite) BeforeTest(suiteName, testName string) {
4445
suite.BaseSuite.BeforeTest(suiteName, testName)
4546
// Add any needed update to the controller setting
4647
// by updating suite.TestControllers[suite.T().Name()].XXXXX
48+
os.Unsetenv("POD_NAME")
49+
os.Unsetenv("POD_NAMESPACE")
4750
testController := suite.TestControllers[suite.T().Name()]
4851
testController.OSArgs.ConfigMap.Name = configMapName
4952
testController.OSArgs.ConfigMap.Namespace = configMapNamespace

deploy/tests/integration/timeout-server/suite_test.go

+3
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
package timeoutserver
1616

1717
import (
18+
"os"
1819
"testing"
1920

2021
"github.com/haproxytech/kubernetes-ingress/deploy/tests/integration"
@@ -44,6 +45,8 @@ func (suite *TimeoutServerSuite) BeforeTest(suiteName, testName string) {
4445
suite.BaseSuite.BeforeTest(suiteName, testName)
4546
// Add any needed update to the controller setting
4647
// by updating suite.TestControllers[suite.T().Name()].XXXXX
48+
os.Unsetenv("POD_NAME")
49+
os.Unsetenv("POD_NAMESPACE")
4750
testController := suite.TestControllers[suite.T().Name()]
4851
testController.OSArgs.ConfigMap.Name = configMapName
4952
testController.OSArgs.ConfigMap.Namespace = configMapNamespace

deploy/tests/ut/acls/suite_test.go

+4
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,10 @@ func (suite *ACLSuite) BeforeTest(suiteName, testName string) {
6767
suite.T().Logf("temporary configuration dir %s", suite.test.TempDir)
6868
}
6969

70+
func (suite *ACLSuite) TearDownSuite() {
71+
os.Unsetenv("POD_NAME")
72+
}
73+
7074
func (suite *ACLSuite) UseACLFixture() (eventChan chan k8ssync.SyncDataEvent) {
7175
var osArgs utils.OSArgs
7276
os.Args = []string{os.Args[0], "-e", "-t", "--config-dir=" + suite.test.TempDir}

deploy/tests/ut/httprequests/suite_test.go

+4
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,10 @@ func (suite *HTTPRequestsSuite) BeforeTest(suiteName, testName string) {
6767
suite.T().Logf("temporary configuration dir %s", suite.test.TempDir)
6868
}
6969

70+
func (suite *HTTPRequestsSuite) TearDownSuite() {
71+
os.Unsetenv("POD_NAME")
72+
}
73+
7074
func (suite *HTTPRequestsSuite) UseHTTPRequestsFixture() (eventChan chan k8ssync.SyncDataEvent) {
7175
var osArgs utils.OSArgs
7276
os.Args = []string{os.Args[0], "-e", "-t", "--config-dir=" + suite.test.TempDir}

go.mod

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ require (
77
github.com/fasthttp/router v1.4.20
88
github.com/go-openapi/swag v0.23.0
99
github.com/go-test/deep v1.1.0
10+
github.com/google/go-cmp v0.6.0
1011
github.com/google/renameio v1.0.1
1112
github.com/haproxytech/client-native/v3 v3.1.2-0.20230607075433-231591da68ed
1213
github.com/haproxytech/client-native/v5 v5.1.4
@@ -51,7 +52,6 @@ require (
5152
github.com/gogo/protobuf v1.3.2 // indirect
5253
github.com/golang/protobuf v1.5.4 // indirect
5354
github.com/google/gnostic-models v0.6.8 // indirect
54-
github.com/google/go-cmp v0.6.0 // indirect
5555
github.com/google/gofuzz v1.2.0 // indirect
5656
github.com/google/uuid v1.6.0 // indirect
5757
github.com/haproxytech/go-logger v1.1.0 // indirect

0 commit comments

Comments
 (0)