From 7ef9fe3454f4a025c88884ce59e3b0b58af0cf97 Mon Sep 17 00:00:00 2001
From: Charles Hall <charles@computer.surgery>
Date: Wed, 12 Oct 2022 17:50:04 -0700
Subject: [PATCH] add regression tests

This way we don't regress on accident again in the future.
---
 src/service/admin/mod.rs | 32 ++++++++++++++++++++++++++++++++
 1 file changed, 32 insertions(+)

diff --git a/src/service/admin/mod.rs b/src/service/admin/mod.rs
index ad6d26b20..942df1c36 100644
--- a/src/service/admin/mod.rs
+++ b/src/service/admin/mod.rs
@@ -37,6 +37,7 @@
 
 use super::pdu::PduBuilder;
 
+#[cfg_attr(test, derive(Debug))]
 #[derive(Parser)]
 #[command(name = "@conduit:server.name:", version = env!("CARGO_PKG_VERSION"))]
 enum AdminCommand {
@@ -1160,3 +1161,34 @@ pub(crate) async fn make_user_admin(
         Ok(())
     }
 }
+
+#[cfg(test)]
+mod test {
+    use super::*;
+
+    #[test]
+    fn get_help_short() {
+        get_help_inner("-h");
+    }
+
+    #[test]
+    fn get_help_long() {
+        get_help_inner("--help");
+    }
+
+    #[test]
+    fn get_help_subcommand() {
+        get_help_inner("help");
+    }
+
+    fn get_help_inner(input: &str) {
+        let error = AdminCommand::try_parse_from(["argv[0] doesn't matter", input])
+            .unwrap_err()
+            .to_string();
+
+        // Search for a handful of keywords that suggest the help printed properly
+        assert!(error.contains("Usage:"));
+        assert!(error.contains("Commands:"));
+        assert!(error.contains("Options:"));
+    }
+}
-- 
GitLab