-
Notifications
You must be signed in to change notification settings - Fork 241
/
cacheencoder.go
35 lines (31 loc) · 1.18 KB
/
cacheencoder.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
// Copyright 2018 Microsoft. All rights reserved.
// MIT License
package npm
import (
"encoding/json"
"time"
npmconfig "github.com/Azure/azure-container-networking/npm/config"
dpmocks "github.com/Azure/azure-container-networking/npm/pkg/dataplane/mocks"
k8sversion "k8s.io/apimachinery/pkg/version"
kubeinformers "k8s.io/client-go/informers"
k8sfake "k8s.io/client-go/kubernetes/fake"
fakeexec "k8s.io/utils/exec/testing"
)
// CacheEncoder is used only for unit tests to test encoding and decoding Cache.
func CacheEncoder(nodeName string) json.Marshaler {
noResyncPeriodFunc := func() time.Duration { return 0 }
kubeclient := k8sfake.NewSimpleClientset()
kubeInformer := kubeinformers.NewSharedInformerFactory(kubeclient, noResyncPeriodFunc())
fakeK8sVersion := &k8sversion.Info{
GitVersion: "v1.20.2",
}
exec := &fakeexec.FakeExec{}
npmVersion := "npm-ut-test"
cfg := npmconfig.DefaultConfig
cfg.Toggles.EnableHTTPDebugAPI = true
cfg.Toggles.EnableV2NPM = false
// TODO test v2 NPM debug API when it's implemented
npMgr := NewNetworkPolicyManager(cfg, kubeInformer, &dpmocks.MockGenericDataplane{}, exec, npmVersion, fakeK8sVersion)
npMgr.NodeName = nodeName
return npMgr
}