vektra / mockery

A mock code autogenerator for Go
https://vektra.github.io/mockery/
BSD 3-Clause "New" or "Revised" License
5.8k stars 395 forks source link

Filename generated with variable name #735

Closed fatahTop closed 6 months ago

fatahTop commented 7 months ago

Description

I just try mockery out and using the binary .exe for windows as recommended by the docs then I create config file .mockery.yaml on top root of my project repo as follows:

inpackage: True 
with-expecter: True 
filename: "{{ .InterfaceName }}_mock.go"

When I try to generate mockery using the command mockery --name Foo I got the file named { .InterfaceName }}_mock.go instead of Foo_mock.go, I don't know what went wrong I just try this out. It works fine if I don't use the config file or specify the filename in config but I want to be able to customize the filename generated.

I also tried cmd ways: mockery --name Foo --filename "{{ .InterfaceName }}_mock.go" but got the same result.

I also tried to use camelcase like "{{ .InterfaceName | camelcase }}_mock.go" but got error:

ERR Unable to get writer error="open D:\dir\dirB\dirC{{ .InterfaceName | camelcase }}_mock.go: The filename, directory name, or volume label syntax is incorrect." dry-run=false interface=Foo qualified-name=dirC version=v2.37.1

Mockery Version

mockery_2.37.1_Windows_x86_64

Golang Version

go1.21.3

Installation Method

Steps to Reproduce

  1. Create config .mockery.yaml with filename config
  2. Run mockery --name Foo
  3. Check the filename generated

Expected Behavior

It result with filename Foo_mock.go

Actual Behavior

{{ .InterfaceName }}_mock.go

LandonTClipp commented 7 months ago

Are you using the packages config feature?

https://vektra.github.io/mockery/v2.37/configuration/#templated-strings

From the docs:

Templated variables are only available when using the packages config feature.
fatahTop commented 6 months ago

Ah i see it worked fine using package config sorry my bad