Radish alpha
h
Radicle Heartwood Protocol & Stack
Radicle
Git (anonymous pull)
Log in to clone via SSH
REVIEW: Add example values for --existing and unit tests
✗ CI failure Erik Kundt committed 8 months ago
commit 13a8391b6faebe43d7408703c6b608b8b213a5f2
parent eba641643d7d24967f4867f58277a5b376220542
1 failed (1 total) View logs
1 file changed +30 -0
modified crates/radicle-cli/src/commands/init/args.rs
@@ -39,6 +39,8 @@ pub struct Args {
    #[arg(long, conflicts_with = "private")]
    public: bool,
    /// Setup repository as an existing Radicle repository
+
    ///
+
    /// [example values: rad:z3Tr6bC7ctEg2EHmLvknUr29mEDLH, z3Tr6bC7ctEg2EHmLvknUr29mEDLH]
    #[arg(long, value_name = "RID")]
    pub(super) existing: Option<RepoId>,
    /// Setup the upstream of the default branch
@@ -109,3 +111,31 @@ impl clap::builder::TypedValueParser for ScopeParser {
        ))
    }
}
+

+
#[cfg(test)]
+
mod test {
+
    use super::Args;
+
    use clap::error::ErrorKind;
+
    use clap::Parser;
+

+
    #[test]
+
    fn should_parse_rid_non_urn() {
+
        let args = Args::try_parse_from(["init", "--existing", "z3Tr6bC7ctEg2EHmLvknUr29mEDLH"]);
+
        assert!(args.is_ok())
+
    }
+

+
    #[test]
+
    fn should_parse_rid_urn() {
+
        let args =
+
            Args::try_parse_from(["init", "--existing", "rad:z3Tr6bC7ctEg2EHmLvknUr29mEDLH"]);
+
        assert!(args.is_ok())
+
    }
+

+
    #[test]
+
    fn should_not_parse_rid_url() {
+
        let err =
+
            Args::try_parse_from(["init", "--existing", "rad://z3Tr6bC7ctEg2EHmLvknUr29mEDLH"])
+
                .unwrap_err();
+
        assert_eq!(err.kind(), ErrorKind::ValueValidation);
+
    }
+
}