Skip to content

Commit

Permalink
tests: avoid overwriting "plant.yaml"
Browse files Browse the repository at this point in the history
Copy "tests/data/plant.yaml" to the temporary root's "garden.yaml" so
that tests can concurrently write to this file without racing with other
tests that may be running concurrently.
  • Loading branch information
davvid committed Jun 2, 2024
1 parent 5772bd3 commit 16dc4f9
Showing 1 changed file with 51 additions and 52 deletions.
103 changes: 51 additions & 52 deletions tests/plant_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -192,12 +192,17 @@ fn plant_git_worktree() -> Result<()> {
fn plant_keep_variables_oneline() -> Result<()> {
let tree_name = "example/oneline";
let config_path = "tests/data/plant.yaml";
let config_pathbuf = std::path::PathBuf::from(config_path);
let fixture = common::BareRepoFixture::new(function_name!());
let fixture_root = fixture.root();
// Copy plant.yaml to "garden.yaml" in the temporary root.
let mut fixture_config_pathbuf = fixture.root_pathbuf();
fixture_config_pathbuf.push("garden.yaml");
std::fs::copy(config_path, &fixture_config_pathbuf)?;

// Check that the config uses ${storage} variables for url and remotes.
{
let app_context = garden::model::ApplicationContext::from_path_and_root(
&config_pathbuf,
&fixture_config_pathbuf,
Some(&fixture.root_pathbuf()),
)?;
let cfg = app_context.get_root_config();
Expand All @@ -206,26 +211,22 @@ fn plant_keep_variables_oneline() -> Result<()> {
}
// Grow the tree.
common::exec_garden(&[
"--root",
&fixture.root(),
"--config",
config_path,
"--chdir",
&fixture_root,
"grow",
tree_name,
])?;
assert!(fixture.pathbuf(tree_name).exists());
// Re-plant the tree and ensure that the variables are retained.
common::exec_garden(&[
"--chdir",
&fixture.root(),
"--config",
config_path,
&fixture_root,
"plant",
tree_name,
])?;
{
let app_context = garden::model::ApplicationContext::from_path_and_root(
&config_pathbuf,
&fixture_config_pathbuf,
Some(&fixture.root_pathbuf()),
)?;
let cfg = app_context.get_root_config();
Expand All @@ -242,26 +243,24 @@ fn plant_keep_variables_oneline() -> Result<()> {
fn plant_add_remote_to_oneline_tree() -> Result<()> {
let tree_name = "example/oneline";
let fixture = common::BareRepoFixture::new(function_name!());

let mut garden_yaml = fixture.root_pathbuf();
garden_yaml.push("garden.yaml");
std::fs::copy("tests/data/plant.yaml", &garden_yaml)?;

let config_path = fixture.path("garden.yaml");
let config_pathbuf = std::path::PathBuf::from(config_path);

let fixture_root = fixture.root();
let config_path = "tests/data/plant.yaml";
// Copy plant.yaml to "garden.yaml" in the temporary root.
let mut fixture_config_pathbuf = fixture.root_pathbuf();
fixture_config_pathbuf.push("garden.yaml");
std::fs::copy(config_path, &fixture_config_pathbuf)?;
// Check that the config uses ${storage} variables for url and remotes.
{
let app_context = garden::model::ApplicationContext::from_path_and_root(
&config_pathbuf,
&fixture_config_pathbuf,
Some(&fixture.root_pathbuf()),
)?;
let cfg = app_context.get_root_config();
let tree = cfg.get_tree(tree_name).unwrap();
assert_eq!(tree.remotes.get("origin").unwrap().get_expr(), "${storage}");
}
// Grow the tree.
common::exec_garden(&["--chdir", &fixture.root(), "grow", tree_name])?;
common::exec_garden(&["--chdir", &fixture_root, "grow", tree_name])?;
assert!(fixture.pathbuf(tree_name).exists());

// Add a remote called "new-remote".
Expand All @@ -270,10 +269,10 @@ fn plant_add_remote_to_oneline_tree() -> Result<()> {
common::assert_cmd(&cmd, &oneline_path);

// Re-plant the tree and ensure that variables are retained and the new remote is recorded.
common::exec_garden(&["--chdir", &fixture.root(), "plant", tree_name])?;
common::exec_garden(&["--chdir", &fixture_root, "plant", tree_name])?;
{
let app_context = garden::model::ApplicationContext::from_path_and_root(
&config_pathbuf,
&fixture_config_pathbuf,
Some(&fixture.root_pathbuf()),
)?;
let cfg = app_context.get_root_config();
Expand All @@ -294,12 +293,16 @@ fn plant_add_remote_to_oneline_tree() -> Result<()> {
fn plant_keep_variables_simple() -> Result<()> {
let tree_name = "example/main";
let config_path = "tests/data/plant.yaml";
let config_pathbuf = std::path::PathBuf::from(config_path);
let fixture = common::BareRepoFixture::new(function_name!());
let fixture_root = fixture.root();
// Copy plant.yaml to "garden.yaml" in the temporary root.
let mut fixture_config_pathbuf = fixture.root_pathbuf();
fixture_config_pathbuf.push("garden.yaml");
std::fs::copy(config_path, &fixture_config_pathbuf)?;
// Check that the config uses ${storage} variables for url and remotes.
{
let app_context = garden::model::ApplicationContext::from_path_and_root(
&config_pathbuf,
&fixture_config_pathbuf,
Some(&fixture.root_pathbuf()),
)?;
let cfg = app_context.get_root_config();
Expand All @@ -308,26 +311,22 @@ fn plant_keep_variables_simple() -> Result<()> {
}
// Grow the tree.
common::exec_garden(&[
"--root",
&fixture.root(),
"--config",
config_path,
"--chdir",
&fixture_root,
"grow",
tree_name,
])?;
assert!(fixture.pathbuf(tree_name).exists());
// Re-plant the tree and ensure that the variables are retained.
common::exec_garden(&[
"--chdir",
&fixture.root(),
"--config",
config_path,
&fixture_root,
"plant",
tree_name,
])?;
{
let app_context = garden::model::ApplicationContext::from_path_and_root(
&config_pathbuf,
&fixture_config_pathbuf,
Some(&fixture.root_pathbuf()),
)?;
let cfg = app_context.get_root_config();
Expand All @@ -344,12 +343,16 @@ fn plant_keep_variables_simple() -> Result<()> {
fn plant_keep_variables_with_remotes() -> Result<()> {
let tree_name = "example/variables";
let config_path = "tests/data/plant.yaml";
let config_pathbuf = std::path::PathBuf::from(config_path);
let fixture = common::BareRepoFixture::new(function_name!());
let fixture_root = fixture.root();
// Copy plant.yaml to "garden.yaml" in the temporary root.
let mut fixture_config_pathbuf = fixture.root_pathbuf();
fixture_config_pathbuf.push("garden.yaml");
std::fs::copy(config_path, &fixture_config_pathbuf)?;
// Check that the config uses ${storage} variables for url and remotes.
{
let app_context = garden::model::ApplicationContext::from_path_and_root(
&config_pathbuf,
&fixture_config_pathbuf,
Some(&fixture.root_pathbuf()),
)?;
let cfg = app_context.get_root_config();
Expand All @@ -362,26 +365,23 @@ fn plant_keep_variables_with_remotes() -> Result<()> {
}
// Grow the tree.
common::exec_garden(&[
"--root",
&fixture.root(),
"--config",
config_path,
"--chdir",
&fixture_root,
"grow",
tree_name,
])?;

assert!(fixture.pathbuf(tree_name).exists());
// Re-plant the tree and ensure that the variables are retained.
common::exec_garden(&[
"--chdir",
&fixture.root(),
"--config",
config_path,
&fixture_root,
"plant",
tree_name,
])?;
{
let app_context = garden::model::ApplicationContext::from_path_and_root(
&config_pathbuf,
&fixture_config_pathbuf,
Some(&fixture.root_pathbuf()),
)?;
let cfg = app_context.get_root_config();
Expand All @@ -402,12 +402,15 @@ fn plant_keep_variables_with_remotes() -> Result<()> {
fn plant_keep_variables_with_templates() -> Result<()> {
let tree_name = "example/template";
let config_path = "tests/data/plant.yaml";
let config_pathbuf = std::path::PathBuf::from(config_path);
let fixture = common::BareRepoFixture::new(function_name!());
let fixture_root = fixture.root();
let mut fixture_config_pathbuf = fixture.root_pathbuf();
fixture_config_pathbuf.push("garden.yaml");
std::fs::copy(config_path, &fixture_config_pathbuf)?;
// Check that the config uses ${storage} variables for url and remotes.
{
let app_context = garden::model::ApplicationContext::from_path_and_root(
&config_pathbuf,
&fixture_config_pathbuf,
Some(&fixture.root_pathbuf()),
)?;
let cfg = app_context.get_root_config();
Expand All @@ -420,26 +423,22 @@ fn plant_keep_variables_with_templates() -> Result<()> {
}
// Grow the tree.
common::exec_garden(&[
"--root",
&fixture.root(),
"--config",
config_path,
"--chdir",
&fixture_root,
"grow",
tree_name,
])?;
assert!(fixture.pathbuf(tree_name).exists());
// Re-plant the tree and ensure that the variables are retained.
common::exec_garden(&[
"--chdir",
&fixture.root(),
"--config",
config_path,
&fixture_root,
"plant",
tree_name,
])?;
{
let app_context = garden::model::ApplicationContext::from_path_and_root(
&config_pathbuf,
&fixture_config_pathbuf,
Some(&fixture.root_pathbuf()),
)?;
let cfg = app_context.get_root_config();
Expand Down

0 comments on commit 16dc4f9

Please sign in to comment.