From b69c0678701c56fee7354493a075b838aef3ba8d Mon Sep 17 00:00:00 2001 From: Shunsuke Suzuki Date: Sun, 5 Nov 2023 09:41:20 +0900 Subject: [PATCH] refactor: split functions (#12) --- pkg/controller/run.go | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/pkg/controller/run.go b/pkg/controller/run.go index 68beac0..8cde5b0 100644 --- a/pkg/controller/run.go +++ b/pkg/controller/run.go @@ -16,6 +16,14 @@ func (c *Controller) Run(_ context.Context, _ *logrus.Entry, param *ParamRun, vo } providers := make(map[string]version.Constraints, len(cfg.Providers)) + if err := parseConfig(cfg, providers); err != nil { + return err + } + + return validate(vout, providers) +} + +func parseConfig(cfg *Config, providers map[string]version.Constraints) error { for _, provider := range cfg.Providers { if provider.Name == "" { return ErrProviderNameIsRequired @@ -33,7 +41,10 @@ func (c *Controller) Run(_ context.Context, _ *logrus.Entry, param *ParamRun, vo } providers[provider.Name] = constraints } + return nil +} +func validate(vout *TerraformVersionOutput, providers map[string]version.Constraints) error { for providerName, providerVersion := range vout.ProviderSelections { constraints, ok := providers[providerName] if !ok {