Skip to content

Commit ad5e0d3

Browse files
authored
[2/n] add tests for duplicate control plane zones and artifacts
We already have code which ensures that duplicate zones and artifacts are detected. Add tests to exercise these code paths (we're going to hoist them to a higher level in a subsequent commit). While writing this code, I realized that we don't exit with code 0 when encountering duplicate artifacts. That's not good. I'll fix it in a subsequent commit. Reviewers: iliana Reviewed By: iliana Pull Request: #18
1 parent 69ca562 commit ad5e0d3

File tree

3 files changed

+88
-0
lines changed

3 files changed

+88
-0
lines changed
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# This manifest contains two artifacts with the same name and version, which
2+
# will hash to the same value.
3+
4+
system_version = "1.0.0"
5+
6+
[[artifact.gimlet_sp]]
7+
name = "fake-gimlet-sp"
8+
version = "1.0.0"
9+
source = { kind = "fake", size = "1MiB" }
10+
11+
[[artifact.gimlet_sp]]
12+
name = "fake-gimlet-sp"
13+
version = "1.0.0"
14+
source = { kind = "fake", size = "1MiB" }
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# This manifest has two control plane zones that hash to the same contents. This
2+
# is not allowed.
3+
4+
system_version = "1.0.0"
5+
6+
[[artifact.control_plane]]
7+
name = "fake-control-plane"
8+
version = "1.0.0"
9+
[artifact.control_plane.source]
10+
kind = "composite-control-plane"
11+
zones = [
12+
{ kind = "fake", name = "zone1", size = "1MiB" },
13+
{ kind = "fake", name = "zone1", size = "1MiB" },
14+
]

bin/tests/integration-tests/command_tests.rs

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,66 @@ fn test_assemble_fake_non_semver() -> Result<()> {
223223
Ok(())
224224
}
225225

226+
#[test]
227+
fn test_assemble_duplicate_zone() -> Result<()> {
228+
let log_config = ConfigLogging::File {
229+
level: ConfigLoggingLevel::Trace,
230+
path: "UNUSED".into(),
231+
if_exists: ConfigLoggingIfExists::Fail,
232+
};
233+
let logctx = LogContext::new("test_assemble_duplicate_zone", &log_config);
234+
let tempdir = tempfile::tempdir().unwrap();
235+
let key = Key::generate_ed25519()?;
236+
237+
let archive_path = tempdir.path().join("archive.zip");
238+
239+
let mut cmd = make_cmd(&key);
240+
cmd.args([
241+
"assemble",
242+
"--skip-all-present",
243+
"invalid-manifests/duplicate-zone.toml",
244+
]);
245+
cmd.arg(&archive_path);
246+
cmd.assert().failure().stderr(predicate::str::contains(
247+
"duplicate zones are not allowed \
248+
(zone1.tar.gz and zone1.tar.gz have the same checksum)",
249+
));
250+
251+
logctx.cleanup_successful();
252+
Ok(())
253+
}
254+
255+
#[test]
256+
fn test_assemble_duplicate_artifact() -> Result<()> {
257+
let log_config = ConfigLogging::File {
258+
level: ConfigLoggingLevel::Trace,
259+
path: "UNUSED".into(),
260+
if_exists: ConfigLoggingIfExists::Fail,
261+
};
262+
let logctx =
263+
LogContext::new("test_assemble_duplicate_artifact", &log_config);
264+
let tempdir = tempfile::tempdir().unwrap();
265+
let key = Key::generate_ed25519()?;
266+
267+
let archive_path = tempdir.path().join("archive.zip");
268+
269+
let mut cmd = make_cmd(&key);
270+
cmd.args([
271+
"assemble",
272+
"--skip-all-present",
273+
"invalid-manifests/duplicate-artifact.toml",
274+
]);
275+
cmd.arg(&archive_path);
276+
// TODO: this should be failure, not success!
277+
cmd.assert().success().stderr(predicate::str::contains(
278+
"a target named gimlet_sp-fake-gimlet-sp-1.0.0.tar.gz \
279+
already exists in the repository",
280+
));
281+
282+
logctx.cleanup_successful();
283+
Ok(())
284+
}
285+
226286
fn make_cmd(key: &Key) -> Command {
227287
let mut cmd = Command::cargo_bin("tufaceous").unwrap();
228288
cmd.env("TUFACEOUS_KEY", key.to_string());

0 commit comments

Comments
 (0)