Skip to content

Commit

Permalink
TEST/MINOR: fix some unit tests and e2e tests random failures
Browse files Browse the repository at this point in the history
  • Loading branch information
hdurand0710 committed Jan 9, 2025
1 parent 77799be commit 084144b
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 1 deletion.
17 changes: 16 additions & 1 deletion deploy/tests/e2e/crd-tcp/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ import (
"io"
"strings"

"github.com/google/go-cmp/cmp"
"github.com/google/go-cmp/cmp/cmpopts"

"github.com/stretchr/testify/suite"

parser "github.com/haproxytech/client-native/v5/config-parser"
Expand Down Expand Up @@ -81,7 +84,19 @@ func (suite *CRDTCPSuite) BeforeTest(suiteName, testName string) {
func (suite *CRDTCPSuite) checkFrontend(p parser.Parser, frontendName, param string, value common.ParserData) {
v, err := p.Get(parser.Frontends, frontendName, param)
suite.Require().NoError(err, "Could not get Haproxy config parser Frontend %s param %s", frontendName, param)
suite.Equal(value, v, fmt.Sprintf("Frontend param %s should be equal to %v but is %v", param, value, v))

// Sort functions for map[string]XXX
sortBinds := cmpopts.SortSlices(func(a, b types.Bind) bool {
return a.Path < b.Path
})
areEqual := cmp.Equal(v, value, sortBinds)

if !areEqual {
diff := cmp.Diff(v, value, sortBinds)
suite.T().Log(diff)
}

suite.Equal(areEqual, true, fmt.Sprintf("Frontend param %s should be equal to %v but is %v", param, value, v))
}

func (suite *CRDTCPSuite) checkBackend(p parser.Parser, backendName, param string, value common.ParserData) {
Expand Down
3 changes: 3 additions & 0 deletions deploy/tests/integration/config-snippet/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
package configsnippet_test

import (
"os"
"testing"

"github.com/haproxytech/kubernetes-ingress/deploy/tests/integration"
Expand Down Expand Up @@ -44,6 +45,8 @@ func (suite *DisableConfigSnippetSuite) BeforeTest(suiteName, testName string) {
suite.BaseSuite.BeforeTest(suiteName, testName)
// Add any needed update to the controller setting
// by updating suite.TestControllers[suite.T().Name()].XXXXX
os.Unsetenv("POD_NAME")
os.Unsetenv("POD_NAMESPACE")
testController := suite.TestControllers[suite.T().Name()]
testController.OSArgs.ConfigMap.Name = configMapName
testController.OSArgs.ConfigMap.Namespace = configMapNamespace
Expand Down
3 changes: 3 additions & 0 deletions deploy/tests/integration/pod-maxconn/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
package podmaxconn

import (
"os"
"testing"

"github.com/haproxytech/kubernetes-ingress/deploy/tests/integration"
Expand Down Expand Up @@ -44,6 +45,8 @@ func (suite *PodMaxConnSuite) BeforeTest(suiteName, testName string) {
suite.BaseSuite.BeforeTest(suiteName, testName)
// Add any needed update to the controller setting
// by updating suite.TestControllers[suite.T().Name()].XXXXX
os.Unsetenv("POD_NAME")
os.Unsetenv("POD_NAMESPACE")
testController := suite.TestControllers[suite.T().Name()]
testController.OSArgs.ConfigMap.Name = configMapName
testController.OSArgs.ConfigMap.Namespace = configMapNamespace
Expand Down
3 changes: 3 additions & 0 deletions deploy/tests/integration/timeout-server/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
package timeoutserver

import (
"os"
"testing"

"github.com/haproxytech/kubernetes-ingress/deploy/tests/integration"
Expand Down Expand Up @@ -44,6 +45,8 @@ func (suite *TimeoutServerSuite) BeforeTest(suiteName, testName string) {
suite.BaseSuite.BeforeTest(suiteName, testName)
// Add any needed update to the controller setting
// by updating suite.TestControllers[suite.T().Name()].XXXXX
os.Unsetenv("POD_NAME")
os.Unsetenv("POD_NAMESPACE")
testController := suite.TestControllers[suite.T().Name()]
testController.OSArgs.ConfigMap.Name = configMapName
testController.OSArgs.ConfigMap.Namespace = configMapNamespace
Expand Down
4 changes: 4 additions & 0 deletions deploy/tests/ut/acls/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@ func (suite *ACLSuite) BeforeTest(suiteName, testName string) {
suite.T().Logf("temporary configuration dir %s", suite.test.TempDir)
}

func (suite *ACLSuite) TearDownSuite() {
os.Unsetenv("POD_NAME")
}

func (suite *ACLSuite) UseACLFixture() (eventChan chan k8ssync.SyncDataEvent) {
var osArgs utils.OSArgs
os.Args = []string{os.Args[0], "-e", "-t", "--config-dir=" + suite.test.TempDir}
Expand Down
4 changes: 4 additions & 0 deletions deploy/tests/ut/httprequests/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@ func (suite *HTTPRequestsSuite) BeforeTest(suiteName, testName string) {
suite.T().Logf("temporary configuration dir %s", suite.test.TempDir)
}

func (suite *HTTPRequestsSuite) TearDownSuite() {
os.Unsetenv("POD_NAME")
}

func (suite *HTTPRequestsSuite) UseHTTPRequestsFixture() (eventChan chan k8ssync.SyncDataEvent) {
var osArgs utils.OSArgs
os.Args = []string{os.Args[0], "-e", "-t", "--config-dir=" + suite.test.TempDir}
Expand Down

0 comments on commit 084144b

Please sign in to comment.