Skip to content

V3 replace-type doesn't work for pointer parameters #1097

@richarduuz

Description

@richarduuz

Description

There are two bugs when using replace-type for pointer parameters

  1. paramPkgPath and paramObjName are empty string if the signature param is types.Pointer, causing the following ifaceConfig.GetReplacement function doesn't return the replace-type from the config.
  2. Assuming the correct replace-type can be retrieved, the replaced type will be loaded here and since it is not types.Pointers, the following types.TypeString() wouldn't add * at the beginning.

If you reckon these bugs are valid, I am happy to raise a PR to fix them, since I have made potential fix on my local.

Reproducer

  1. Create an interface that including temporal schedule in a project.
type ScheduleHandle interface {
	client.ScheduleHandle
}
  1. Copy the following config to .mockery.yaml
dir: '{{.InterfaceDir}}/mocks'
structname: '{{.InterfaceName}}'
pkgname: mocks
filename: "{{.InterfaceName}}.go"
template: testify
log-level: debug
template-data:
  unroll-variadic: true
packages:
  mockery-bug/internal:
    interfaces:
      ScheduleHandle:
        config:
          replace-type:
            go.temporal.io/sdk/internal:
              ScheduleBackfillOptions:
                pkg-path: go.temporal.io/sdk/client
                type-name: ScheduleBackfillOptions
              SchedulePauseOptions:
                pkg-path: go.temporal.io/sdk/client
                type-name: SchedulePauseOptions
              ScheduleTriggerOptions:
                pkg-path: go.temporal.io/sdk/client
                type-name: ScheduleTriggerOptions
              ScheduleUnpauseOptions:
                pkg-path: go.temporal.io/sdk/client
                type-name: ScheduleUnpauseOptions
              ScheduleUpdateOptions:
                pkg-path: go.temporal.io/sdk/client
                type-name: ScheduleUpdateOptions
              ScheduleDescription:
                pkg-path: go.temporal.io/sdk/client
                type-name: ScheduleDescription
  1. run mockery, and check the generated file ScheduleHandle.go, the imports for all other structs have been correctly replaced from internal to client, except ScheduleDescription in the Describe method.

Expected behavior

The return value *internal.ScheduleDescription is supposed to be *client.ScheduleDescription.

Mockery version

v3.5.1

Installation Mechanism

  • [] go get
  • [] Pre-built release
  • [] homebrew
  • [] Other

Go version

1.24

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions