Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions npm/pkg/dataplane/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
REPO_ROOT = $(shell git rev-parse --show-toplevel)
TOOLS_DIR = $(REPO_ROOT)/build/tools
TOOLS_BIN_DIR = $(REPO_ROOT)/build/tools/bin
MOCKGEN = $(TOOLS_BIN_DIR)/mockgen

.PHONY: generate

generate: $(MOCKGEN) ## Generate mock clients
$(MOCKGEN) -source=$(REPO_ROOT)/npm/pkg/dataplane/types.go -copyright_file=$(REPO_ROOT)/npm/pkg/dataplane/ignore_headers.txt -package=mocks > mocks/genericdataplane_generated.go

$(MOCKGEN):
@make -C $(REPO_ROOT) $(MOCKGEN)
13 changes: 13 additions & 0 deletions npm/pkg/dataplane/dataplane_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ import (

"github.com/Azure/azure-container-networking/npm/metrics"
"github.com/Azure/azure-container-networking/npm/pkg/dataplane/ipsets"
"github.com/Azure/azure-container-networking/npm/pkg/dataplane/mocks"
"github.com/golang/mock/gomock"
"github.com/stretchr/testify/require"
)

func TestNewDataPlane(t *testing.T) {
Expand Down Expand Up @@ -151,3 +154,13 @@ func TestAddToSet(t *testing.T) {
}
}
}

// gomock sample usage for generated mock dataplane
func TestAddToList(t *testing.T) {
ctrl := gomock.NewController(t)
defer ctrl.Finish()

m := mocks.NewMockGenericDataplane(ctrl)
m.EXPECT().AddToList("test", []string{"test"}).Return(nil)
require.NoError(t, m.AddToList("test", []string{"test"}))
}
1 change: 1 addition & 0 deletions npm/pkg/dataplane/ignore_headers.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
autogenerated
222 changes: 222 additions & 0 deletions npm/pkg/dataplane/mocks/genericdataplane_generated.go

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

23 changes: 23 additions & 0 deletions npm/pkg/dataplane/types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package dataplane

import (
"github.com/Azure/azure-container-networking/npm"
"github.com/Azure/azure-container-networking/npm/pkg/dataplane/ipsets"
"github.com/Azure/azure-container-networking/npm/pkg/dataplane/policies"
)

type GenericDataplane interface {
InitializeDataPlane() error
ResetDataPlane() error
CreateIPSet(setName string, setType ipsets.SetType) error
DeleteIPSet(name string) error
AddToSet(setNames []string, ip, podKey string) error
RemoveFromSet(setNames []string, ip, podKey string) error
AddToList(listName string, setNames []string) error
RemoveFromList(listName string, setNames []string) error
UpdatePod(pod *npm.NpmPod) error
ApplyDataPlane() error
AddPolicy(policies *policies.NPMNetworkPolicy) error
RemovePolicy(policyName string) error
UpdatePolicy(policies *policies.NPMNetworkPolicy) error
}