aboutsummaryrefslogtreecommitdiff
path: root/src/garage/tests/common/ext
diff options
context:
space:
mode:
authorJill <kokakiwi@deuxfleurs.fr>2022-02-02 15:35:52 +0100
committerJill <kokakiwi@deuxfleurs.fr>2022-02-10 17:55:49 +0100
commitdd407e7041102f52611336bef304c3266a4d6fbe (patch)
tree01582c8158cdfc19a46288e04ea53da95da5a64a /src/garage/tests/common/ext
parentaf261e17895d5d3b3bd0bdfd52b3d0db6a984a20 (diff)
downloadgarage-dd407e7041102f52611336bef304c3266a4d6fbe.tar.gz
garage-dd407e7041102f52611336bef304c3266a4d6fbe.zip
tests: Add garage integration tests (base)
Diffstat (limited to 'src/garage/tests/common/ext')
-rw-r--r--src/garage/tests/common/ext/mod.rs3
-rw-r--r--src/garage/tests/common/ext/process.rs55
2 files changed, 58 insertions, 0 deletions
diff --git a/src/garage/tests/common/ext/mod.rs b/src/garage/tests/common/ext/mod.rs
new file mode 100644
index 00000000..6090dd96
--- /dev/null
+++ b/src/garage/tests/common/ext/mod.rs
@@ -0,0 +1,3 @@
+pub use process::*;
+
+mod process;
diff --git a/src/garage/tests/common/ext/process.rs b/src/garage/tests/common/ext/process.rs
new file mode 100644
index 00000000..ba533b6c
--- /dev/null
+++ b/src/garage/tests/common/ext/process.rs
@@ -0,0 +1,55 @@
+use std::process;
+
+pub trait CommandExt {
+ fn quiet(&mut self) -> &mut Self;
+
+ fn expect_success_status(&mut self, msg: &str) -> process::ExitStatus;
+ fn expect_success_output(&mut self, msg: &str) -> process::Output;
+}
+
+impl CommandExt for process::Command {
+ fn quiet(&mut self) -> &mut Self {
+ self.stdout(process::Stdio::null())
+ .stderr(process::Stdio::null())
+ }
+
+ fn expect_success_status(&mut self, msg: &str) -> process::ExitStatus {
+ let status = self.status().expect(msg);
+ status.expect_success(msg);
+ status
+ }
+ fn expect_success_output(&mut self, msg: &str) -> process::Output {
+ let output = self.output().expect(msg);
+ output.expect_success(msg);
+ output
+ }
+}
+
+pub trait OutputExt {
+ fn expect_success(&self, msg: &str);
+}
+
+impl OutputExt for process::Output {
+ fn expect_success(&self, msg: &str) {
+ self.status.expect_success(msg)
+ }
+}
+
+pub trait ExitStatusExt {
+ fn expect_success(&self, msg: &str);
+}
+
+impl ExitStatusExt for process::ExitStatus {
+ fn expect_success(&self, msg: &str) {
+ if !self.success() {
+ match self.code() {
+ Some(code) => panic!(
+ "Command exited with code {code}: {msg}",
+ code = code,
+ msg = msg
+ ),
+ None => panic!("Command exited with signal: {msg}", msg = msg),
+ }
+ }
+ }
+}