-
Notifications
You must be signed in to change notification settings - Fork 453
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: zhangzujian <[email protected]>
- Loading branch information
1 parent
e9cc33f
commit f4345a8
Showing
1 changed file
with
60 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package daemon | ||
|
||
import ( | ||
"testing" | ||
|
||
kubeovnv1 "github.com/kubeovn/kube-ovn/pkg/apis/kubeovn/v1" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
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) | ||
}) | ||
} | ||
} |