From 6363bdbfc55d19789c05cf4a5e13ec96e18e1a0d Mon Sep 17 00:00:00 2001 From: shi0rik0 Date: Thu, 10 Aug 2023 14:41:31 +0800 Subject: [PATCH] Move TestPodIPsIndexFunc to package controller/grouping (#5379) Move TestPodIPsIndexFunc from package controller/traceflow to controller/grouping, because PodIPsIndexFunc is in package controller/grouping. Signed-off-by: shi0rik0 --- pkg/controller/grouping/controller_test.go | 70 ++++++++++++++++++++ pkg/controller/traceflow/controller_test.go | 71 --------------------- 2 files changed, 70 insertions(+), 71 deletions(-) diff --git a/pkg/controller/grouping/controller_test.go b/pkg/controller/grouping/controller_test.go index 37e969922d1..9fcc7f9e294 100644 --- a/pkg/controller/grouping/controller_test.go +++ b/pkg/controller/grouping/controller_test.go @@ -15,6 +15,7 @@ package grouping import ( + "reflect" "testing" "time" @@ -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) + } + }) + } +} diff --git a/pkg/controller/traceflow/controller_test.go b/pkg/controller/traceflow/controller_test.go index c169f14279a..623eab9a6bd 100644 --- a/pkg/controller/traceflow/controller_test.go +++ b/pkg/controller/traceflow/controller_test.go @@ -16,7 +16,6 @@ package traceflow import ( "context" - "reflect" "testing" "time" @@ -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 } @@ -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) - } - }) - } -}