diff --git a/.github/copilot-instructions.md b/.github/copilot-instructions.md index 9b5dfa8be..5a4dbbb1a 100644 --- a/.github/copilot-instructions.md +++ b/.github/copilot-instructions.md @@ -40,7 +40,8 @@ The project is structured as a monorepo to manage the backend, frontend, and sam - tests/: Common unit tests related files. - mocks/: Generated mocks for unit tests. - resources/: Test resource files. - - .mockery.yml: Mockery configurations related to mock generation. + - .mockery.private.yml: Mockery configurations for private interfaces. + - .mockery.public.yml: Mockery configurations for public interfaces. - frontend/: Individual frontend application code. - apps/gate/: Gate app implementation which serves UIs for login, registration and recovery. - packages/: Common frontend packages such as UI components, services, and contexts. @@ -113,7 +114,7 @@ The project is structured as a monorepo to manage the backend, frontend, and sam #### Unit Tests - Ensure unit tests are written to achieve at least 80% coverage. - Use `stretchr/testify` for tests and follow the test suite pattern. -- `mockery` is used to generate mocks; configurations are in `/backend/.mockery.yml`. +- `mockery` is used to generate mocks; configurations for private and public interfaces are in `.mockery.private.yml` and `.mockery.public.yml` respectively. Mocks can be generated using `make mockery` command from the project root directory. - Place generated mocks in the `/backend/tests/mocks/` directory. - Unit tests can be run using `make test_unit` command from the project root directory. Alternatively `go test` command can also be used from the `/backend` directory with applicable flags. diff --git a/Makefile b/Makefile index 637c138c0..ac62be278 100644 --- a/Makefile +++ b/Makefile @@ -26,7 +26,11 @@ PROJECT_DIR := $(realpath $(dir $(abspath $(lastword $(MAKEFILE_LIST)))))/backen PROJECT_BIN_DIR := $(PROJECT_DIR)/bin TOOL_BIN ?= $(PROJECT_BIN_DIR)/tools GOLANGCI_LINT ?= $(TOOL_BIN)/golangci-lint +MOCKERY ?= $(TOOL_BIN)/mockery + +# Tools versions GOLANGCI_LINT_VERSION ?= v1.64.8 +MOCKERY_VERSION ?= v3.5.5 $(TOOL_BIN): mkdir -p $(TOOL_BIN) @@ -95,6 +99,10 @@ docker-build-multiarch-push: lint: golangci-lint cd backend && $(GOLANGCI_LINT) run ./... +mockery: install-mockery + cd backend && $(MOCKERY) --config .mockery.public.yml + cd backend && $(MOCKERY) --config .mockery.private.yml + help: @echo "Makefile targets:" @echo " all - Clean, build, and test the project." @@ -116,13 +124,15 @@ help: @echo " docker-build-multiarch-latest - Build multi-arch Docker image with latest tag." @echo " docker-build-multiarch-push - Build and push multi-arch images to registry." @echo " lint - Run golangci-lint on the project." + @echo " mockery - Generate mocks for unit tests using mockery." @echo " help - Show this help message." .PHONY: all prepare clean clean_all build build_samples package_samples run .PHONY: docker-build docker-build-latest docker-build-multiarch .PHONY: docker-build-multiarch-latest docker-build-multiarch-push .PHONY: test_unit test_integration build_with_coverage test -.PHONY: lint help go_install_tool golangci-lint +.PHONY: help go_install_tool +.PHONY: lint golangci-lint mockery install-mockery define go_install_tool cd /tmp && \ @@ -133,3 +143,8 @@ golangci-lint: $(GOLANGCI_LINT) $(GOLANGCI_LINT): $(TOOL_BIN) $(call go_install_tool,$(GOLANGCI_LINT),github.com/golangci/golangci-lint/cmd/golangci-lint,$(GOLANGCI_LINT_VERSION)) + +install-mockery: $(MOCKERY) + +$(MOCKERY): $(TOOL_BIN) + $(call go_install_tool,$(MOCKERY),github.com/vektra/mockery/v3,$(MOCKERY_VERSION)) diff --git a/backend/.mockery.private.yml b/backend/.mockery.private.yml new file mode 100644 index 000000000..c61bf1a57 --- /dev/null +++ b/backend/.mockery.private.yml @@ -0,0 +1,30 @@ +# ------------------------------------------------------------------------------ +# Copyright (c) 2025, WSO2 LLC. (https://www.wso2.com). +# +# WSO2 LLC. licenses this file to you under the Apache License, +# Version 2.0 (the "License"); you may not use this file except +# in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# ------------------------------------------------------------------------------ + +# Mockery configuration file for generating private mocks within the package +template: testify +template-data: + unroll-variadic: true +packages: + github.com/asgardeo/thunder/internal/system/cache: + config: + all: true + dir: internal/system/cache + structname: '{{.InterfaceName}}Mock' + pkgname: cache + filename: "{{.InterfaceName}}_mock_test.go" diff --git a/backend/.mockery.yml b/backend/.mockery.public.yml similarity index 96% rename from backend/.mockery.yml rename to backend/.mockery.public.yml index 615bc3539..fbdfd19c5 100644 --- a/backend/.mockery.yml +++ b/backend/.mockery.public.yml @@ -16,6 +16,7 @@ # under the License. # ------------------------------------------------------------------------------ +# Mockery configuration file for generating public mocks template: testify template-data: unroll-variadic: true @@ -59,15 +60,6 @@ packages: structname: '{{.InterfaceName}}Mock' pkgname: providermock filename: "{{.InterfaceName}}_mock.go" - - # Uncomment to generate mocks in the cache package. - # github.com/asgardeo/thunder/internal/system/cache: - # config: - # all: true - # dir: internal/system/cache - # structname: '{{.InterfaceName}}Mock' - # pkgname: cache - # filename: "{{.InterfaceName}}_mock_test.go" github.com/asgardeo/thunder/internal/system/cache: config: