From 44aa552b09575f5de1cb91ad81dc2bfa4f2507d9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dominik=20V=C3=A1gner?= <55958556+dominikvagner@users.noreply.github.com> Date: Tue, 22 Oct 2024 17:45:58 +0200 Subject: [PATCH] Fixes 4552: fix missing method bug with mock gen (#856) * Fixes 4552: fix missing method bug with mock gen * fix: mockery path, script for mockery comment fix --- .mockery.yaml | 62 +++++++++++++++++++ mk/mockery.mk | 4 +- pkg/cache/cache.go | 1 - pkg/cache/cache_mock.go | 2 +- pkg/candlepin_client/candlepin_client_mock.go | 2 +- pkg/candlepin_client/interface.go | 1 - pkg/dao/admin_tasks_mock.go | 2 +- pkg/dao/domain_dao_mock.go | 2 +- pkg/dao/environments_mock.go | 2 +- pkg/dao/interfaces.go | 11 ---- pkg/dao/metrics_mock.go | 2 +- pkg/dao/package_groups_mock.go | 2 +- pkg/dao/repositories_mock.go | 2 +- pkg/dao/repository_configs_mock.go | 2 +- pkg/dao/rpms_mock.go | 2 +- pkg/dao/snapshots_mock.go | 2 +- pkg/dao/task_info_mock.go | 2 +- pkg/dao/templates_mock.go | 2 +- pkg/pulp_client/interfaces.go | 2 - pkg/pulp_client/pulp_client_mock.go | 2 +- pkg/pulp_client/pulp_global_client_mock.go | 2 +- pkg/tasks/client/client.go | 1 - pkg/tasks/client/client_mock.go | 2 +- pkg/tasks/queue/queue.go | 1 - pkg/tasks/queue/queue_mock.go | 2 +- scripts/mockery_comment_fix.sh | 29 +++++++++ 26 files changed, 111 insertions(+), 35 deletions(-) create mode 100644 .mockery.yaml create mode 100755 scripts/mockery_comment_fix.sh diff --git a/.mockery.yaml b/.mockery.yaml new file mode 100644 index 000000000..76888c1cc --- /dev/null +++ b/.mockery.yaml @@ -0,0 +1,62 @@ +filename: "{{ .InterfaceName | snakecase }}_mock.go" +dir: "{{.InterfaceDir}}" +mockname: "Mock{{.InterfaceName}}" +outpkg: "{{.PackageName}}" +inpackage: True +with-expecter: False +disable-version-string: True + +packages: + github.com/content-services/content-sources-backend/pkg/tasks/queue: + interfaces: + Queue: + github.com/content-services/content-sources-backend/pkg/tasks/client: + interfaces: + TaskClient: + config: + filename: "client_mock.go" + github.com/content-services/content-sources-backend/pkg/pulp_client: + interfaces: + PulpGlobalClient: + PulpClient: + github.com/content-services/content-sources-backend/pkg/candlepin_client: + interfaces: + CandlepinClient: + github.com/content-services/content-sources-backend/pkg/cache: + interfaces: + Cache: + github.com/content-services/content-sources-backend/pkg/dao: + interfaces: + RepositoryConfigDao: + config: + filename: "repository_configs_mock.go" + RpmDao: + config: + filename: "rpms_mock.go" + RepositoryDao: + config: + filename: "repositories_mock.go" + SnapshotDao: + config: + filename: "snapshots_mock.go" + MetricsDao: + config: + filename: "metrics_mock.go" + TaskInfoDao: + config: + filename: "task_info_mock.go" + AdminTaskDao: + config: + filename: "admin_tasks_mock.go" + DomainDao: + config: + filename: "domain_dao_mock.go" + PackageGroupDao: + config: + filename: "package_groups_mock.go" + EnvironmentDao: + config: + filename: "environments_mock.go" + TemplateDao: + config: + filename: "templates_mock.go" diff --git a/mk/mockery.mk b/mk/mockery.mk index 2906da3d5..65f47ac93 100644 --- a/mk/mockery.mk +++ b/mk/mockery.mk @@ -8,4 +8,6 @@ $(GO_OUTPUT)/mockery: ## Install mockery locally on your GO_OUTPUT (./release) d .PHONY: mock mock: $(GO_OUTPUT)/mockery ## Install mockery if it isn't already in ./release directory and regenerate mocks - go generate ./... \ No newline at end of file + ./scripts/mockery_comment_fix.sh comment + $(GO_OUTPUT)/mockery + ./scripts/mockery_comment_fix.sh uncomment diff --git a/pkg/cache/cache.go b/pkg/cache/cache.go index 23e366cb8..6ae17e7bf 100644 --- a/pkg/cache/cache.go +++ b/pkg/cache/cache.go @@ -13,7 +13,6 @@ import ( var NotFound = errors.New("not found in cache") -//go:generate $GO_OUTPUT/mockery --name Cache --filename cache_mock.go --inpackage type Cache interface { GetAccessList(ctx context.Context) (rbac.AccessList, error) SetAccessList(ctx context.Context, accessList rbac.AccessList) error diff --git a/pkg/cache/cache_mock.go b/pkg/cache/cache_mock.go index 022bb3e6e..270e9403f 100644 --- a/pkg/cache/cache_mock.go +++ b/pkg/cache/cache_mock.go @@ -1,4 +1,4 @@ -// Code generated by mockery v2.46.2. DO NOT EDIT. +// Code generated by mockery. DO NOT EDIT. package cache diff --git a/pkg/candlepin_client/candlepin_client_mock.go b/pkg/candlepin_client/candlepin_client_mock.go index d0d71f571..0fdc0a0ee 100644 --- a/pkg/candlepin_client/candlepin_client_mock.go +++ b/pkg/candlepin_client/candlepin_client_mock.go @@ -1,4 +1,4 @@ -// Code generated by mockery v2.46.2. DO NOT EDIT. +// Code generated by mockery. DO NOT EDIT. package candlepin_client diff --git a/pkg/candlepin_client/interface.go b/pkg/candlepin_client/interface.go index 5203678b5..d1c9d23cb 100644 --- a/pkg/candlepin_client/interface.go +++ b/pkg/candlepin_client/interface.go @@ -6,7 +6,6 @@ import ( caliri "github.com/content-services/caliri/release/v4" ) -//go:generate $GO_OUTPUT/mockery --name CandlepinClient --filename candlepin_client_mock.go --inpackage type CandlepinClient interface { CreateOwner(ctx context.Context) error ImportManifest(ctx context.Context, filename string) error diff --git a/pkg/dao/admin_tasks_mock.go b/pkg/dao/admin_tasks_mock.go index 4a89c1b6d..5e22bbc37 100644 --- a/pkg/dao/admin_tasks_mock.go +++ b/pkg/dao/admin_tasks_mock.go @@ -1,4 +1,4 @@ -// Code generated by mockery v2.46.2. DO NOT EDIT. +// Code generated by mockery. DO NOT EDIT. package dao diff --git a/pkg/dao/domain_dao_mock.go b/pkg/dao/domain_dao_mock.go index 80ba75304..2493fcab7 100644 --- a/pkg/dao/domain_dao_mock.go +++ b/pkg/dao/domain_dao_mock.go @@ -1,4 +1,4 @@ -// Code generated by mockery v2.46.2. DO NOT EDIT. +// Code generated by mockery. DO NOT EDIT. package dao diff --git a/pkg/dao/environments_mock.go b/pkg/dao/environments_mock.go index 125ab4ad9..6f1d1b7ef 100644 --- a/pkg/dao/environments_mock.go +++ b/pkg/dao/environments_mock.go @@ -1,4 +1,4 @@ -// Code generated by mockery v2.46.2. DO NOT EDIT. +// Code generated by mockery. DO NOT EDIT. package dao diff --git a/pkg/dao/interfaces.go b/pkg/dao/interfaces.go index c6fc92a46..181538e7a 100644 --- a/pkg/dao/interfaces.go +++ b/pkg/dao/interfaces.go @@ -62,7 +62,6 @@ func SetupGormTableOrFail(db *gorm.DB) { } } -//go:generate $GO_OUTPUT/mockery --name RepositoryConfigDao --filename repository_configs_mock.go --inpackage type RepositoryConfigDao interface { Create(ctx context.Context, newRepo api.RepositoryRequest) (api.RepositoryResponse, error) BulkCreate(ctx context.Context, newRepositories []api.RepositoryRequest) ([]api.RepositoryResponse, []error) @@ -84,7 +83,6 @@ type RepositoryConfigDao interface { BulkImport(ctx context.Context, reposToImport []api.RepositoryRequest) ([]api.RepositoryImportResponse, []error) } -//go:generate $GO_OUTPUT/mockery --name RpmDao --filename rpms_mock.go --inpackage type RpmDao interface { List(ctx context.Context, orgID string, uuidRepo string, limit int, offset int, search string, sortBy string) (api.RepositoryRpmCollectionResponse, int64, error) Search(ctx context.Context, orgID string, request api.ContentUnitSearchRequest) ([]api.SearchRpmResponse, error) @@ -98,7 +96,6 @@ type RpmDao interface { ListTemplateErrata(ctx context.Context, orgId string, templateUUID string, filters tangy.ErrataListFilters, pageOpts api.PaginationData) ([]api.SnapshotErrata, int, error) } -//go:generate $GO_OUTPUT/mockery --name RepositoryDao --filename repositories_mock.go --inpackage type RepositoryDao interface { FetchForUrl(ctx context.Context, url string) (Repository, error) ListForIntrospection(ctx context.Context, urls *[]string, force bool) ([]Repository, error) @@ -108,7 +105,6 @@ type RepositoryDao interface { OrphanCleanup(ctx context.Context) error } -//go:generate $GO_OUTPUT/mockery --name SnapshotDao --filename snapshots_mock.go --inpackage type SnapshotDao interface { Create(ctx context.Context, snap *models.Snapshot) error List(ctx context.Context, orgID string, repoConfigUuid string, paginationData api.PaginationData, filterData api.FilterData) (api.SnapshotCollectionResponse, int64, error) @@ -124,7 +120,6 @@ type SnapshotDao interface { FetchSnapshotsModelByDateAndRepository(ctx context.Context, orgID string, request api.ListSnapshotByDateRequest) ([]models.Snapshot, error) } -//go:generate $GO_OUTPUT/mockery --name MetricsDao --filename metrics_mock.go --inpackage type MetricsDao interface { RepositoriesCount(ctx context.Context) int RepositoryConfigsCount(ctx context.Context) int @@ -137,7 +132,6 @@ type MetricsDao interface { RHReposSnapshotNotCompletedInLast36HoursCount(ctx context.Context) int64 } -//go:generate $GO_OUTPUT/mockery --name TaskInfoDao --filename task_info_mock.go --inpackage type TaskInfoDao interface { Fetch(ctx context.Context, OrgID string, id string) (api.TaskInfoResponse, error) List(ctx context.Context, OrgID string, pageData api.PaginationData, filterData api.TaskInfoFilterData) (api.TaskInfoCollectionResponse, int64, error) @@ -145,19 +139,16 @@ type TaskInfoDao interface { Cleanup(ctx context.Context) error } -//go:generate $GO_OUTPUT/mockery --name AdminTaskDao --filename admin_tasks_mock.go --inpackage type AdminTaskDao interface { Fetch(ctx context.Context, id string) (api.AdminTaskInfoResponse, error) List(ctx context.Context, pageData api.PaginationData, filterData api.AdminTaskFilterData) (api.AdminTaskInfoCollectionResponse, int64, error) } -//go:generate $GO_OUTPUT/mockery --name DomainDao --filename domain_dao_mock.go --inpackage type DomainDao interface { FetchOrCreateDomain(ctx context.Context, orgId string) (string, error) Fetch(ctx context.Context, orgId string) (string, error) } -//go:generate $GO_OUTPUT/mockery --name PackageGroupDao --filename package_groups_mock.go --inpackage type PackageGroupDao interface { List(ctx context.Context, orgID string, uuidRepo string, limit int, offset int, search string, sortBy string) (api.RepositoryPackageGroupCollectionResponse, int64, error) Search(ctx context.Context, orgID string, request api.ContentUnitSearchRequest) ([]api.SearchPackageGroupResponse, error) @@ -166,7 +157,6 @@ type PackageGroupDao interface { SearchSnapshotPackageGroups(ctx context.Context, orgId string, request api.SnapshotSearchRpmRequest) ([]api.SearchPackageGroupResponse, error) } -//go:generate $GO_OUTPUT/mockery --name EnvironmentDao --filename environments_mock.go --inpackage type EnvironmentDao interface { List(ctx context.Context, orgID string, uuidRepo string, limit int, offset int, search string, sortBy string) (api.RepositoryEnvironmentCollectionResponse, int64, error) Search(ctx context.Context, orgID string, request api.ContentUnitSearchRequest) ([]api.SearchEnvironmentResponse, error) @@ -175,7 +165,6 @@ type EnvironmentDao interface { SearchSnapshotEnvironments(ctx context.Context, orgId string, request api.SnapshotSearchRpmRequest) ([]api.SearchEnvironmentResponse, error) } -//go:generate $GO_OUTPUT/mockery --name TemplateDao --filename templates_mock.go --inpackage type TemplateDao interface { Create(ctx context.Context, templateRequest api.TemplateRequest) (api.TemplateResponse, error) Fetch(ctx context.Context, orgID string, uuid string, includeSoftDel bool) (api.TemplateResponse, error) diff --git a/pkg/dao/metrics_mock.go b/pkg/dao/metrics_mock.go index f453a4908..ec5699bff 100644 --- a/pkg/dao/metrics_mock.go +++ b/pkg/dao/metrics_mock.go @@ -1,4 +1,4 @@ -// Code generated by mockery v2.46.2. DO NOT EDIT. +// Code generated by mockery. DO NOT EDIT. package dao diff --git a/pkg/dao/package_groups_mock.go b/pkg/dao/package_groups_mock.go index 627c041d3..f25d40277 100644 --- a/pkg/dao/package_groups_mock.go +++ b/pkg/dao/package_groups_mock.go @@ -1,4 +1,4 @@ -// Code generated by mockery v2.46.2. DO NOT EDIT. +// Code generated by mockery. DO NOT EDIT. package dao diff --git a/pkg/dao/repositories_mock.go b/pkg/dao/repositories_mock.go index fe88ff94b..4c77edd72 100644 --- a/pkg/dao/repositories_mock.go +++ b/pkg/dao/repositories_mock.go @@ -1,4 +1,4 @@ -// Code generated by mockery v2.46.2. DO NOT EDIT. +// Code generated by mockery. DO NOT EDIT. package dao diff --git a/pkg/dao/repository_configs_mock.go b/pkg/dao/repository_configs_mock.go index 4752c2cd1..3e84e7136 100644 --- a/pkg/dao/repository_configs_mock.go +++ b/pkg/dao/repository_configs_mock.go @@ -1,4 +1,4 @@ -// Code generated by mockery v2.46.2. DO NOT EDIT. +// Code generated by mockery. DO NOT EDIT. package dao diff --git a/pkg/dao/rpms_mock.go b/pkg/dao/rpms_mock.go index 1be780c4e..d33d00952 100644 --- a/pkg/dao/rpms_mock.go +++ b/pkg/dao/rpms_mock.go @@ -1,4 +1,4 @@ -// Code generated by mockery v2.46.2. DO NOT EDIT. +// Code generated by mockery. DO NOT EDIT. package dao diff --git a/pkg/dao/snapshots_mock.go b/pkg/dao/snapshots_mock.go index b2f2a5b09..13721c2b7 100644 --- a/pkg/dao/snapshots_mock.go +++ b/pkg/dao/snapshots_mock.go @@ -1,4 +1,4 @@ -// Code generated by mockery v2.46.2. DO NOT EDIT. +// Code generated by mockery. DO NOT EDIT. package dao diff --git a/pkg/dao/task_info_mock.go b/pkg/dao/task_info_mock.go index 8383dd99b..05ff55d6d 100644 --- a/pkg/dao/task_info_mock.go +++ b/pkg/dao/task_info_mock.go @@ -1,4 +1,4 @@ -// Code generated by mockery v2.46.2. DO NOT EDIT. +// Code generated by mockery. DO NOT EDIT. package dao diff --git a/pkg/dao/templates_mock.go b/pkg/dao/templates_mock.go index e1451d271..05a76030d 100644 --- a/pkg/dao/templates_mock.go +++ b/pkg/dao/templates_mock.go @@ -1,4 +1,4 @@ -// Code generated by mockery v2.46.2. DO NOT EDIT. +// Code generated by mockery. DO NOT EDIT. package dao diff --git a/pkg/pulp_client/interfaces.go b/pkg/pulp_client/interfaces.go index 87db2697c..0b5019c87 100644 --- a/pkg/pulp_client/interfaces.go +++ b/pkg/pulp_client/interfaces.go @@ -7,7 +7,6 @@ import ( zest "github.com/content-services/zest/release/v2024" ) -//go:generate $GO_OUTPUT/mockery --name PulpGlobalClient --filename pulp_global_client_mock.go --inpackage type PulpGlobalClient interface { // Domains LookupOrCreateDomain(ctx context.Context, name string) (string, error) @@ -21,7 +20,6 @@ type PulpGlobalClient interface { GetContentPath(ctx context.Context) (string, error) } -//go:generate $GO_OUTPUT/mockery --name PulpClient --filename pulp_client_mock.go --inpackage type PulpClient interface { // Artifacts LookupArtifact(ctx context.Context, sha256sum string) (*string, error) diff --git a/pkg/pulp_client/pulp_client_mock.go b/pkg/pulp_client/pulp_client_mock.go index 93ad49ac5..120261348 100644 --- a/pkg/pulp_client/pulp_client_mock.go +++ b/pkg/pulp_client/pulp_client_mock.go @@ -1,4 +1,4 @@ -// Code generated by mockery v2.46.2. DO NOT EDIT. +// Code generated by mockery. DO NOT EDIT. package pulp_client diff --git a/pkg/pulp_client/pulp_global_client_mock.go b/pkg/pulp_client/pulp_global_client_mock.go index ce87456b6..1b5859310 100644 --- a/pkg/pulp_client/pulp_global_client_mock.go +++ b/pkg/pulp_client/pulp_global_client_mock.go @@ -1,4 +1,4 @@ -// Code generated by mockery v2.46.2. DO NOT EDIT. +// Code generated by mockery. DO NOT EDIT. package pulp_client diff --git a/pkg/tasks/client/client.go b/pkg/tasks/client/client.go index c250cc883..6792256b9 100644 --- a/pkg/tasks/client/client.go +++ b/pkg/tasks/client/client.go @@ -10,7 +10,6 @@ import ( "github.com/google/uuid" ) -//go:generate $GO_OUTPUT/mockery --name TaskClient --filename client_mock.go --inpackage type TaskClient interface { Enqueue(task queue.Task) (uuid.UUID, error) Cancel(ctx context.Context, taskId string) error diff --git a/pkg/tasks/client/client_mock.go b/pkg/tasks/client/client_mock.go index 37bc647f3..ffc623f1c 100644 --- a/pkg/tasks/client/client_mock.go +++ b/pkg/tasks/client/client_mock.go @@ -1,4 +1,4 @@ -// Code generated by mockery v2.46.2. DO NOT EDIT. +// Code generated by mockery. DO NOT EDIT. package client diff --git a/pkg/tasks/queue/queue.go b/pkg/tasks/queue/queue.go index b7ca2438d..cbf010529 100644 --- a/pkg/tasks/queue/queue.go +++ b/pkg/tasks/queue/queue.go @@ -25,7 +25,6 @@ type Task struct { Priority int } -//go:generate $GO_OUTPUT/mockery --name Queue --filename queue_mock.go --inpackage type Queue interface { // Enqueue Enqueues a job Enqueue(task *Task) (uuid.UUID, error) diff --git a/pkg/tasks/queue/queue_mock.go b/pkg/tasks/queue/queue_mock.go index 3df5d58b1..a55d17f93 100644 --- a/pkg/tasks/queue/queue_mock.go +++ b/pkg/tasks/queue/queue_mock.go @@ -1,4 +1,4 @@ -// Code generated by mockery v2.46.2. DO NOT EDIT. +// Code generated by mockery. DO NOT EDIT. package queue diff --git a/scripts/mockery_comment_fix.sh b/scripts/mockery_comment_fix.sh new file mode 100755 index 000000000..0698ecf3d --- /dev/null +++ b/scripts/mockery_comment_fix.sh @@ -0,0 +1,29 @@ +#!/bin/bash + +COMMAND="$1" # comment | uncomment +PATTERN="" + +function print_out_usage { + cat < +EOF +} + +if [ "${COMMAND}" == "comment" ]; then + PATTERN="2,$$ s/^/\/\//" +elif [ "${COMMAND}" == "uncomment" ]; then + PATTERN="2,$$ s/^\/\///" +else + echo "error: unsupported or missing argument" >&2 + print_out_usage >&2 + exit 1 +fi + +case "$( uname -s )" in + "Linux" ) # For GNU/Linux systems the -i flag doesn't accept the extension. + sed -i "$PATTERN" pkg/dao/registry_mock.go + ;; + "Darwin" | * ) # For Darwin/BSD systems the -i flag needs an extension specified, can be left blank to not add an extension. + sed -i '' "$PATTERN" pkg/dao/registry_mock.go + ;; +esac