Skip to content

Commit

Permalink
tests: cycles in environment variables are detected and gracefully ha…
Browse files Browse the repository at this point in the history
…ndled
  • Loading branch information
davvid committed Feb 6, 2024
1 parent 1b200ea commit ac13570
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 0 deletions.
3 changes: 3 additions & 0 deletions tests/data/circular.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,11 @@ trees:
path: ${GARDEN_CONFIG_DIR}
variables:
root-variable: root-tree-${circular-variable}
environment:
ENV_CIRCULAR_VARIABLE: ${TREE_NAME}/${env-circular-variable}

# This file contains circular dependencies in variables.
variables:
circular-variable: ${graft::circular-variable}
root-variable: root-${circular-variable}
env-circular-variable: variables/${ENV_CIRCULAR_VARIABLE}
2 changes: 2 additions & 0 deletions tests/data/grafts/graft-circular.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,5 @@ variables:
trees:
current:
path: ${GARDEN_CONFIG_DIR}
environment:
ENV_CIRCULAR_VARIABLE: graft/${TREE_NAME}/${env-circular-variable}
27 changes: 27 additions & 0 deletions tests/integration_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1009,6 +1009,33 @@ fn eval_graft_variables_with_circular_dependencies() {
assert_eq!(output, "root-graft-");
}

/// Test evaluating a graft variable that triggers an infinite loop via a circular dependency.
#[test]
fn eval_environment_variables_with_circular_dependencies() {
// The graft's environment variable has "graft/${TREE_NAME}/${circular-variable}".
// The ${env-circular-variable} expression is "variables/${ENV_CIRCULAR_VARIABLE}"
// The evaluation machinery is short-circuits itself on the inner ${env-circular-variable}
// and resolves down until the cycle is detected and gets cut off.
// The graft::current tree is called "current".
let output = garden_capture(&[
"--config",
"tests/data/circular.yaml",
"eval",
"${ENV_CIRCULAR_VARIABLE}",
"graft::current",
]);
assert_eq!(output, "graft/current/variables/graft/current/");
// The root-tree's context traverses in a different order and evaluates its TREE_NAME.
let output = garden_capture(&[
"--config",
"tests/data/circular.yaml",
"eval",
"${ENV_CIRCULAR_VARIABLE}",
"root-tree",
]);
assert_eq!(output, "root-tree/variables/root-tree/");
}

/// `garden grow` creates symlinks
#[test]
#[named]
Expand Down

0 comments on commit ac13570

Please sign in to comment.