Skip to content

Commit 4b85ba0

Browse files
committed
test: add tests for directory flattening and tfvars precedence
1 parent 071903f commit 4b85ba0

1 file changed

Lines changed: 27 additions & 0 deletions

File tree

stacks-test.sh

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,30 @@ test_env_match() {
3131
assert_unsuccessful_code
3232
done
3333
}
34+
35+
test_directory_flattening() {
36+
# Run the script directly to test the directory flattening logic
37+
cd example/
38+
output=$(bash ../stacks-gen-deps.sh dev-eu 1 network/vpc network/vpc/main.tf network/netplan.tf org/main.tf providers.tf network/vpc/subdir/below.tf)
39+
40+
# Check that nested files in the branch are flattened correctly
41+
assert_contains '/network_vpc_main.tf: network/vpc/main.tf' "$output"
42+
assert_contains '/network_netplan.tf: network/netplan.tf' "$output"
43+
assert_contains '/providers.tf: providers.tf' "$output"
44+
assert_not_contains 'org/main.tf' "$output"
45+
assert_not_contains 'below' "$output"
46+
}
47+
48+
test_tfvars_precedence() {
49+
# Run the script to test tfvars parsing and precedence mapping
50+
cd example/
51+
output=$(bash ../stacks-gen-deps.sh dev-eu 1 network/vpc network/vpc/main.tf all.tfvars dev-eu.tfvars dev.tfvars network/all.tfvars network/dev-eu.tfvars network/eu.tfvars)
52+
53+
assert_contains '/0-all-.auto.tfvars: all.tfvars' "$output"
54+
assert_contains '/2-dev-.auto.tfvars: dev.tfvars' "$output"
55+
assert_contains '/2-dev-eu-.auto.tfvars: dev-eu.tfvars' "$output"
56+
assert_contains '/network_0-all-.auto.tfvars: network/all.tfvars' "$output"
57+
assert_contains '/network_1-eu-.auto.tfvars: network/eu.tfvars' "$output"
58+
assert_contains '/network_2-dev-eu-.auto.tfvars: network/dev-eu.tfvars' "$output"
59+
}
60+

0 commit comments

Comments
 (0)