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 1f69704
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions pkg/agent/monitortool/monitor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,14 @@ 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"
"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"
"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/util/ip"
Expand Down Expand Up @@ -136,6 +135,14 @@ func (c *fakeClock) NewTicker(d time.Duration) clock.Ticker {
return c.FakeClock.NewTicker(d)
}

type antreaClientGetter struct {
clientset versioned.Interface
}

func (g *antreaClientGetter) GetAntreaClient() (versioned.Interface, error) {
return g.clientset, nil
}

type testMonitor struct {
*NodeLatencyMonitor
clientset *fake.Clientset
Expand All @@ -162,7 +169,7 @@ func newTestMonitor(
crdClientset := fakeversioned.NewSimpleClientset(crdObjects...)
crdInformerFactory := crdinformers.NewSharedInformerFactory(crdClientset, 0)
nlmInformer := crdInformerFactory.Crd().V1alpha1().NodeLatencyMonitors()
antreaClientProvider, _ := client.NewAntreaClientProvider(componentbaseconfig.ClientConnectionConfiguration{}, clientset)
antreaClientProvider := &antreaClientGetter{fakeversioned.NewSimpleClientset(crdObjects...)}
m := NewNodeLatencyMonitor(antreaClientProvider, nodeInformer, nlmInformer, nodeConfig, trafficEncapMode)
fakeClock := newFakeClock(clockT)
m.clock = fakeClock
Expand Down

0 comments on commit 1f69704

Please sign in to comment.