diff --git a/cmd/gateway/gateway_suite_test.go b/cmd/gateway/gateway_suite_test.go index 074dceea4c..f364bbb9c8 100644 --- a/cmd/gateway/gateway_suite_test.go +++ b/cmd/gateway/gateway_suite_test.go @@ -3,7 +3,7 @@ package main_test import ( "testing" - . "github.com/onsi/ginkgo" + . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" ) diff --git a/cmd/gateway/setup.go b/cmd/gateway/setup.go index 1c6c585800..e6f3260fa0 100644 --- a/cmd/gateway/setup.go +++ b/cmd/gateway/setup.go @@ -28,12 +28,6 @@ type ( V Validator Key string } - - EnvValidator func(string) error - EnvValidatorContext struct { - V EnvValidator - Key string - } ) func GatewayControllerParam(domain string) ValidatorContext { @@ -131,8 +125,9 @@ func MustValidateArguments(flagset *flag.FlagSet, validators ...ValidatorContext func ValidatePodIP(podIP string) error { if podIP == "" { return errors.New("POD_IP environment variable must be set") - } else if net.ParseIP(podIP) == nil { - return fmt.Errorf("POD_IP '%s' must be a valid IP address", podIP) + } + if net.ParseIP(podIP) == nil { + return fmt.Errorf("POD_IP %q must be a valid IP address", podIP) } return nil diff --git a/cmd/gateway/setup_test.go b/cmd/gateway/setup_test.go index 85838a6558..f44e5f82a6 100644 --- a/cmd/gateway/setup_test.go +++ b/cmd/gateway/setup_test.go @@ -3,7 +3,7 @@ package main_test import ( "errors" - . "github.com/onsi/ginkgo" + . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" flag "github.com/spf13/pflag" @@ -265,15 +265,23 @@ var _ = Describe("Main", func() { }) // CLI argument validation Describe("environment variable validaton", func() { - It("should validate the POD_IP env var", func() { - // var not set - err := ValidatePodIP("") - Expect(err.Error()).To(ContainSubstring("must be set")) - // var set to invalid value - err = ValidatePodIP("invalid") - Expect(err.Error()).To(ContainSubstring("must be a valid")) - // var set to valid value - Expect(ValidatePodIP("1.2.3.4")).To(Succeed()) - }) + type testCase struct { + expSubMsg string + podIP string + expErr bool + } + DescribeTable("should validate the POD_IP env var", + func(tc testCase) { + err := ValidatePodIP(tc.podIP) + if !tc.expErr { + Expect(err).ToNot(HaveOccurred()) + } else { + Expect(err.Error()).To(ContainSubstring(tc.expSubMsg)) + } + }, + Entry("var not set", testCase{podIP: "", expErr: true, expSubMsg: "must be set"}), + Entry("var set to invalid value", testCase{podIP: "invalid", expErr: true, expSubMsg: "must be a valid"}), + Entry("var set to valid value", testCase{podIP: "1.2.3.4", expErr: false}), + ) }) // environment variable validation }) // end Main