Skip to content

Commit

Permalink
Code review cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
sjberman committed May 16, 2023
1 parent f077362 commit 43c3209
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 20 deletions.
2 changes: 1 addition & 1 deletion cmd/gateway/gateway_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package main_test
import (
"testing"

. "github.com/onsi/ginkgo"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
)

Expand Down
11 changes: 3 additions & 8 deletions cmd/gateway/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,6 @@ type (
V Validator
Key string
}

EnvValidator func(string) error
EnvValidatorContext struct {
V EnvValidator
Key string
}
)

func GatewayControllerParam(domain string) ValidatorContext {
Expand Down Expand Up @@ -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
Expand Down
30 changes: 19 additions & 11 deletions cmd/gateway/setup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -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

0 comments on commit 43c3209

Please sign in to comment.