mirror of
https://github.com/k3s-io/k3s.git
synced 2024-06-07 19:41:36 +00:00
Add test for filterByIPFamily
Signed-off-by: Brad Davidson <brad.davidson@rancher.com>
This commit is contained in:
parent
cc333d8d0c
commit
cbe4bcfeee
91
pkg/cloudprovider/servicelb_test.go
Normal file
91
pkg/cloudprovider/servicelb_test.go
Normal file
@ -0,0 +1,91 @@
|
||||
package cloudprovider
|
||||
|
||||
import (
|
||||
"reflect"
|
||||
"testing"
|
||||
|
||||
core "k8s.io/api/core/v1"
|
||||
)
|
||||
|
||||
const (
|
||||
addrv4 = "1.2.3.4"
|
||||
addrv6 = "2001:db8::1"
|
||||
)
|
||||
|
||||
func Test_UnitFilterByIPFamily(t *testing.T) {
|
||||
type args struct {
|
||||
ips []string
|
||||
svc *core.Service
|
||||
}
|
||||
tests := []struct {
|
||||
name string
|
||||
args args
|
||||
want []string
|
||||
wantErr bool
|
||||
}{
|
||||
{
|
||||
name: "No IPFamily",
|
||||
args: args{
|
||||
ips: []string{addrv4, addrv6},
|
||||
svc: &core.Service{
|
||||
Spec: core.ServiceSpec{
|
||||
IPFamilies: []core.IPFamily{},
|
||||
},
|
||||
},
|
||||
},
|
||||
want: nil,
|
||||
wantErr: false,
|
||||
},
|
||||
{
|
||||
name: "IPv4 Only",
|
||||
args: args{
|
||||
ips: []string{addrv4, addrv6},
|
||||
svc: &core.Service{
|
||||
Spec: core.ServiceSpec{
|
||||
IPFamilies: []core.IPFamily{core.IPv4Protocol},
|
||||
},
|
||||
},
|
||||
},
|
||||
want: []string{addrv4},
|
||||
wantErr: false,
|
||||
},
|
||||
{
|
||||
name: "IPv6 Only",
|
||||
args: args{
|
||||
ips: []string{addrv4, addrv6},
|
||||
svc: &core.Service{
|
||||
Spec: core.ServiceSpec{
|
||||
IPFamilies: []core.IPFamily{core.IPv6Protocol},
|
||||
},
|
||||
},
|
||||
},
|
||||
want: []string{addrv6},
|
||||
wantErr: false,
|
||||
},
|
||||
{
|
||||
name: "Dual-Stack",
|
||||
args: args{
|
||||
ips: []string{addrv4, addrv6},
|
||||
svc: &core.Service{
|
||||
Spec: core.ServiceSpec{
|
||||
IPFamilies: []core.IPFamily{core.IPv4Protocol, core.IPv6Protocol},
|
||||
},
|
||||
},
|
||||
},
|
||||
want: []string{addrv4, addrv6},
|
||||
wantErr: false,
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
got, err := filterByIPFamily(tt.args.ips, tt.args.svc)
|
||||
if (err != nil) != tt.wantErr {
|
||||
t.Errorf("filterByIPFamily() error = %v, wantErr %v", err, tt.wantErr)
|
||||
return
|
||||
}
|
||||
if !reflect.DeepEqual(got, tt.want) {
|
||||
t.Errorf("filterByIPFamily() = %+v\nWant = %+v", got, tt.want)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user