aboutsummaryrefslogtreecommitdiffstats
path: root/tests/migrations.rs
diff options
context:
space:
mode:
Diffstat (limited to 'tests/migrations.rs')
-rw-r--r--tests/migrations.rs70
1 files changed, 70 insertions, 0 deletions
diff --git a/tests/migrations.rs b/tests/migrations.rs
index 1856b38..05e3099 100644
--- a/tests/migrations.rs
+++ b/tests/migrations.rs
@@ -293,6 +293,8 @@ fn staging_for_the_next_generation() {
s2.1
);
assert!(host.migrate(&s2, true).accepted);
+ // A marker, for the next switch to serve the views; a dry run leaves it.
+ assert!(host.root.join("state/migrate-due").exists());
// The running generation goes on: what it has no slot for is kept.
let s1 = host.schema(s1_value);
@@ -312,6 +314,7 @@ fn staging_for_the_next_generation() {
host.reactions()
.contains("--no-block try-restart b.service")
);
+ assert!(!host.root.join("state/migrate-due").exists());
// A first deployment: no state, no views; staged, then switched to.
let fresh = Host::new("stage-first");
@@ -330,3 +333,70 @@ fn staging_for_the_next_generation() {
assert!(fresh.migrate(&s2, false).accepted);
assert_eq!(fresh.view("b.key", "b.key").unwrap(), b"B");
}
+
+/// Submissions waiting in the incoming directory: planned against the next
+/// generation's schema by the check before the switch (on a copy, changing nothing),
+/// and taken by the switch, before the views; one refused refuses the switch, and is
+/// moved aside.
+#[test]
+fn incoming_submissions() {
+ let host = Host::new("incoming");
+ let s2 = host.schema(secrets(
+ json!({ "a": { "type": "application/octet-stream" } }),
+ json!({ "a": { "from": ["secrets/a"], "reactions": { "restart": ["a.service"] } } }),
+ ));
+ let put = |name: &str, dir: &std::path::Path| {
+ let incoming = host.root.join("state/incoming");
+ std::fs::create_dir_all(&incoming).unwrap();
+ std::fs::rename(dir, incoming.join(name)).unwrap();
+ };
+ // A first deployment: nothing but a waiting submission.
+ put("1", &rotate(&host, "first", "a", b"A"));
+ let check = host.migrate(&s2, true);
+ assert!(check.accepted, "{check:?}");
+ assert!(check.incoming[0].plan.as_ref().unwrap().accepted);
+ assert!(host.snapshot("secrets").is_none());
+ assert!(host.root.join("state/incoming/1").exists());
+ // The dry run's copy of the snapshots is gone.
+ assert_eq!(
+ std::fs::read_dir(host.root.join("run/tmp"))
+ .unwrap()
+ .count(),
+ 0
+ );
+ // The switch.
+ let migration = host.migrate(&s2, false);
+ assert!(migration.accepted, "{migration:?}");
+ assert_eq!(host.view("a", "a").unwrap(), b"A");
+ assert!(host.snapshot("secrets").is_some());
+ assert!(!host.root.join("state/incoming/1").exists());
+
+ // Two in order, the second building on what the first makes; then one refused,
+ // which refuses the switch, and is moved aside by it.
+ put("2", &rotate(&host, "second", "a", b"B"));
+ put("3", &rotate(&host, "third", "a", b"C"));
+ let migration = host.migrate(&s2, false);
+ assert!(
+ migration.accepted && migration.incoming.len() == 2,
+ "{migration:?}"
+ );
+ assert_eq!(host.view("a", "a").unwrap(), b"C");
+ let bad = host.submission(
+ "bad",
+ json!({ "channel": "secrets", "items": [{ "address": "secrets/nope", "op": "set" }] }),
+ &[("secrets/nope", b"x")],
+ );
+ put("4", &bad);
+ let check = host.migrate(&s2, true);
+ assert!(!check.accepted);
+ assert!(
+ check.refused[0].starts_with("incoming 4: required item secrets/nope"),
+ "{check:?}"
+ );
+ assert!(host.root.join("state/incoming/4").exists());
+ let migration = host.migrate(&s2, false);
+ assert!(!migration.accepted);
+ assert!(host.root.join("state/refused/4").exists());
+ assert!(!host.root.join("state/incoming/4").exists());
+ assert_eq!(host.view("a", "a").unwrap(), b"C");
+}