diff options
Diffstat (limited to 'tests/migrations.rs')
| -rw-r--r-- | tests/migrations.rs | 82 |
1 files changed, 82 insertions, 0 deletions
diff --git a/tests/migrations.rs b/tests/migrations.rs index b91972c..1856b38 100644 --- a/tests/migrations.rs +++ b/tests/migrations.rs @@ -248,3 +248,85 @@ fn what_is_kept() { .is_empty() ); } + +/// A generation that adds a required slot: the switch is refused until a submission +/// for it is staged, which changes nothing the running generation serves; a submission +/// under the running generation keeps the staged entry; the switch brings it. And a +/// first deployment, without any state. +#[test] +fn staging_for_the_next_generation() { + let host = Host::new("stage"); + let s1_value = secrets( + json!({ "a": { "type": "application/octet-stream" } }), + json!({ "a": { "from": ["secrets/a"] } }), + ); + let s1 = host.schema(s1_value.clone()); + assert!(host.apply(&s1, &rotate(&host, "a", "a", b"A")).accepted); + let reactions_before = host.reactions(); + let s2_value = secrets( + json!({ + "a": { "type": "application/octet-stream" }, + "b.key": { "type": "application/octet-stream", "secret": true } + }), + json!({ + "a": { "from": ["secrets/a"] }, + "b.key": { "from": ["secrets/b.key"], "reactions": { "restart": ["b.service"] } } + }), + ); + let s2 = host.schema(s2_value.clone()); + assert_eq!( + host.migrate(&s2, true).refused, + ["required slot secrets/b.key can't be filled"] + ); + + // Staged: the snapshot, under S2; no views, no reactions. + let plan = host.stage(&s2, &rotate(&host, "b", "b.key", b"B")); + assert!( + plan.accepted && plan.staged && plan.snapshot.is_some(), + "{plan:?}" + ); + assert!(host.view("b.key", "b.key").is_none()); + assert_eq!(host.view("a", "a").unwrap(), b"A"); + assert_eq!(host.reactions(), reactions_before); + assert_eq!( + host.store().current("secrets").unwrap().unwrap().schema, + s2.1 + ); + assert!(host.migrate(&s2, true).accepted); + + // The running generation goes on: what it has no slot for is kept. + let s1 = host.schema(s1_value); + let plan = host.apply(&s1, &rotate(&host, "a2", "a", b"A2")); + assert_eq!( + plan.warnings, + ["kept, in no slot of the schema: secrets/b.key"] + ); + + // The switch: the staged entry is there, with its view and reaction. + let s2 = host.schema(s2_value.clone()); + let migration = host.migrate(&s2, false); + assert!(migration.accepted, "{migration:?}"); + assert_eq!(host.view("b.key", "b.key").unwrap(), b"B"); + assert_eq!(host.view("a", "a").unwrap(), b"A2"); + assert!( + host.reactions() + .contains("--no-block try-restart b.service") + ); + + // A first deployment: no state, no views; staged, then switched to. + let fresh = Host::new("stage-first"); + let s2 = fresh.schema(s2_value); + let first = fresh.submission( + "first", + json!({ "channel": "secrets", "complete": true, "items": [ + { "address": "secrets/a", "op": "set" }, + { "address": "secrets/b.key", "op": "set" } + ] }), + &[("secrets/a", b"A"), ("secrets/b.key", b"B")], + ); + let plan = fresh.stage(&s2, &first); + assert!(plan.accepted && plan.snapshot.is_some(), "{plan:?}"); + assert!(fresh.view("a", "a").is_none()); + assert!(fresh.migrate(&s2, false).accepted); + assert_eq!(fresh.view("b.key", "b.key").unwrap(), b"B"); +} |
