aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/migrations.rs63
1 files changed, 62 insertions, 1 deletions
diff --git a/tests/migrations.rs b/tests/migrations.rs
index c892f72..18451a7 100644
--- a/tests/migrations.rs
+++ b/tests/migrations.rs
@@ -401,13 +401,74 @@ fn incoming_submissions() {
let check = host.migrate(&s2, true);
assert!(!check.accepted);
assert!(
- check.refused[0].starts_with("incoming 4: required item secrets/nope"),
+ check.refused[0].starts_with("incoming 4 (")
+ && check.refused[0].contains("/state/incoming/4): required item secrets/nope"),
"{check:?}"
);
assert!(host.root.join("state/incoming/4").exists());
+ // Waiting, and refused by the running generation: --status says so, and why.
+ let (code, stdout) = enstate(&host, &["--status", "--json"]);
+ assert_eq!(code, Some(1));
+ let status: Value = serde_json::from_str(&stdout).unwrap();
+ assert_eq!(status["incoming"][0]["name"], json!("4"));
+ assert_eq!(status["incoming"][0]["refused"], json!(true));
+ assert!(
+ status["incoming"][0]["reasons"][0]
+ .as_str()
+ .unwrap()
+ .contains("secrets/nope")
+ );
let migration = host.migrate(&s2, false);
assert!(!migration.accepted);
assert!(host.root.join("state/refused/4").exists());
+ // Visible, with why and when: in the store, and by --status, which exits with 1.
+ let refusals = host.store().refused().unwrap();
+ assert_eq!(refusals.len(), 1);
+ assert_eq!(refusals[0].name, "4");
+ assert!(
+ refusals[0].reasons[0].contains("secrets/nope"),
+ "{refusals:?}"
+ );
+ assert!(
+ refusals[0].at.ends_with('Z') && refusals[0].at.len() == 20,
+ "{refusals:?}"
+ );
+ let (code, stdout) = enstate(&host, &["--status", "--json"]);
+ assert_eq!(code, Some(1));
+ let output = stdout;
+ let status: Value = serde_json::from_str(&output).unwrap();
+ assert_eq!(status["attention"], json!(true));
+ assert_eq!(status["refused"][0]["name"], json!("4"));
assert!(!host.root.join("state/incoming/4").exists());
assert_eq!(host.view("a", "a").unwrap(), b"C");
+ // Forgotten, and nothing needs attention any more.
+ let (code, stdout) = enstate(&host, &["--forget", "4"]);
+ assert_eq!(code, Some(0), "{stdout}");
+ assert!(!host.root.join("state/refused/4").exists());
+ assert!(!host.root.join("state/refused/4.json").exists());
+ let (code, _) = enstate(&host, &["--status"]);
+ assert_eq!(code, Some(0));
+ let (code, _) = enstate(&host, &["--forget", "4"]);
+ assert_eq!(code, Some(2));
+}
+
+/// Runs enstate on `host`'s store with `arguments`: its exit status and output.
+fn enstate(host: &Host, arguments: &[&str]) -> (Option<i32>, String) {
+ let mut command = std::process::Command::new(env!("CARGO_BIN_EXE_enstate"));
+ command
+ .args(arguments)
+ .arg(format!("--state-dir={}", host.root.join("state").display()));
+ if arguments[0] != "--forget" {
+ command
+ .arg(format!("--run-dir={}", host.root.join("run").display()))
+ .arg(format!(
+ "--schema={}",
+ host.root.join("schema.json").display()
+ ));
+ }
+ let output = command.output().unwrap();
+ (
+ output.status.code(),
+ String::from_utf8_lossy(&output.stdout).into_owned(),
+ )
}