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

Parameters without a default are automatically required by porter #169

Merged
merged 2 commits into from Feb 19, 2019
Merged
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
25 changes: 25 additions & 0 deletions pkg/config/manifest_test.go
Expand Up @@ -205,6 +205,31 @@ func TestResolveArray(t *testing.T) {
assert.Equal(t, "Ralpha", args[0])
}

func TestResolveInMainDict(t *testing.T) {
c := NewTestConfig(t)
c.SetupPorterHome()

c.TestContext.AddTestFile("testdata/param-test-in-block.yaml", Name)

require.NoError(t, c.LoadManifest())

installStep := c.Manifest.Install[0]

os.Setenv("COMMAND", "echo hello world")
err := c.Manifest.ResolveStep(installStep)
assert.NoError(t, err)

assert.NotNil(t, installStep.Data)
t.Logf("install data %v", installStep.Data)
exec := installStep.Data["exec"].(map[interface{}]interface{})
assert.NotNil(t, exec)
command := exec["command"].(interface{})
assert.NotNil(t, command)
cmdVal, ok := command.(string)
assert.True(t, ok)
assert.Equal(t, "echo hello world", cmdVal)
}

func TestResolveSliceWithAMap(t *testing.T) {
c := NewTestConfig(t)
c.SetupPorterHome()
Expand Down
26 changes: 26 additions & 0 deletions pkg/config/testdata/param-test-in-block.yaml
@@ -0,0 +1,26 @@
mixins:
- exec

name: HELLO
version: 0.1.0
description: "An example Porter configuration"
invocationImage: jeremyrickard/porter-hello:latest

parameters:
- name: command
type: string
default: "echo Hello World"

install:
- description: "Install Hello World"
exec:
command:
source: bundle.parameters.command

uninstall:
- description: "Uninstall Hello World"
exec:
command: bash
arguments:
- -c
- echo Goodbye World
7 changes: 6 additions & 1 deletion pkg/porter/build.go
Expand Up @@ -298,12 +298,17 @@ func (p *Porter) generateBundleParameters() map[string]ParameterDefinition {
DataType: param.DataType,
DefaultValue: param.DefaultValue,
AllowedValues: param.AllowedValues,
Required: param.Required,
MinValue: param.MinValue,
MaxValue: param.MaxValue,
MinLength: param.MinLength,
MaxLength: param.MaxLength,
}

// If the default is empty, set required to true.
if param.DefaultValue == nil {
p.Required = true
}

if param.Metadata.Description != "" {
p.Metadata = ParameterMetadata{Description: param.Metadata.Description}
}
Expand Down
27 changes: 27 additions & 0 deletions pkg/porter/build_test.go
Expand Up @@ -125,3 +125,30 @@ func TestPorter_buildBundle(t *testing.T) {
require.Equal(t, bundle.Version, "0.1.0")
require.Equal(t, bundle.Description, "An example Porter configuration")
}

func TestPorter_paramRequired(t *testing.T) {
p := NewTestPorter(t)
p.TestConfig.SetupPorterHome()
p.TestConfig.TestContext.AddTestFile("./testdata/paramafest.yaml", config.Name)

err := p.LoadManifest()
require.NoError(t, err)

err = p.buildBundle("foo", "digest")
require.NoError(t, err)

bundleBytes, err := p.FileSystem.ReadFile("bundle.json")
require.NoError(t, err)

var bundle Bundle
err = json.Unmarshal(bundleBytes, &bundle)
require.NoError(t, err)

p1, ok := bundle.Parameters["command"]
require.True(t, ok)
require.False(t, p1.Required)

p2, ok := bundle.Parameters["command2"]
require.True(t, ok)
require.True(t, p2.Required)
}
10 changes: 5 additions & 5 deletions pkg/porter/packrd/packed-packr.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

31 changes: 31 additions & 0 deletions pkg/porter/testdata/paramafest.yaml
@@ -0,0 +1,31 @@
mixins:
- exec

name: HELLO
version: 0.1.0
description: "An example Porter configuration"
invocationImage: jeremyrickard/porter-hello:latest

parameters:
- name: command
type: string
default: "echo Hello World"
- name: command2
type: string

install:
- description: "Install Hello World"
exec:
command: bash
arguments:
- -c
- source: bundle.parameters.command


uninstall:
- description: "Uninstall Hello World"
exec:
command: bash
arguments:
- -c
- echo Goodbye World