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 (kubeovn#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
2 people authored and zcq98 committed Sep 18, 2024
1 parent a9d1409 commit fdf0c90
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 fdf0c90

Please sign in to comment.