Skip to content

Commit ed75463

Browse files
committed
Fix confusion around pkgname
1 parent e29f842 commit ed75463

File tree

4 files changed

+57
-642
lines changed

4 files changed

+57
-642
lines changed

.mockery.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ packages:
1414
interfaces:
1515
TypesPackage:
1616
github.com/vektra/mockery/v3/internal/fixtures:
17-
interfaces:
1817
RequesterVariadic:
1918
configs:
2019
- mockname: MockRequesterVariadicOneArgument

internal/cmd/mockery.go

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -164,32 +164,33 @@ type InterfaceCollection struct {
164164
srcPkgPath string
165165
outFilePath *pathlib.Path
166166
srcPkg *packages.Package
167-
pkgName string
167+
outPkgName string
168168
interfaces []*pkg.Interface
169169
}
170170

171171
func NewInterfaceCollection(
172172
srcPkgPath string,
173173
outFilePath *pathlib.Path,
174174
srcPkg *packages.Package,
175-
pkgName string,
175+
outPkgName string,
176176
) *InterfaceCollection {
177177
return &InterfaceCollection{
178178
srcPkgPath: srcPkgPath,
179179
outFilePath: outFilePath,
180180
srcPkg: srcPkg,
181+
outPkgName: outPkgName,
181182
interfaces: make([]*pkg.Interface, 0),
182183
}
183184
}
184185

185186
func (i *InterfaceCollection) Append(ctx context.Context, iface *pkg.Interface) error {
186187
log := zerolog.Ctx(ctx).With().
187188
Str(logging.LogKeyInterface, iface.Name).
188-
Str(logging.LogKeyPackageName, iface.Pkg.Name).
189+
Str("source-pkgname", iface.Pkg.Name).
189190
Str(logging.LogKeyPackagePath, iface.Pkg.PkgPath).
190191
Str("expected-package-path", i.srcPkgPath).Logger()
191192
if iface.Pkg.PkgPath != i.srcPkgPath {
192-
msg := "cannot mix interfaces from different packages in the same file."
193+
msg := "cannot mix interfaces from different packages in the same file"
193194
log.Error().Msg(msg)
194195
return errors.New(msg)
195196
}
@@ -198,9 +199,9 @@ func (i *InterfaceCollection) Append(ctx context.Context, iface *pkg.Interface)
198199
log.Error().Msg(msg)
199200
return errors.New(msg)
200201
}
201-
if i.pkgName != iface.Config.PkgName {
202+
if i.outPkgName != iface.Config.PkgName {
202203
msg := "all mocks in an output file must have the same pkgname"
203-
log.Error().Str("expected-pkgname", i.pkgName).Str("interface-pkgname", iface.Config.PkgName).Msg(msg)
204+
log.Error().Str("output-pkgname", i.outPkgName).Str("interface-pkgname", iface.Config.PkgName).Msg(msg)
204205
return errors.New(msg)
205206
}
206207
i.interfaces = append(i.interfaces, iface)
@@ -256,7 +257,7 @@ func (r *RootApp) Run() error {
256257
ifaceLog := log.
257258
With().
258259
Str(logging.LogKeyInterface, iface.Name).
259-
Str(logging.LogKeyQualifiedName, iface.Pkg.Types.Path()).
260+
Str(logging.LogKeyPackagePath, iface.Pkg.Types.Path()).
260261
Logger()
261262

262263
ifaceCtx := ifaceLog.WithContext(ctx)
@@ -287,18 +288,20 @@ func (r *RootApp) Run() error {
287288
iface.Pkg.PkgPath,
288289
pathlib.NewPath(ifaceConfig.Dir).Join(ifaceConfig.FileName),
289290
iface.Pkg,
290-
iface.Config.PkgName,
291+
ifaceConfig.PkgName,
291292
)
292293
}
293-
mockFileToInterfaces[filePath].Append(
294+
if err := mockFileToInterfaces[filePath].Append(
294295
ctx,
295296
pkg.NewInterface(
296297
iface.Name,
297298
iface.FileName,
298299
iface.File,
299300
iface.Pkg,
300301
ifaceConfig),
301-
)
302+
); err != nil {
303+
return err
304+
}
302305
}
303306
}
304307

@@ -320,7 +323,8 @@ func (r *RootApp) Run() error {
320323
interfacesInFile.outFilePath.Parent(),
321324
packageConfig.Template,
322325
pkg.Formatter(r.Config.Formatter),
323-
interfacesInFile.pkgName,
326+
packageConfig,
327+
interfacesInFile.outPkgName,
324328
)
325329
if err != nil {
326330
return err

0 commit comments

Comments
 (0)