Skip to content

Commit

Permalink
fix bugs and enhance unit test coverage for all functions in pkg/util…
Browse files Browse the repository at this point in the history
…/validator.go (#4505)

* Fix bugs in validator.go and enhance unit test coverage for all functions

---------

Signed-off-by: dolibali <[email protected]>
Co-authored-by: dolibali <[email protected]>
  • Loading branch information
dolibali and dolibali committed Sep 18, 2024
1 parent 640f683 commit a2b22ec
Show file tree
Hide file tree
Showing 2 changed files with 464 additions and 6 deletions.
11 changes: 6 additions & 5 deletions pkg/util/validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ func ValidateSubnet(subnet kubeovnv1.Subnet) error {
for _, cidr := range strings.Split(subnet.Spec.CIDRBlock, ",") {
// v6 ip address can not use upper case
if ContainsUppercase(subnet.Spec.CIDRBlock) {
err := fmt.Errorf("subnet cidr block %s v6 ip address can not contain upper case", subnet.Spec.Gateway)
err := fmt.Errorf("subnet cidr block %s v6 ip address can not contain upper case", subnet.Spec.CIDRBlock)
klog.Error(err)
return err
}
Expand All @@ -86,7 +86,7 @@ func ValidateSubnet(subnet kubeovnv1.Subnet) error {
allow := subnet.Spec.AllowSubnets
for _, cidr := range allow {
// v6 ip address can not use upper case
if ContainsUppercase(subnet.Spec.CIDRBlock) {
if ContainsUppercase(cidr) {
err := fmt.Errorf("subnet %s allow subnet %s v6 ip address can not contain upper case", subnet.Name, cidr)
klog.Error(err)
return err
Expand Down Expand Up @@ -205,10 +205,11 @@ func validateNatOutgoingPolicyRules(subnet kubeovnv1.Subnet) error {
}

func validateNatOutGoingPolicyRuleIPs(matchIPStr string) (string, error) {
ipItems := strings.Split(matchIPStr, ",")
if len(ipItems) == 0 {
return "", errors.New("MatchIPStr format error")
if matchIPStr = strings.TrimSpace(matchIPStr); matchIPStr == "" {
return "", errors.New("IPStr should not be empty")
}

ipItems := strings.Split(matchIPStr, ",")
lastProtocol := ""
checkProtocolConsistent := func(ipCidr string) bool {
currentProtocol := CheckProtocol(ipCidr)
Expand Down
Loading

0 comments on commit a2b22ec

Please sign in to comment.