From 0cf52aecade5c7f65b6b56919f2459af51a8d621 Mon Sep 17 00:00:00 2001 From: Vaughn Dice Date: Mon, 20 Jul 2020 17:00:00 -0600 Subject: [PATCH] move applyDefaultOptions to sharedOptions.Validate() Signed-off-by: Vaughn Dice --- pkg/porter/cnab.go | 12 +++++------- pkg/porter/cnab_test.go | 25 ++++++++++--------------- pkg/porter/install.go | 5 ----- pkg/porter/invoke.go | 5 ----- pkg/porter/options.go | 4 +++- pkg/porter/uninstall.go | 5 ----- pkg/porter/upgrade.go | 5 ----- 7 files changed, 18 insertions(+), 43 deletions(-) diff --git a/pkg/porter/cnab.go b/pkg/porter/cnab.go index 7eeea21a9..3ca4b6a87 100644 --- a/pkg/porter/cnab.go +++ b/pkg/porter/cnab.go @@ -93,6 +93,11 @@ func (o *sharedOptions) Validate(args []string, p *Porter) error { return err } + err = p.applyDefaultOptions(o) + if err != nil { + return err + } + err = o.validateParams(p) if err != nil { return err @@ -235,13 +240,6 @@ func (o *sharedOptions) parseParams() error { // parseParamSets parses the variable assignments in ParameterSets. func (o *sharedOptions) parseParamSets(p *Porter) error { if len(o.ParameterSets) > 0 { - // Load the manifest as it may be needed to determine if any - // parameters are of the Porter-exclusive type of 'file' - err := p.LoadManifestFrom(o.File) - if err != nil { - return err - } - parsed, err := p.loadParameterSets(o.ParameterSets) if err != nil { return errors.Wrapf(err, "unable to process provided parameter sets: %v", o.ParameterSets) diff --git a/pkg/porter/cnab_test.go b/pkg/porter/cnab_test.go index 1aeb87e62..29cf1b4d3 100644 --- a/pkg/porter/cnab_test.go +++ b/pkg/porter/cnab_test.go @@ -6,7 +6,6 @@ import ( "testing" "get.porter.sh/porter/pkg/build" - "get.porter.sh/porter/pkg/config" "get.porter.sh/porter/pkg/context" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" @@ -92,10 +91,6 @@ func TestSharedOptions_defaultDriver(t *testing.T) { func TestParseParamSets_viaPathOrName(t *testing.T) { p := NewTestPorter(t) - cxt := p.TestConfig.TestContext - - // Add manifest used to parse parameter sets - cxt.AddTestFile("testdata/porter.yaml", config.Name) p.TestParameters.TestSecrets.AddSecret("foo_secret", "foo_value") p.TestParameters.TestSecrets.AddSecret("PARAM2_SECRET", "VALUE2") @@ -107,12 +102,12 @@ func TestParseParamSets_viaPathOrName(t *testing.T) { "HELLO_CUSTOM", "/paramset.json", }, - bundleFileOptions: bundleFileOptions{ - File: config.Name, - }, } - err := opts.parseParamSets(p.Porter) + err := opts.Validate([]string{}, p.Porter) + assert.NoError(t, err) + + err = opts.parseParamSets(p.Porter) assert.NoError(t, err) wantParams := map[string]string{ @@ -124,11 +119,8 @@ func TestParseParamSets_viaPathOrName(t *testing.T) { func TestParseParamSets_FileType(t *testing.T) { p := NewTestPorter(t) - cxt := p.TestConfig.TestContext - - // Add manifest used to parse parameter sets - cxt.AddTestFile("testdata/porter-with-file-param.yaml", config.Name) + p.TestConfig.TestContext.AddTestFile("testdata/porter-with-file-param.yaml", "porter.yaml") p.TestConfig.TestContext.AddTestFile("testdata/paramset-with-file-param.json", "/paramset.json") opts := sharedOptions{ @@ -136,11 +128,14 @@ func TestParseParamSets_FileType(t *testing.T) { "/paramset.json", }, bundleFileOptions: bundleFileOptions{ - File: config.Name, + File: "porter.yaml", }, } - err := opts.parseParamSets(p.Porter) + err := opts.Validate([]string{}, p.Porter) + assert.NoError(t, err) + + err = opts.parseParamSets(p.Porter) assert.NoError(t, err) wantParams := map[string]string{ diff --git a/pkg/porter/install.go b/pkg/porter/install.go index a96c295a8..e8ba32b1d 100644 --- a/pkg/porter/install.go +++ b/pkg/porter/install.go @@ -22,11 +22,6 @@ func (p *Porter) InstallBundle(opts InstallOptions) error { return errors.Wrap(err, "unable to pull bundle before installation") } - err = p.applyDefaultOptions(&opts.sharedOptions) - if err != nil { - return err - } - err = p.ensureLocalBundleIsUpToDate(opts.bundleFileOptions) if err != nil { return err diff --git a/pkg/porter/invoke.go b/pkg/porter/invoke.go index ed4b13f89..7ac233de7 100644 --- a/pkg/porter/invoke.go +++ b/pkg/porter/invoke.go @@ -32,11 +32,6 @@ func (p *Porter) InvokeBundle(opts InvokeOptions) error { return errors.Wrap(err, "unable to pull bundle before invoking the custom action") } - err = p.applyDefaultOptions(&opts.sharedOptions) - if err != nil { - return err - } - err = p.ensureLocalBundleIsUpToDate(opts.bundleFileOptions) if err != nil { return err diff --git a/pkg/porter/options.go b/pkg/porter/options.go index 51d1cc3f1..0bad8e062 100644 --- a/pkg/porter/options.go +++ b/pkg/porter/options.go @@ -1,6 +1,8 @@ package porter -import "get.porter.sh/porter/pkg/manifest" +import ( + "get.porter.sh/porter/pkg/manifest" +) // applyDefaultOptions applies more advanced defaults to the options // based on values that beyond just what was supplied by the user diff --git a/pkg/porter/uninstall.go b/pkg/porter/uninstall.go index e8b629ee6..5af9edb3f 100644 --- a/pkg/porter/uninstall.go +++ b/pkg/porter/uninstall.go @@ -22,11 +22,6 @@ func (p *Porter) UninstallBundle(opts UninstallOptions) error { return errors.Wrap(err, "unable to pull bundle before uninstall") } - err = p.applyDefaultOptions(&opts.sharedOptions) - if err != nil { - return err - } - err = p.ensureLocalBundleIsUpToDate(opts.bundleFileOptions) if err != nil { return err diff --git a/pkg/porter/upgrade.go b/pkg/porter/upgrade.go index b445cf0af..143458cfe 100644 --- a/pkg/porter/upgrade.go +++ b/pkg/porter/upgrade.go @@ -22,11 +22,6 @@ func (p *Porter) UpgradeBundle(opts UpgradeOptions) error { return errors.Wrap(err, "unable to pull bundle before upgrade") } - err = p.applyDefaultOptions(&opts.sharedOptions) - if err != nil { - return err - } - err = p.ensureLocalBundleIsUpToDate(opts.bundleFileOptions) if err != nil { return err