Skip to content

Commit 64df11b

Browse files
authored
feat: bump mockery and switch to generate by config file (goharbor#20742)
The packages feature in mockery is the new way for managing mocks, and will be the only way to generate mocks in v3. see https://vektra.github.io/mockery/v2.43/migrating_to_packages/. 1. Bump mockery to v2.43.2. 2. Switch the generation from old way to configuration yaml. Signed-off-by: chlins <chlins.zhang@gmail.com>
1 parent 753c765 commit 64df11b

File tree

117 files changed

+635
-357
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

117 files changed

+635
-357
lines changed

CONTRIBUTING.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ To build the code, please refer to [build](https://goharbor.io/docs/edge/build-c
276276

277277
**Note**: from v2.0, Harbor uses [go-swagger](https://github.com/go-swagger/go-swagger) to generate API server from Swagger 2.0 (aka [OpenAPI 2.0](https://github.com/OAI/OpenAPI-Specification/blob/master/versions/2.0.md)). To add or change the APIs, first update the `api/v2.0/swagger.yaml` file, then run `make gen_apis` to generate the API server, finally, implement or update the API handlers in `src/server/v2.0/handler` package.
278278

279-
As now Harbor uses `controller/manager/dao` programming model, we suggest to use [testify mock](https://github.com/stretchr/testify/blob/master/mock/doc.go) to test `controller` and `manager`. Harbor integrates [mockery](https://github.com/vektra/mockery) to generate mocks for golang interfaces using the testify mock package. To generate mocks for the interface, first add `//go:generate mockery xxx` comment with mockery command in the subpackages of `src/testing`, then run `make gen_mocks` to generate mocks.
279+
As now Harbor uses `controller/manager/dao` programming model, we suggest to use [testify mock](https://github.com/stretchr/testify/blob/master/mock/doc.go) to test `controller` and `manager`. Harbor integrates [mockery](https://github.com/vektra/mockery) to generate mocks for golang interfaces using the testify mock package. To generate mocks for the interface, first add mock config in the `src/.mockery.yaml`, then run `make gen_mocks` to generate mocks.
280280

281281
### Keep sync with upstream
282282

Makefile

+3-3
Original file line numberDiff line numberDiff line change
@@ -312,13 +312,13 @@ gen_apis: lint_apis
312312

313313

314314
MOCKERY_IMAGENAME=$(IMAGENAMESPACE)/mockery
315-
MOCKERY_VERSION=v2.42.2
316-
MOCKERY=$(RUNCONTAINER) ${MOCKERY_IMAGENAME}:${MOCKERY_VERSION}
315+
MOCKERY_VERSION=v2.43.2
316+
MOCKERY=$(RUNCONTAINER)/src ${MOCKERY_IMAGENAME}:${MOCKERY_VERSION}
317317
MOCKERY_IMAGE_BUILD_CMD=${DOCKERBUILD} -f ${TOOLSPATH}/mockery/Dockerfile --build-arg GOLANG=${GOBUILDIMAGE} --build-arg MOCKERY_VERSION=${MOCKERY_VERSION} -t ${MOCKERY_IMAGENAME}:$(MOCKERY_VERSION) .
318318

319319
gen_mocks:
320320
$(call prepare_docker_image,${MOCKERY_IMAGENAME},${MOCKERY_VERSION},${MOCKERY_IMAGE_BUILD_CMD})
321-
${MOCKERY} go generate ./...
321+
${MOCKERY} mockery
322322

323323
mocks_check: gen_mocks
324324
@echo checking mocks...

0 commit comments

Comments
 (0)