Skip to content

Commit

Permalink
Add mockgen to build tools
Browse files Browse the repository at this point in the history
Signed-off-by: Andrea Mazzotti <[email protected]>
  • Loading branch information
anmazzotti committed Sep 25, 2024
1 parent 273b7f2 commit b328dc0
Show file tree
Hide file tree
Showing 8 changed files with 23 additions and 18 deletions.
19 changes: 17 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@ KUSTOMIZE_VER := v5.3.0
KUSTOMIZE := $(ABS_TOOLS_DIR)/kustomize-$(KUSTOMIZE_VER)
KUSTOMIZE_PKG := sigs.k8s.io/kustomize/kustomize/v5

MOCKGEN_PKG := go.uber.org/mock/mockgen
MOCKGEN_VER := v0.4.0
MOCKGEN := $(ABS_TOOLS_DIR)/mockgen-$(MOCKGEN_VER)

$(CONTROLLER_GEN):
GOBIN=$(ABS_TOOLS_DIR) $(GO_INSTALL) $(CONTROLLER_GEN_PKG) controller-gen $(CONTROLLER_GEN_VER)

Expand All @@ -70,6 +74,9 @@ $(SETUP_ENVTEST):
$(KUSTOMIZE):
CGO_ENABLED=0 GOBIN=$(ABS_TOOLS_DIR) $(GO_INSTALL) $(KUSTOMIZE_PKG) kustomize $(KUSTOMIZE_VER)

$(MOCKGEN):
GOBIN=$(ABS_TOOLS_DIR) $(GO_INSTALL) $(MOCKGEN_PKG) mockgen $(MOCKGEN_VER)

.PHONY: build
build: operator register support

Expand Down Expand Up @@ -238,12 +245,20 @@ generate-manifests: $(CONTROLLER_GEN) ## Generate manifests for the operator e.g
output:webhook:dir=./config/webhook \
webhook

.PHONY: generate-mocks
generate-mocks: $(MOCKGEN)
$(MOCKGEN) -copyright_file=scripts/boilerplate.go.txt -destination=pkg/register/mocks/client.go -package=mocks github.com/rancher/elemental-operator/pkg/register Client
$(MOCKGEN) -copyright_file=scripts/boilerplate.go.txt -destination=pkg/register/mocks/state.go -package=mocks github.com/rancher/elemental-operator/pkg/register StateHandler
$(MOCKGEN) -copyright_file=scripts/boilerplate.go.txt -destination=pkg/install/mocks/install.go -package=mocks github.com/rancher/elemental-operator/pkg/install Installer
$(MOCKGEN) -copyright_file=scripts/boilerplate.go.txt -destination=pkg/elementalcli/mocks/elementalcli.go -package=mocks github.com/rancher/elemental-operator/pkg/elementalcli Runner
$(MOCKGEN) -copyright_file=scripts/boilerplate.go.txt -destination=pkg/network/mocks/network.go -package=mocks github.com/rancher/elemental-operator/pkg/network Configurator
$(MOCKGEN) -copyright_file=scripts/boilerplate.go.txt -destination=pkg/util/mocks/command_runner.go -package=mocks github.com/rancher/elemental-operator/pkg/util CommandRunner

.PHONY: generate-go
generate-go: $(CONTROLLER_GEN) ## Runs Go related generate targets for the operator
generate-go: generate-mocks $(CONTROLLER_GEN) ## Runs Go related generate targets for the operator
$(CONTROLLER_GEN) \
object:headerFile=$(ROOT)scripts/boilerplate.go.txt \
paths=./api/...
./scripts/generate_mocks.sh

build-crds: $(KUSTOMIZE)
$(KUSTOMIZE) build config/crd > .obs/chartfile/elemental-operator-crds-helm/templates/crds.yaml
Expand Down
2 changes: 1 addition & 1 deletion pkg/elementalcli/mocks/elementalcli.go

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

2 changes: 1 addition & 1 deletion pkg/install/mocks/install.go

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

2 changes: 1 addition & 1 deletion pkg/network/mocks/network.go

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

2 changes: 1 addition & 1 deletion pkg/register/mocks/client.go

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

2 changes: 1 addition & 1 deletion pkg/register/mocks/state.go

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

2 changes: 1 addition & 1 deletion pkg/util/mocks/command_runner.go

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

10 changes: 0 additions & 10 deletions scripts/generate_mocks.sh

This file was deleted.

0 comments on commit b328dc0

Please sign in to comment.