Skip to content
This repository was archived by the owner on Jul 18, 2025. It is now read-only.

Commit 59fb96a

Browse files
authored
Merge pull request #554 from rumpl/fix-load-flattened-parameters
Make sure Load is consistent
2 parents ceac1cf + 468409a commit 59fb96a

File tree

4 files changed

+49
-5
lines changed

4 files changed

+49
-5
lines changed

BUILDING.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ During the automated CI, the unit tests and end-to-end tests are run as
9191
part of the PR validation. As a developer you can run these tests
9292
locally by using any of the following `Makefile` targets:
9393

94-
- `make test`: run all non-end-to-end tests
94+
- `make test-unit`: run all non-end-to-end tests
9595
- `make test-e2e`: run all end-to-end tests
9696

9797
To execute a specific test or set of tests you can use the `go test`

render/render_test.go

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66

77
"github.com/deislabs/cnab-go/bundle"
88
"github.com/docker/app/types"
9+
"github.com/docker/app/types/parameters"
910
composetypes "github.com/docker/cli/cli/compose/types"
1011
yaml "gopkg.in/yaml.v2"
1112
"gotest.tools/assert"
@@ -232,3 +233,31 @@ func TestServiceImageOverride(t *testing.T) {
232233
assert.Check(t, is.Len(c.Services, 1))
233234
assert.Check(t, is.Equal(c.Services[0].Image, "test"))
234235
}
236+
237+
func TestRenderShouldMergeNonUniformParameters(t *testing.T) {
238+
metadata := strings.NewReader(validMeta)
239+
composeFile := strings.NewReader(`
240+
version: "3.6"
241+
services:
242+
any:
243+
image: none/none
244+
environment:
245+
SSH_USER: ${ssh.user}
246+
`)
247+
p := strings.NewReader(`
248+
ssh.user: FILLME
249+
`)
250+
parametersOverride := strings.NewReader(`
251+
ssh:
252+
user: sirtea
253+
`)
254+
app := &types.App{Path: "my-app"}
255+
assert.NilError(t, types.Metadata(metadata)(app))
256+
assert.NilError(t, types.WithComposes(composeFile)(app))
257+
assert.NilError(t, types.WithParameters(p, parametersOverride)(app))
258+
params := app.Parameters()
259+
assert.Equal(t, len(params), 1)
260+
assert.DeepEqual(t, params, parameters.Parameters{
261+
"ssh": map[string]interface{}{"user": "sirtea"},
262+
})
263+
}

types/parameters/load.go

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,18 @@ func Load(data []byte, ops ...func(*Options)) (Parameters, error) {
3030
if err != nil {
3131
return nil, err
3232
}
33-
parameters := converted.(map[string]interface{})
33+
params := converted.(map[string]interface{})
3434
if options.prefix != "" {
35-
parameters = map[string]interface{}{
36-
options.prefix: parameters,
35+
params = map[string]interface{}{
36+
options.prefix: params,
3737
}
3838
}
39-
return parameters, nil
39+
// Make sure params are always loaded expanded
40+
expandedParams, err := FromFlatten(flatten(params))
41+
if err != nil {
42+
return nil, err
43+
}
44+
return expandedParams, nil
4045
}
4146

4247
// LoadMultiple loads multiple data in parameters

types/parameters/load_test.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,16 @@ baz:
4343
}))
4444
}
4545

46+
func TestLoadSameWithDifferentNotation(t *testing.T) {
47+
flatParameters, err := Load([]byte(`foo.bar: baz`))
48+
assert.NilError(t, err)
49+
expandedParameters, err := Load([]byte(`
50+
foo:
51+
bar: "baz"`))
52+
assert.NilError(t, err)
53+
assert.Check(t, is.DeepEqual(flatParameters, expandedParameters))
54+
}
55+
4656
func TestLoadWithPrefix(t *testing.T) {
4757
parameters, err := Load([]byte(`
4858
foo: bar

0 commit comments

Comments
 (0)