Skip to content

Commit

Permalink
chore: add fake antrea client.
Browse files Browse the repository at this point in the history
Signed-off-by: Asklv <[email protected]>
  • Loading branch information
IRONICBo committed Jun 15, 2024
1 parent 4eae08c commit ec414a1
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 3 deletions.
1 change: 1 addition & 0 deletions hack/update-codegen-dockerized.sh
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ MOCKGEN_TARGETS=(
"pkg/agent/interfacestore InterfaceStore testing"
"pkg/agent/memberlist Interface testing"
"pkg/agent/memberlist Memberlist ."
"pkg/agent/client AntreaClientProvider testing"
"pkg/agent/multicast RouteInterface testing"
"pkg/agent/types McastNetworkPolicyController testing"
"pkg/agent/monitortool PacketListener testing"
Expand Down
69 changes: 69 additions & 0 deletions pkg/agent/client/testing/mock_client.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 5 additions & 3 deletions pkg/agent/monitortool/monitor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,16 @@ import (
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/client-go/informers"
"k8s.io/client-go/kubernetes/fake"
componentbaseconfig "k8s.io/component-base/config"
"k8s.io/utils/clock"
clocktesting "k8s.io/utils/clock/testing"

"antrea.io/antrea/pkg/agent/client"
clienttesting "antrea.io/antrea/pkg/agent/client/testing"
"antrea.io/antrea/pkg/agent/config"
monitortesting "antrea.io/antrea/pkg/agent/monitortool/testing"
"antrea.io/antrea/pkg/agent/util/nettest"
crdv1alpha1 "antrea.io/antrea/pkg/apis/crd/v1alpha1"
fakeversioned "antrea.io/antrea/pkg/client/clientset/versioned/fake"
statsfake "antrea.io/antrea/pkg/client/clientset/versioned/fake"

Check failure on line 45 in pkg/agent/monitortool/monitor_test.go

View workflow job for this annotation

GitHub Actions / Golangci-lint (macos-latest)

duplicated-imports: Package "antrea.io/antrea/pkg/client/clientset/versioned/fake" already imported (revive)

Check failure on line 45 in pkg/agent/monitortool/monitor_test.go

View workflow job for this annotation

GitHub Actions / Golangci-lint (ubuntu-latest)

duplicated-imports: Package "antrea.io/antrea/pkg/client/clientset/versioned/fake" already imported (revive)
crdinformers "antrea.io/antrea/pkg/client/informers/externalversions"
"antrea.io/antrea/pkg/util/ip"
)
Expand Down Expand Up @@ -157,12 +157,14 @@ func newTestMonitor(
) *testMonitor {
ctrl := gomock.NewController(t)
clientset := fake.NewSimpleClientset(objects...)
statsClientset := statsfake.NewSimpleClientset(objects...)
informerFactory := informers.NewSharedInformerFactory(clientset, 0)
nodeInformer := informerFactory.Core().V1().Nodes()
crdClientset := fakeversioned.NewSimpleClientset(crdObjects...)
crdInformerFactory := crdinformers.NewSharedInformerFactory(crdClientset, 0)
nlmInformer := crdInformerFactory.Crd().V1alpha1().NodeLatencyMonitors()
antreaClientProvider, _ := client.NewAntreaClientProvider(componentbaseconfig.ClientConnectionConfiguration{}, clientset)
antreaClientProvider := clienttesting.NewMockAntreaClientProvider(ctrl)
antreaClientProvider.EXPECT().GetAntreaClient().Return(statsClientset, nil).AnyTimes()
m := NewNodeLatencyMonitor(antreaClientProvider, nodeInformer, nlmInformer, nodeConfig, trafficEncapMode)
fakeClock := newFakeClock(clockT)
m.clock = fakeClock
Expand Down

0 comments on commit ec414a1

Please sign in to comment.