Skip to content

Commit

Permalink
Fixes 4552: fix missing method bug with mock gen (#856)
Browse files Browse the repository at this point in the history
* Fixes 4552: fix missing method bug with mock gen

* fix: mockery path, script for mockery comment fix
  • Loading branch information
dominikvagner authored Oct 22, 2024
1 parent d9c148b commit 44aa552
Show file tree
Hide file tree
Showing 26 changed files with 111 additions and 35 deletions.
62 changes: 62 additions & 0 deletions .mockery.yaml
Original file line number Diff line number Diff line change
@@ -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"
4 changes: 3 additions & 1 deletion mk/mockery.mk
Original file line number Diff line number Diff line change
Expand Up @@ -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 ./...
./scripts/mockery_comment_fix.sh comment
$(GO_OUTPUT)/mockery
./scripts/mockery_comment_fix.sh uncomment
1 change: 0 additions & 1 deletion pkg/cache/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion pkg/cache/cache_mock.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pkg/candlepin_client/candlepin_client_mock.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion pkg/candlepin_client/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion pkg/dao/admin_tasks_mock.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pkg/dao/domain_dao_mock.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pkg/dao/environments_mock.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 0 additions & 11 deletions pkg/dao/interfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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
Expand All @@ -137,27 +132,23 @@ 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)
FetchActiveTasks(ctx context.Context, orgID string, objectUUID string, taskTypes ...string) ([]string, error)
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)
Expand All @@ -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)
Expand All @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion pkg/dao/metrics_mock.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pkg/dao/package_groups_mock.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pkg/dao/repositories_mock.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pkg/dao/repository_configs_mock.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pkg/dao/rpms_mock.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pkg/dao/snapshots_mock.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pkg/dao/task_info_mock.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pkg/dao/templates_mock.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 0 additions & 2 deletions pkg/pulp_client/interfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion pkg/pulp_client/pulp_client_mock.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pkg/pulp_client/pulp_global_client_mock.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion pkg/tasks/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion pkg/tasks/client/client_mock.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion pkg/tasks/queue/queue.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion pkg/tasks/queue/queue_mock.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

29 changes: 29 additions & 0 deletions scripts/mockery_comment_fix.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#!/bin/bash

COMMAND="$1" # comment | uncomment
PATTERN=""

function print_out_usage {
cat <<EOF
Usage: ./scripts/mockery_comment_fix.sh <(comment | uncomment)>
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

0 comments on commit 44aa552

Please sign in to comment.