Skip to content

Commit

Permalink
test: Package default(), new() & tests
Browse files Browse the repository at this point in the history
Signed-off-by: Adam Perkowski <[email protected]>
  • Loading branch information
adamperkowski committed Nov 27, 2024
1 parent 712bcea commit ed3aaa4
Showing 1 changed file with 35 additions and 3 deletions.
38 changes: 35 additions & 3 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,36 @@ pub struct Package {
pub prefix: String,
}

// TODO: Package defaults & tests
impl Package {
pub fn new(source: String, target: String, use_max_tag: bool, prefix: String) -> error::Result<Self> {
let mut package = Package::default();

match source.as_ref() {
"aur" => Ok(package.aur = target),
"github" => Ok(package.github = target),
"gitlab" => Ok(package.gitlab = target),
_ => Err(error::Error::SourceNotFound(source.clone()))
}?;

package.source = source;
package.use_max_tag = Some(use_max_tag);
package.prefix = prefix;

Ok(package)
}

fn default() -> Self {
Package {
source: String::new(),
host: String::new(),
aur: String::new(),
github: String::new(),
gitlab: String::new(),
use_max_tag: None,
prefix: String::new(),
}
}

/// global function to get various API-specific agrs for a package
///
/// # example
Expand Down Expand Up @@ -156,8 +184,12 @@ mod tests {
async fn loading() {
let config = load(None).await.unwrap();

// TODO: here, ref L47

assert_eq!(config.1, PathBuf::from("nvrs.toml"));
}

#[tokio::test]
async fn manual_package() {
assert!(Package::new("non_existing_source".to_string(), "non_existing".to_string(), false, String::new()).is_err());
assert!(Package::new("github".to_string(), "orhun/git-cliff".to_string(), false, "v".to_string()).is_ok());
}
}

0 comments on commit ed3aaa4

Please sign in to comment.