Skip to content

Commit

Permalink
fix release.toml version check
Browse files Browse the repository at this point in the history
We had a mistake in bottlerocket-os#112
commit 67ef875. The check to make sure the version Release.toml matched
the release version in Twoliter.toml could never succeed due to
quotation marks around the version string.

This fixes it and adds a test to prove that it works.
  • Loading branch information
webern committed Dec 8, 2023
1 parent e88ede9 commit ea64b72
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 1 deletion.
62 changes: 61 additions & 1 deletion twoliter/src/project.rs
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,8 @@ impl UnvalidatedProject {
return Ok(());
}
}
.to_string();
.as_str()
.context("The version in Release.toml is not a string")?;
ensure!(
version == self.release_version,
"The version found in Release.toml, '{version}', does not match the release-version \
Expand Down Expand Up @@ -328,4 +329,63 @@ mod test {
project.toolchain("aarch64").unwrap().to_string()
);
}

#[tokio::test]
async fn test_release_toml_check_error() {
let tempdir = TempDir::new().unwrap();
let p = tempdir.path();
let from = data_dir();
let twoliter_toml_from = from.join("Twoliter-1.toml");
let twoliter_toml_to = p.join("Twoliter.toml");
let release_toml_from = from.join("Release-2.toml");
let release_toml_to = p.join("Release.toml");
fs::copy(&twoliter_toml_from, &twoliter_toml_to)
.await
.expect(&format!(
"Unable to copy {} to {}",
twoliter_toml_from.display(),
twoliter_toml_to.display()
));
fs::copy(&release_toml_from, &release_toml_to)
.await
.expect(&format!(
"Unable to copy {} to {}",
release_toml_from.display(),
release_toml_to.display()
));
let result = Project::find_and_load(&p).await;
assert!(
result.is_err(),
"Expected the loading of the project to fail because of a mismatched version in \
Release.toml, but the project loaded without an error."
);
}

#[tokio::test]
async fn test_release_toml_check_ok() {
let tempdir = TempDir::new().unwrap();
let p = tempdir.path();
let from = data_dir();
let twoliter_toml_from = from.join("Twoliter-1.toml");
let twoliter_toml_to = p.join("Twoliter.toml");
let release_toml_from = from.join("Release-1.toml");
let release_toml_to = p.join("Release.toml");
fs::copy(&twoliter_toml_from, &twoliter_toml_to)
.await
.expect(&format!(
"Unable to copy {} to {}",
twoliter_toml_from.display(),
twoliter_toml_to.display()
));
fs::copy(&release_toml_from, &release_toml_to)
.await
.expect(&format!(
"Unable to copy {} to {}",
release_toml_from.display(),
release_toml_to.display()
));

// The project should load because Release.toml and Twoliter.toml versions match.
Project::find_and_load(&p).await.unwrap();
}
}
1 change: 1 addition & 0 deletions twoliter/src/test/data/Release-1.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
version = "1.0.0"
1 change: 1 addition & 0 deletions twoliter/src/test/data/Release-2.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
version = "2.0.0"

0 comments on commit ea64b72

Please sign in to comment.