Skip to content

Commit

Permalink
Some more tests for the build command
Browse files Browse the repository at this point in the history
  • Loading branch information
james-w committed Jul 15, 2024
1 parent 98b5c6a commit a14ed61
Showing 1 changed file with 67 additions and 3 deletions.
70 changes: 67 additions & 3 deletions tests/test_build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,12 +142,12 @@ fn test_build_rebuilds_if_file_changes() {
.modified()
.unwrap();

// Tiny sleep to make sure the timestamp changes
thread::sleep(Duration::from_nanos(500));
cmd.assert().success();

test_context.workdir.child("hello").touch().unwrap();

cmd.assert().success();
// Tiny sleep to make sure the timestamp changes
thread::sleep(Duration::from_nanos(500));

eprintln!(
"{}",
Expand All @@ -164,3 +164,67 @@ fn test_build_rebuilds_if_file_changes() {

assert!(ending_timestamp > middle_timestamp);
}

#[test]
fn test_error_when_is_not_an_arfifact() {
let config_src = r#"
[command.exec.copy]
command = "cp hello world"
"#;

let test_context = common::TestContext::new();
test_context.write_config(config_src);

let mut cmd = test_context.get_command();
cmd.arg("build").arg("copy");

cmd.assert().failure();

cmd.assert().stderr(predicate::str::contains(
"Target <copy> is not buildable, use the run command instead",
));
}

#[test]
fn test_error_when_does_not_exist() {
let config_src = r#"
[command.exec.copy]
command = "cp hello world"
"#;

let test_context = common::TestContext::new();
test_context.write_config(config_src);

let mut cmd = test_context.get_command();
cmd.arg("build").arg("non_existent");

cmd.assert().failure();

cmd.assert().stderr(predicate::str::contains(
"Target <non_existent> not found in config file <",
));
}

#[test]
fn test_error_when_ambiguous() {
let config_src = r#"
[artifact.exec.copy]
command = "cp hello world"
[artifact.container_image.copy]
context = "."
tag = "latest"
"#;

let test_context = common::TestContext::new();
test_context.write_config(config_src);

let mut cmd = test_context.get_command();
cmd.arg("build").arg("copy");

cmd.assert().failure();

cmd.assert().stderr(predicate::str::contains(
"Target <copy> is ambiguous, possible values are <artifact.exec.copy, artifact.container_image.copy>",
));
}

0 comments on commit a14ed61

Please sign in to comment.