-
Notifications
You must be signed in to change notification settings - Fork 454
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix getting subnet cidr by protocol (#4844)
Signed-off-by: zhangzujian <[email protected]>
- Loading branch information
1 parent
5e8288b
commit e19f48c
Showing
3 changed files
with
77 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package daemon | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
|
||
kubeovnv1 "github.com/kubeovn/kube-ovn/pkg/apis/kubeovn/v1" | ||
) | ||
|
||
func TestGetCidrByProtocol(t *testing.T) { | ||
cases := []struct { | ||
name string | ||
cidr string | ||
protocol string | ||
wantErr bool | ||
expetced string | ||
}{{ | ||
name: "ipv4 only", | ||
cidr: "1.1.1.0/24", | ||
protocol: kubeovnv1.ProtocolIPv4, | ||
expetced: "1.1.1.0/24", | ||
}, { | ||
name: "ipv6 only", | ||
cidr: "2001:db8::/120", | ||
protocol: kubeovnv1.ProtocolIPv6, | ||
expetced: "2001:db8::/120", | ||
}, { | ||
name: "get ipv4 from ipv6", | ||
cidr: "2001:db8::/120", | ||
protocol: kubeovnv1.ProtocolIPv4, | ||
}, { | ||
name: "get ipv4 from dual stack", | ||
cidr: "1.1.1.0/24,2001:db8::/120", | ||
protocol: kubeovnv1.ProtocolIPv4, | ||
expetced: "1.1.1.0/24", | ||
}, { | ||
name: "get ipv6 from ipv4", | ||
cidr: "1.1.1.0/24", | ||
protocol: kubeovnv1.ProtocolIPv6, | ||
}, { | ||
name: "get ipv6 from dual stack", | ||
cidr: "1.1.1.0/24,2001:db8::/120", | ||
protocol: kubeovnv1.ProtocolIPv6, | ||
expetced: "2001:db8::/120", | ||
}, { | ||
name: "invalid cidr", | ||
cidr: "foo bar", | ||
protocol: kubeovnv1.ProtocolIPv4, | ||
wantErr: true, | ||
}} | ||
for _, c := range cases { | ||
t.Run(c.name, func(t *testing.T) { | ||
got, err := getCidrByProtocol(c.cidr, c.protocol) | ||
if (err != nil) != c.wantErr { | ||
t.Errorf("getCidrByProtocol(%q, %q) error = %v, wantErr = %v", c.cidr, c.protocol, err, c.wantErr) | ||
} | ||
require.Equal(t, c.expetced, got) | ||
}) | ||
} | ||
} |