Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes #769 : Mock files getting created in disk when dry-run is enabled #775

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion cmd/mockery.go
Expand Up @@ -269,7 +269,7 @@ func (r *RootApp) Run() error {
}
ifaceLog.Debug().Msg("config specifies to generate this interface")

outputter := pkg.NewOutputter(&r.Config, boilerplate, true)
outputter := pkg.NewOutputter(&r.Config, boilerplate, r.Config.DryRun)
if err := outputter.Generate(ifaceCtx, iface); err != nil {
return err
}
Expand Down
5 changes: 5 additions & 0 deletions pkg/outputter.go
Expand Up @@ -351,6 +351,11 @@ func (m *Outputter) Generate(ctx context.Context, iface *Interface) error {
return err
}

// If we're in dry-run mode, don't write the mock to disk
if m.dryRun {
continue
}

Comment on lines +354 to +358
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you instead log what file we would have written to, then return? That will be more helpful.

outputPath := pathlib.NewPath(interfaceConfig.Dir).Join(interfaceConfig.FileName)
if err := outputPath.Parent().MkdirAll(); err != nil {
return stackerr.NewStackErrf(err, "failed to mkdir parents of: %v", outputPath)
Expand Down
15 changes: 9 additions & 6 deletions pkg/walker.go
Expand Up @@ -198,12 +198,15 @@ func (v *GeneratorVisitor) VisitWalk(ctx context.Context, iface *Interface) erro
return err
}

if !v.dryRun {
log.Info().Msgf("writing mock to file")
err = gen.Write(out)
if err != nil {
return err
}
// If we're in dry-run mode, avoid writing the mock to disk
if v.dryRun {
return nil
}

log.Info().Msgf("writing mock to file")
err = gen.Write(out)
if err != nil {
return err
}

return nil
Expand Down