Skip to content

Commit 7587fce

Browse files
committed
chore: Wiring expansion into the unit and stack parse
1 parent ac9c536 commit 7587fce

3 files changed

Lines changed: 214 additions & 51 deletions

File tree

pkg/config/expansion_test.go

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ unit "app" {
3838
}
3939
4040
source = "./modules/app"
41-
path = "app"
41+
path = "app/${each.key}"
4242
}
4343
`
4444

@@ -55,7 +55,7 @@ stack "team" {
5555
}
5656
5757
source = "./stacks/team"
58-
path = "team"
58+
path = "team/${count.index}"
5959
}
6060
`
6161

@@ -633,29 +633,31 @@ bogus "x" {
633633
require.Error(t, err)
634634
}
635635

636-
func TestUnitAndStackDecodeExpansionBlock(t *testing.T) {
636+
func TestUnitAndStackExpandPerIterationElement(t *testing.T) {
637637
t.Parallel()
638638

639639
stackCfg, err := parseStackString(t, unitWithExpansionHCL+stackWithExpansionHCL)
640640
require.NoError(t, err)
641-
require.Len(t, stackCfg.Units, 1)
642-
require.Len(t, stackCfg.Stacks, 1)
643-
644-
unitExpansion := stackCfg.Units[0].Expansion
645-
require.NotNil(t, unitExpansion)
646-
require.NotNil(t, unitExpansion.ForEach)
647-
assert.Equal(
648-
t,
649-
cty.SetVal([]cty.Value{cty.StringVal("web"), cty.StringVal("api")}),
650-
*unitExpansion.ForEach,
651-
)
641+
require.Len(t, stackCfg.Units, 2)
642+
require.Len(t, stackCfg.Stacks, 2)
643+
644+
unitPaths := map[string]string{}
645+
646+
for _, unit := range stackCfg.Units {
647+
require.NotNil(t, unit.Expansion)
648+
unitPaths[unit.Expansion.Key()] = unit.Path
649+
}
650+
651+
assert.Equal(t, map[string]string{"web": "app/web", "api": "app/api"}, unitPaths)
652+
653+
stackPaths := map[string]string{}
654+
655+
for _, stack := range stackCfg.Stacks {
656+
require.NotNil(t, stack.Expansion)
657+
stackPaths[stack.Expansion.Key()] = stack.Path
658+
}
652659

653-
stackExpansion := stackCfg.Stacks[0].Expansion
654-
require.NotNil(t, stackExpansion)
655-
require.NotNil(t, stackExpansion.Count)
656-
// Decoding and the literal build the number at different big.Float precisions,
657-
// which assert.Equal reads as a diff.
658-
assert.True(t, stackExpansion.Count.RawEquals(cty.NumberIntVal(2)))
660+
assert.Equal(t, map[string]string{"0": "team/0", "1": "team/1"}, stackPaths)
659661
}
660662

661663
func TestBlocksWithoutExpansionDecodeUnchanged(t *testing.T) {

0 commit comments

Comments
 (0)