Skip to content

Commit

Permalink
Use mockery for generating mock interfaces (#37)
Browse files Browse the repository at this point in the history
  • Loading branch information
nhatthm authored Sep 15, 2024
1 parent 2690a2e commit c216d33
Show file tree
Hide file tree
Showing 13 changed files with 1,151 additions and 269 deletions.
15 changes: 5 additions & 10 deletions .golangci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,31 +20,25 @@ linters-settings:
linters:
enable-all: true
disable:
- deadcode
- copyloopvar
- depguard
- exhaustivestruct
- execinquery
- exhaustruct
- exportloopref
- forbidigo
- forcetypeassert
- gci
- gochecknoglobals
- golint
- gomnd
- ifshort
- interfacer
- intrange
- ireturn
- lll
- maligned
- nonamedreturns
- nosnakecase
- nolintlint # https://github.com/golangci/golangci-lint/issues/3063
- paralleltest
- scopelint
- structcheck
- tagliatelle
- testifylint
- testpackage
- varcheck
- varnamelen
- wrapcheck

Expand All @@ -54,6 +48,7 @@ issues:
exclude-rules:
- linters:
- dupl
- err113
- funlen
- goconst
- goerr113
Expand Down
14 changes: 14 additions & 0 deletions .mockery.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
dry-run: false
with-expecter: false
mockname: "{{.InterfaceName}}"
filename: "{{ .InterfaceName | snakecase }}.go"
dir: "."
outpkg: aferomock
packages:
github.com/spf13/afero:
config:
include-regex: "Fs|File"

io/fs:
config:
include-regex: "FileInfo"
21 changes: 20 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,34 @@ MODULE_NAME=aferomock
BIN_DIR = bin
VENDOR_DIR = vendor

GOLANGCI_LINT_VERSION ?= v1.55.2
GOLANGCI_LINT_VERSION ?= v1.61.0
MOCKERY_VERSION ?= v2.45.0

GO ?= go
GOLANGCI_LINT ?= $(shell go env GOPATH)/bin/golangci-lint-$(GOLANGCI_LINT_VERSION)
MOCKERY ?= $(shell go env GOPATH)/bin/mockery-$(MOCKERY_VERSION)

.PHONY: $(VENDOR_DIR)
$(VENDOR_DIR):
@mkdir -p $(VENDOR_DIR)
@$(GO) mod vendor

.PHONY: generate
generate: $(MOCKERY)
@$(MOCKERY)

.PHONY: lint
lint: $(GOLANGCI_LINT) $(VENDOR_DIR)
@$(GOLANGCI_LINT) run -c .golangci.yaml

.PHONY: update
update: $(VENDOR_DIR)
@$(GO) get -u ./...

.PHONY: tidy
tidy: $(VENDOR_DIR)
@$(GO) mod tidy

.PHONY: test
test: test-unit

Expand All @@ -35,3 +49,8 @@ $(GOLANGCI_LINT):
@echo "$(OK_COLOR)==> Installing golangci-lint $(GOLANGCI_LINT_VERSION)$(NO_COLOR)"; \
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b ./bin "$(GOLANGCI_LINT_VERSION)"
@mv ./bin/golangci-lint $(GOLANGCI_LINT)

$(MOCKERY):
@echo "$(OK_COLOR)==> Installing mockery $(MOCKERY_VERSION)$(NO_COLOR)"; \
GOBIN=/tmp $(GO) install github.com/vektra/mockery/$(shell echo "$(MOCKERY_VERSION)" | cut -d '.' -f 1)@$(MOCKERY_VERSION)
@mv /tmp/mockery $(MOCKERY)
Loading

0 comments on commit c216d33

Please sign in to comment.