Skip to content
This repository was archived by the owner on Jun 27, 2023. It is now read-only.
This repository was archived by the owner on Jun 27, 2023. It is now read-only.

Mockgen: Support generating mock for interfaces with generics function params #649

@DanielSolomon

Description

@DanielSolomon

In case I use a concrete type:

type Pagination struct {
	Limit int64
	Skip  int64
}

//go:generate mockgen -source=$GOFILE -destination=mocks/autogen.$GOFILE -package=mocks
type IMongoDbClient interface {
	GetMany(ctx context.Context, collectionName string, filter bson.M, pagination optional.Optional[Pagination]) error
}

Optional is defined in another package as:

type Optional[T any] struct {
	value   T
	present bool
}

When running go generate ./..., the following error is raised:

2022/05/19 10:01:58 Loading input failed: failed parsing source file api.go: api.go:43:97: missing ',' in parameter list
lib/go/mongo/client/api.go:41: running "mockgen": exit status 1

Also tried using the workaround (mentioned in #621):

type OptionalPagination = optional.Optional[Pagination]

Result in:

Loading input failed: failed parsing source file api.go: api.go:41:44: expected ';', found '['
lib/go/mongo/client/api.go:43: running "mockgen": exit status 1

Originally posted by @DanielSolomon in #621 (comment)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions