Skip to content

Commit

Permalink
test: Integrate mockery to Makefile
Browse files Browse the repository at this point in the history
Signed-off-by: Enrique Llorente <ellorent@redhat.com>
  • Loading branch information
qinqon authored and jcaamano committed Jul 10, 2024
1 parent 070add5 commit 8a67b3e
Show file tree
Hide file tree
Showing 31 changed files with 675 additions and 156 deletions.
58 changes: 58 additions & 0 deletions go-controller/.mockery.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
dir: pkg/testing/mocks/{{.PackagePath}}
with-expecter: false
filename: "{{.InterfaceName}}.go"
mockname: "{{.InterfaceName}}"
outpkg: "mocks"
packages:
github.com/ovn-org/ovn-kubernetes/go-controller/pkg/factory:
interfaces:
NodeWatchFactory:
ObjectCacheInterface:
config:
dir: pkg/factory/mocks/
github.com/ovn-org/ovn-kubernetes/go-controller/pkg/cni:
interfaces:
CNIPluginLibOps:
NetNS:
config:
dir: pkg/cni/mocks
github.com/ovn-org/ovn-kubernetes/go-controller/pkg/kube:
config:
all: true
dir: pkg/kube/mocks
github.com/ovn-org/ovn-kubernetes/go-controller/pkg/kube/healthcheck:
config:
all: true
dir: pkg/kube/mocks
github.com/ovn-org/ovn-kubernetes/go-controller/pkg/ovn/address_set:
config:
all: true
dir: pkg/ovn/address_set/mocks
github.com/ovn-org/ovn-kubernetes/go-controller/pkg/util:
interfaces:
DNSOps:
ExecRunner:
FileSystemOps:
NetLinkOps:
SriovnetOps:
VdpaDevice:
VdpaOps:
config:
dir: pkg/util/mocks
k8s.io/utils/exec:
config:
all: true
github.com/vishvananda/netlink:
interfaces:
Link:
github.com/containernetworking/cni/pkg/types:
interfaces:
Result:
github.com/containernetworking/plugins/pkg/ns:
interfaces:
NetNS:
github.com/k8snetworkplumbingwg/network-attachment-definition-client/pkg/client/listers/k8s.cni.cncf.io/v1:
interfaces:
NetworkAttachmentDefinitionLister:
NetworkAttachmentDefinitionNamespaceLister:

35 changes: 35 additions & 0 deletions go-controller/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,14 @@ C_ARGS = -e NOROOT=TRUE
else
C_ARGS = --cap-add=NET_ADMIN --cap-add=SYS_ADMIN --privileged
endif

## Tool Binaries
TOOLS_OUTPUT_DIR = ${CURDIR}/${OUT_DIR}
MOCKERY = ${TOOLS_OUTPUT_DIR}/mockery-${MOCKERY_VERSION}

## Tool Versions
MOCKERY_VERSION ?= v2.43.2

export NOROOT

.PHONY: all build check test
Expand Down Expand Up @@ -62,6 +70,10 @@ modelgen: pkg/nbdb/ovn-nb.ovsschema pkg/sbdb/ovn-sb.ovsschema
codegen:
hack/update-codegen.sh

.PHONY: mocksgen
mocksgen: ${MOCKERY}
${MOCKERY}

install:
install -D -m 755 ${OUT_DIR}/go/bin/ovnkube ${BINDIR}/
install -D -m 755 ${OUT_DIR}/go/bin/ovn-kube-util ${BINDIR}/
Expand Down Expand Up @@ -95,3 +107,26 @@ pkg/nbdb/ovn-nb.ovsschema:

pkg/sbdb/ovn-sb.ovsschema:
curl -sSL https://raw.githubusercontent.com/ovn-org/ovn/$(OVN_SCHEMA_VERSION)/ovn-sb.ovsschema -o $@

${TOOLS_OUTPUT_DIR}:
mkdir -p ${TOOLS_OUTPUT_DIR}

.PHONY: mockery
mockery: ${MOCKERY} ## Download mockery locally if necessary.
${MOCKERY}: ${TOOLS_OUTPUT_DIR}
$(call go-install-tool,${MOCKERY},github.com/vektra/mockery/v2,${MOCKERY_VERSION})


# go-install-tool will 'go install' any package with custom target and name of binary, if it doesn't exist
# $1 - target path with name of binary (ideally with version)
# $2 - package url which can be installed
# $3 - specific version of package
define go-install-tool
@[ -f $(1) ] || { \
set -xe; \
package=$(2)@$(3) ;\
echo "Downloading $${package}" ;\
GOBIN=${TOOLS_OUTPUT_DIR} go install $${package} ;\
mv "$$(echo "$(1)" | sed "s/-$(3)$$//")" $(1) ;\
}
endef
26 changes: 18 additions & 8 deletions go-controller/pkg/cni/mocks/CNIPluginLibOps.go

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

Loading

0 comments on commit 8a67b3e

Please sign in to comment.