Skip to content

Commit

Permalink
Merge pull request #1037 from rawlingsj/sub
Browse files Browse the repository at this point in the history
apply package substitutions in test.environment.contents.packages
  • Loading branch information
rawlingsj committed Feb 20, 2024
2 parents 01ef71f + ddfdbb0 commit 2826e29
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
7 changes: 7 additions & 0 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,13 @@ func (cfg *Configuration) applySubstitutionsForPackages() error {
return fmt.Errorf("failed to apply replacement to package %q: %w", runtime, err)
}
}
for i, runtime := range cfg.Test.Environment.Contents.Packages {
var err error
cfg.Test.Environment.Contents.Packages[i], err = util.MutateStringFromMap(nw, runtime)
if err != nil {
return fmt.Errorf("failed to apply replacement to test package %q: %w", runtime, err)
}
}
return nil
}

Expand Down
12 changes: 11 additions & 1 deletion pkg/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"github.com/stretchr/testify/require"
)

func Test_applySubstitutionsInProvides(t *testing.T) {
func Test_applySubstitution(t *testing.T) {
ctx := slogtest.TestContextWithLogger(t)

fp := filepath.Join(os.TempDir(), "melange-test-applySubstitutionsInProvides")
Expand Down Expand Up @@ -52,6 +52,12 @@ subpackages:
- subpackage-bar=${{vars.bar}}
replaces:
- james=${{package.name}}
test:
environment:
contents:
packages:
- ${{package.name}}-config
`), 0644); err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -91,6 +97,10 @@ subpackages:
require.Equal(t, []string{
"dep~0.0.1",
}, cfg.Environment.Contents.Packages)

require.Equal(t, []string{
"replacement-provides-config",
}, cfg.Test.Environment.Contents.Packages)
}

func Test_rangeSubstitutions(t *testing.T) {
Expand Down

0 comments on commit 2826e29

Please sign in to comment.