Skip to content

Commit

Permalink
Move TestPodIPsIndexFunc to package controller/grouping (#5379)
Browse files Browse the repository at this point in the history
Move TestPodIPsIndexFunc from package controller/traceflow to controller/grouping,
because PodIPsIndexFunc is in package controller/grouping.

Signed-off-by: shi0rik0 <[email protected]>
  • Loading branch information
shi0rik0 authored Aug 10, 2023
1 parent 2302cfe commit 6363bdb
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 71 deletions.
70 changes: 70 additions & 0 deletions pkg/controller/grouping/controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
package grouping

import (
"reflect"
"testing"
"time"

Expand Down Expand Up @@ -105,3 +106,72 @@ func TestGroupEntityControllerRun(t *testing.T) {
})
}
}

func TestPodIPsIndexFunc(t *testing.T) {
type args struct {
obj interface{}
}
tests := []struct {
name string
args args
want []string
wantErr bool
}{
{
name: "invalid input",
args: args{obj: &struct{}{}},
want: nil,
wantErr: true,
},
{
name: "nil IPs",
args: args{obj: &v1.Pod{}},
want: nil,
wantErr: false,
},
{
name: "zero IPs",
args: args{obj: &v1.Pod{Status: v1.PodStatus{PodIPs: []v1.PodIP{}}}},
want: nil,
wantErr: false,
},
{
name: "PodFailed with podIPs",
args: args{
obj: &v1.Pod{
Status: v1.PodStatus{
PodIPs: []v1.PodIP{{IP: "1.2.3.4"}, {IP: "aaaa::bbbb"}},
Phase: v1.PodFailed,
},
},
},
want: nil,
wantErr: false,
},
{
name: "PodRunning with podIPs",
args: args{
obj: &v1.Pod{
Status: v1.PodStatus{
PodIPs: []v1.PodIP{{IP: "1.2.3.4"}, {IP: "aaaa::bbbb"}},
Phase: v1.PodRunning,
},
},
},
want: []string{"1.2.3.4", "aaaa::bbbb"},
wantErr: false,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got, err := PodIPsIndexFunc(tt.args.obj)
if (err != nil) != tt.wantErr {
t.Errorf("podIPsIndexFunc() error = %v, wantErr %v", err, tt.wantErr)
return
}
if !reflect.DeepEqual(got, tt.want) {
t.Errorf("podIPsIndexFunc() got = %v, want %v", got, tt.want)
}
})
}
}
71 changes: 0 additions & 71 deletions pkg/controller/traceflow/controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ package traceflow

import (
"context"
"reflect"
"testing"
"time"

Expand All @@ -35,7 +34,6 @@ import (
"antrea.io/antrea/pkg/client/clientset/versioned"
fakeversioned "antrea.io/antrea/pkg/client/clientset/versioned/fake"
crdinformers "antrea.io/antrea/pkg/client/informers/externalversions"
"antrea.io/antrea/pkg/controller/grouping"
)

var alwaysReady = func() bool { return true }
Expand Down Expand Up @@ -227,72 +225,3 @@ func newCRDClientset() *fakeversioned.Clientset {

return client
}

func Test_podIPsIndexFunc(t *testing.T) {
type args struct {
obj interface{}
}
tests := []struct {
name string
args args
want []string
wantErr bool
}{
{
name: "invalid input",
args: args{obj: &struct{}{}},
want: nil,
wantErr: true,
},
{
name: "nil IPs",
args: args{obj: &corev1.Pod{}},
want: nil,
wantErr: false,
},
{
name: "zero IPs",
args: args{obj: &corev1.Pod{Status: corev1.PodStatus{PodIPs: []corev1.PodIP{}}}},
want: nil,
wantErr: false,
},
{
name: "PodFailed with podIPs",
args: args{
obj: &corev1.Pod{
Status: corev1.PodStatus{
PodIPs: []corev1.PodIP{{IP: "1.2.3.4"}, {IP: "aaaa::bbbb"}},
Phase: corev1.PodFailed,
},
},
},
want: nil,
wantErr: false,
},
{
name: "PodRunning with podIPs",
args: args{
obj: &corev1.Pod{
Status: corev1.PodStatus{
PodIPs: []corev1.PodIP{{IP: "1.2.3.4"}, {IP: "aaaa::bbbb"}},
Phase: corev1.PodRunning,
},
},
},
want: []string{"1.2.3.4", "aaaa::bbbb"},
wantErr: false,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got, err := grouping.PodIPsIndexFunc(tt.args.obj)
if (err != nil) != tt.wantErr {
t.Errorf("podIPsIndexFunc() error = %v, wantErr %v", err, tt.wantErr)
return
}
if !reflect.DeepEqual(got, tt.want) {
t.Errorf("podIPsIndexFunc() got = %v, want %v", got, tt.want)
}
})
}
}

0 comments on commit 6363bdb

Please sign in to comment.