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

Simplify parseConfigTemplates implementation #833

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 5 additions & 11 deletions pkg/outputter.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,12 +180,9 @@ func (*FileOutputStreamProvider) underscoreCaseName(caseName string) string {
func parseConfigTemplates(ctx context.Context, c *config.Config, iface *Interface) error {
log := zerolog.Ctx(ctx)

isExported := ast.IsExported(iface.Name)
var mock string
if isExported {
mock := "mock"
if ast.IsExported(iface.Name) {
mock = "Mock"
} else {
mock = "mock"
}

workingDir, err := os.Getwd()
Expand Down Expand Up @@ -248,12 +245,10 @@ func parseConfigTemplates(ctx context.Context, c *config.Config, iface *Interfac
"outpkg": &c.Outpkg,
}

numIterations := 0
changesMade := true
for changesMade {
if numIterations >= 20 {
msg := "infinite loop in template variables detected"
log.Error().Msg(msg)
for i := 0; changesMade; i++ {
if i >= 20 {
log.Error().Msg("infinite loop in template variables detected")
for key, val := range templateMap {
l := log.With().Str("variable-name", key).Str("variable-value", *val).Logger()
l.Error().Msg("config variable value")
Expand Down Expand Up @@ -282,7 +277,6 @@ func parseConfigTemplates(ctx context.Context, c *config.Config, iface *Interfac
changesMade = true
}
}
numIterations += 1
}

return nil
Expand Down
Loading