Skip to content

Commit

Permalink
Merge pull request #148 from kaleido-io/mocks
Browse files Browse the repository at this point in the history
Use mockery for contractregistry and sarama mocks
  • Loading branch information
awrichar authored Sep 20, 2021
2 parents ebe0585 + ed7256e commit 5e46ec0
Show file tree
Hide file tree
Showing 19 changed files with 1,784 additions and 1,237 deletions.
24 changes: 22 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ BINARY_UNIX=$(BINARY_NAME)-tux
BINARY_MAC=$(BINARY_NAME)-mac
BINARY_WIN=$(BINARY_NAME)-win

GOBIN := $(shell $(VGO) env GOPATH)/bin
MOCKERY := $(GOBIN)/mockery

.DELETE_ON_ERROR:
GOFILES := $(shell find . -name '*.go' -print)

Expand All @@ -23,8 +26,6 @@ coverage.txt: $(GOFILES)
$(VGO) test ./... -cover -coverprofile=coverage.txt -covermode=atomic -timeout 30s
coverage.html:
$(VGO) tool cover -html=coverage.txt
mocks:
mockgen github.com/Shopify/sarama Client,ConsumerGroup,ConsumerGroupSession,ConsumerGroupClaim > internal/kafka/mock_sarama/sarama_mocks.go
test: coverage.txt
coverage: coverage.txt coverage.html
clean: force
Expand All @@ -45,3 +46,22 @@ build-mac:
GOOS=darwin GOARCH=amd64 $(VGO) build -o $(BINARY_MAC) -v
build-win:
GOOS=windows GOARCH=amd64 $(VGO) build -o $(BINARY_WIN) -v

${MOCKERY}:
$(VGO) install github.com/vektra/mockery/cmd/mockery@latest
sarama:
$(eval SARAMA_PATH := $(shell $(VGO) list -f '{{.Dir}}' github.com/Shopify/sarama))

define makemock
mocks: mocks-$(strip $(1))-$(strip $(2))
mocks-$(strip $(1))-$(strip $(2)): ${MOCKERY} sarama
${MOCKERY} --case underscore --dir $(1) --name $(2) --outpkg $(3) --output mocks/$(strip $(3))
endef

$(eval $(call makemock, internal/contractregistry, ContractStore, contractregistrymocks))
$(eval $(call makemock, internal/contractregistry, RemoteRegistry, contractregistrymocks))
$(eval $(call makemock, internal/eth, RPCClient, ethmocks))
$(eval $(call makemock, $$(SARAMA_PATH), Client, saramamocks))
$(eval $(call makemock, $$(SARAMA_PATH), ConsumerGroup, saramamocks))
$(eval $(call makemock, $$(SARAMA_PATH), ConsumerGroupSession, saramamocks))
$(eval $(call makemock, $$(SARAMA_PATH), ConsumerGroupClaim, saramamocks))
1 change: 0 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ require (
github.com/go-openapi/jsonreference v0.19.5
github.com/go-openapi/spec v0.20.3
github.com/go-openapi/swag v0.19.15 // indirect
github.com/golang/mock v1.6.0
github.com/gorilla/websocket v1.4.2
github.com/hashicorp/golang-lru v0.5.5-0.20210104140557-80c98217689d
github.com/icza/dyno v0.0.0-20200205103839-49cb13720835
Expand Down
38 changes: 1 addition & 37 deletions go.sum

Large diffs are not rendered by default.

Loading

0 comments on commit 5e46ec0

Please sign in to comment.