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

Add failing test case for parameter with output source #2904

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions CONTRIBUTORS.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,5 +101,6 @@ and we will add you. **All** contributors belong here. 💯
- [guangwu guo](https://github.com/testwill)
- [Eric Herrmann](https://github.com/egherrmann)
- [Alex Dejanu](https://github.com/dejanu)
- [Leo Bergnéhr](https://github.com/lbergnehr)


28 changes: 22 additions & 6 deletions pkg/runtime/runtime_manifest.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"compress/gzip"
"context"
"encoding/base64"
"encoding/json"
"fmt"
"io"
"os"
Expand Down Expand Up @@ -131,15 +132,27 @@ func (m *RuntimeManifest) loadDependencyDefinitions() error {
return nil
}

func (m *RuntimeManifest) resolveParameter(pd manifest.ParameterDefinition) string {
func (m *RuntimeManifest) resolveParameter(pd manifest.ParameterDefinition) (interface{}, error) {
getValue := func(envVar string) (interface{}, error) {
value := m.config.Getenv(envVar)
if pd.Type == "object" {
var obj map[string]interface{}
if err := json.Unmarshal([]byte(value), &obj); err != nil {
return nil, err
}
return obj, nil
}
return value, nil
}

if pd.Destination.EnvironmentVariable != "" {
return m.config.Getenv(pd.Destination.EnvironmentVariable)
return getValue(pd.Destination.EnvironmentVariable)
}
if pd.Destination.Path != "" {
return pd.Destination.Path
return pd.Destination.Path, nil
}
envVar := manifest.ParamToEnvVar(pd.Name)
return m.config.Getenv(envVar)
return getValue(envVar)
}

func (m *RuntimeManifest) resolveCredential(cd manifest.CredentialDefinition) (string, error) {
Expand Down Expand Up @@ -271,9 +284,12 @@ func (m *RuntimeManifest) buildSourceData() (map[string]interface{}, error) {
}

pe := param.Name
val := m.resolveParameter(param)
val, err := m.resolveParameter(param)
if err != nil {
return nil, err
}
if param.Sensitive {
m.setSensitiveValue(val)
m.setSensitiveValue(val.(string))
}
params[pe] = val
}
Expand Down
11 changes: 11 additions & 0 deletions pkg/runtime/runtime_manifest_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,21 @@ func TestResolveMapParam(t *testing.T) {
ctx := context.Background()
testConfig := config.NewTestConfig(t)
testConfig.Setenv("PERSON", "Ralpha")
testConfig.Setenv("CONTACT", "{ \"name\": \"Breta\" }")

mContent := `schemaVersion: 1.0.0-alpha.2
parameters:
- name: person
- name: place
applyTo: [install]
- name: contact
type: object

install:
- mymixin:
Parameters:
Thing: ${ bundle.parameters.person }
Object: ${ bundle.parameters.contact.name }
`
rm := runtimeManifestFromStepYaml(t, testConfig, mContent)
s := rm.Install[0]
Expand All @@ -62,6 +66,13 @@ install:
assert.Equal(t, "Ralpha", val)
assert.NotContains(t, "place", pms, "parameters that don't apply to the current action should not be resolved")

// New assertions for the contact parameter
require.IsType(t, "string", pms["Object"], "Data.mymixin.Parameters.Object has incorrect type")
contactName := pms["Object"].(string)
require.IsType(t, "string", contactName, "Data.mymixin.Parameters.Object.name has incorrect type")

assert.Equal(t, "Breta", contactName)

err = rm.Initialize(ctx)
require.NoError(t, err)
}
Expand Down