diff options
author | Jaime Martinez <jmartinez@gitlab.com> | 2022-02-07 02:24:59 +0300 |
---|---|---|
committer | Jaime Martinez <jmartinez@gitlab.com> | 2022-02-07 02:24:59 +0300 |
commit | f125379b7e8fc6955d1c7cb2d686862e44628bff (patch) | |
tree | 2226c0a799a52694e293ac4ecaefe00b5a3b0109 | |
parent | d4a251ae1bb492fee8af0d3d3619bdd3f5bfc1c0 (diff) | |
parent | f180f94fc467a0151d8e7cd7eb76fc8dcb0b6348 (diff) |
Merge branch 'ci/validate-mocks' into 'master'
ci: add mocks-check task to validate mocks
See merge request gitlab-org/gitlab-pages!672
-rw-r--r-- | .gitlab/ci/test.yml | 5 | ||||
-rw-r--r-- | Makefile.build.mk | 4 | ||||
-rw-r--r-- | Makefile.internal.mk | 4 | ||||
-rw-r--r-- | Makefile.util.mk | 9 |
4 files changed, 20 insertions, 2 deletions
diff --git a/.gitlab/ci/test.yml b/.gitlab/ci/test.yml index d20c144e..e9bca5d6 100644 --- a/.gitlab/ci/test.yml +++ b/.gitlab/ci/test.yml @@ -64,3 +64,8 @@ check deps: - echo skipping script: - make deps-check + +check mocks: + extends: .tests-common + script: + - make mocks-check diff --git a/Makefile.build.mk b/Makefile.build.mk index 6ee9218c..88d74dbf 100644 --- a/Makefile.build.mk +++ b/Makefile.build.mk @@ -19,9 +19,9 @@ setup: .GOPATH/.ok cisetup: .GOPATH/.ok mkdir -p bin/ # Installing dev tools defined in go.tools - awk '/_/ {print $$2}' ./tools/main.go | grep -v -e mockgen -e golangci | xargs -tI % go install ${V:+-v -x} -modfile=tools/go.mod -mod=mod % + awk '/_/ {print $$2}' ./tools/main.go | grep -v -e golangci | xargs -tI % go install ${V:+-v -x} -modfile=tools/go.mod -mod=mod % -generate-mocks: .GOPATH/.ok +generate-mocks: .GOPATH/.ok bin/mockgen $Q bin/mockgen -source=internal/interface.go -destination=internal/handlers/mock/handler_mock.go -package=mock $Q bin/mockgen -source=internal/source/source.go -destination=internal/source/mock/source_mock.go -package=mock $Q bin/mockgen -source=internal/source/gitlab/mock/client_stub.go -destination=internal/source/gitlab/mock/client_mock.go -package=mock diff --git a/Makefile.internal.mk b/Makefile.internal.mk index d2340855..a3e7eb7b 100644 --- a/Makefile.internal.mk +++ b/Makefile.internal.mk @@ -32,3 +32,7 @@ bin/golangci-lint: .GOPATH/.ok bin/gotestsum: .GOPATH/.ok @test -x $@ || \ { echo "Vendored gotestsum not found, try running 'make setup'..."; exit 1; } + +bin/mockgen: .GOPATH/.ok + @test -x $@ || \ + { echo "Vendored mockgen not found, try running 'make setup'..."; exit 1; } diff --git a/Makefile.util.mk b/Makefile.util.mk index 692848c7..e9abe846 100644 --- a/Makefile.util.mk +++ b/Makefile.util.mk @@ -49,6 +49,15 @@ deps-check: .GOPATH/.ok exit 1; \ fi; +mocks-check: .GOPATH/.ok generate-mocks + @if git diff --color=always --exit-code -- *_mock.go; then \ + echo "mocks are ok"; \ + else \ + echo ""; \ + echo "mocks needs to be regenerated, please run 'make generate-mocks' and commit them";\ + exit 1; \ + fi; + deps-download: .GOPATH/.ok go mod download |