Skip to content

Commit

Permalink
move applyDefaultOptions to sharedOptions.Validate()
Browse files Browse the repository at this point in the history
Signed-off-by: Vaughn Dice <[email protected]>
  • Loading branch information
vdice committed Jul 20, 2020
1 parent 613cd89 commit 0cf52ae
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 43 deletions.
12 changes: 5 additions & 7 deletions pkg/porter/cnab.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
25 changes: 10 additions & 15 deletions pkg/porter/cnab_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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")
Expand All @@ -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{
Expand All @@ -124,23 +119,23 @@ 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{
ParameterSets: []string{
"/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{
Expand Down
5 changes: 0 additions & 5 deletions pkg/porter/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 0 additions & 5 deletions pkg/porter/invoke.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 3 additions & 1 deletion pkg/porter/options.go
Original file line number Diff line number Diff line change
@@ -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
Expand Down
5 changes: 0 additions & 5 deletions pkg/porter/uninstall.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 0 additions & 5 deletions pkg/porter/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 0cf52ae

Please sign in to comment.