more tests
This commit is contained in:
parent
970096b3d4
commit
2002682937
31
src/main.rs
31
src/main.rs
@ -3,7 +3,7 @@ mod github;
|
||||
use github::{AssetUploader, Release, Releaser};
|
||||
use reqwest::Client;
|
||||
use serde::Deserialize;
|
||||
use std::{error::Error, fs::File};
|
||||
use std::{error::Error, fs::File, path::Path};
|
||||
|
||||
#[derive(Deserialize, Default)]
|
||||
struct Config {
|
||||
@ -29,10 +29,20 @@ fn release(conf: &Config) -> Release {
|
||||
}
|
||||
}
|
||||
|
||||
fn is_tag<R>(gitref: R) -> bool where R: AsRef<str> {
|
||||
fn is_tag<R>(gitref: R) -> bool
|
||||
where
|
||||
R: AsRef<str>,
|
||||
{
|
||||
gitref.as_ref().starts_with("refs/tags/")
|
||||
}
|
||||
|
||||
fn mime_or_default<P>(path: P) -> mime::Mime
|
||||
where
|
||||
P: AsRef<Path>,
|
||||
{
|
||||
mime_guess::from_path(path).first_or(mime::APPLICATION_OCTET_STREAM)
|
||||
}
|
||||
|
||||
fn run(
|
||||
conf: Config,
|
||||
releaser: &dyn Releaser,
|
||||
@ -53,13 +63,11 @@ fn run(
|
||||
for pattern in patterns {
|
||||
for path in glob::glob(pattern.as_str())? {
|
||||
let resolved = path?;
|
||||
let mime =
|
||||
mime_guess::from_path(&resolved).first_or(mime::APPLICATION_OCTET_STREAM);
|
||||
uploader.upload(
|
||||
conf.github_token.as_str(),
|
||||
conf.github_repository.as_str(),
|
||||
release_id,
|
||||
mime,
|
||||
mime_or_default(&resolved),
|
||||
File::open(resolved)?,
|
||||
)?;
|
||||
}
|
||||
@ -78,6 +86,14 @@ fn main() -> Result<(), Box<dyn Error>> {
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
#[test]
|
||||
fn mime_or_default_defaults_to_octect_stream() {
|
||||
assert_eq!(
|
||||
mime_or_default("umbiguous-file"),
|
||||
mime::APPLICATION_OCTET_STREAM
|
||||
)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn release_constructs_a_release_from_a_config() -> Result<(), Box<dyn Error>> {
|
||||
for (conf, expect) in vec![(Config::default(), Release::default())] {
|
||||
@ -88,10 +104,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn is_tag_checks_refs() {
|
||||
for (gitref, expect) in &[
|
||||
("refs/tags/foo", true),
|
||||
("refs/heads/master", false)
|
||||
] {
|
||||
for (gitref, expect) in &[("refs/tags/foo", true), ("refs/heads/master", false)] {
|
||||
assert_eq!(is_tag(gitref), *expect)
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user