Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 1 addition & 9 deletions src/addon/file_server/directory_entry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,7 @@ impl Ord for DirectoryEntry {

impl PartialOrd for DirectoryEntry {
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
if self.is_dir && other.is_dir {
return Some(self.display_name.cmp(&other.display_name));
}

if self.is_dir && !other.is_dir {
return Some(Ordering::Less);
}

Some(Ordering::Greater)
Some(self.cmp(other))
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/addon/file_server/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -328,14 +328,14 @@ mod tests {

#[test]
fn parse_req_uri_path() {
let have = vec![
let have = [
"/index.html",
"/index.html?foo=1234",
"/foo/index.html?bar=baz",
"/foo/bar/baz.html?day=6&month=27&year=2021",
];

let want = vec![
let want = [
"/index.html",
"/index.html",
"/foo/index.html",
Expand Down
107 changes: 60 additions & 47 deletions src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ pub struct Cli {

impl Cli {
pub fn from_str_args(args: Vec<&str>) -> Self {
Cli::from_iter_safe(args.into_iter()).unwrap_or_else(|e| e.exit())
Cli::from_iter_safe(args).unwrap_or_else(|e| e.exit())
}
}

Expand Down Expand Up @@ -107,9 +107,10 @@ mod tests {
#[test]
fn with_host() {
let from_args = Cli::from_str_args(vec!["http-server", "--host", "0.0.0.0"]);
let mut expect = Cli::default();

expect.host = "0.0.0.0".parse().unwrap();
let expect = Cli {
host: "0.0.0.0".parse().unwrap(),
..Default::default()
};

assert_eq!(from_args, expect);
}
Expand All @@ -123,40 +124,44 @@ mod tests {
"--port",
"54200",
]);
let mut expect = Cli::default();

expect.host = "192.168.0.1".parse().unwrap();
expect.port = 54200_u16;
let expect = Cli {
host: "192.168.0.1".parse().unwrap(),
port: 54200_u16,
..Default::default()
};

assert_eq!(from_args, expect);
}

#[test]
fn with_root_dir() {
let from_args = Cli::from_str_args(vec!["http-server", "~/User/sources/http-server"]);
let mut expect = Cli::default();

expect.root_dir = PathBuf::from_str("~/User/sources/http-server").unwrap();
let expect = Cli {
root_dir: PathBuf::from_str("~/User/sources/http-server").unwrap(),
..Default::default()
};

assert_eq!(from_args, expect);
}

#[test]
fn with_quiet() {
let from_args = Cli::from_str_args(vec!["http-server", "--quiet"]);
let mut expect = Cli::default();

expect.quiet = true;
let expect = Cli {
quiet: true,
..Default::default()
};

assert_eq!(from_args, expect);
}

#[test]
fn with_tls_no_config() {
let from_args = Cli::from_str_args(vec!["http-server", "--tls"]);
let mut expect = Cli::default();

expect.tls = true;
let expect = Cli {
tls: true,
..Default::default()
};

assert_eq!(from_args, expect);
}
Expand All @@ -173,32 +178,35 @@ mod tests {
"--tls-key-algorithm",
"rsa",
]);
let mut expect = Cli::default();

expect.tls = true;
expect.tls_cert = PathBuf::from_str("~/secrets/cert").unwrap();
expect.tls_key = PathBuf::from_str("~/secrets/key").unwrap();
expect.tls_key_algorithm = PrivateKeyAlgorithm::Rsa;
let expect = Cli {
tls: true,
tls_cert: PathBuf::from_str("~/secrets/cert").unwrap(),
tls_key: PathBuf::from_str("~/secrets/key").unwrap(),
tls_key_algorithm: PrivateKeyAlgorithm::Rsa,
..Default::default()
};

assert_eq!(from_args, expect);
}

#[test]
fn with_cors() {
let from_args = Cli::from_str_args(vec!["http-server", "--cors"]);
let mut expect = Cli::default();

expect.cors = true;
let expect = Cli {
cors: true,
..Default::default()
};

assert_eq!(from_args, expect);
}

#[test]
fn with_gzip() {
let from_args = Cli::from_str_args(vec!["http-server", "--gzip"]);
let mut expect = Cli::default();

expect.gzip = true;
let expect = Cli {
gzip: true,
..Default::default()
};

assert_eq!(from_args, expect);
}
Expand All @@ -212,52 +220,57 @@ mod tests {
"--password",
"Appleseed",
]);
let mut expect = Cli::default();

expect.username = Some(String::from("John"));
expect.password = Some(String::from("Appleseed"));
let expect = Cli {
username: Some(String::from("John")),
password: Some(String::from("Appleseed")),
..Default::default()
};

assert_eq!(from_args, expect);
}

#[test]
fn with_username_but_not_password() {
let from_args = Cli::from_str_args(vec!["http-server", "--username", "John"]);
let mut expect = Cli::default();

expect.username = Some(String::from("John"));
expect.password = None;
let expect = Cli {
username: Some(String::from("John")),
password: None,
..Default::default()
};

assert_eq!(from_args, expect);
}

#[test]
fn with_password_but_not_username() {
let from_args = Cli::from_str_args(vec!["http-server", "--password", "Appleseed"]);
let mut expect = Cli::default();

expect.username = None;
expect.password = Some(String::from("Appleseed"));
let expect = Cli {
username: None,
password: Some(String::from("Appleseed")),
..Default::default()
};

assert_eq!(from_args, expect);
}

#[test]
fn with_logger() {
let from_args = Cli::from_str_args(vec!["http-server", "--logger"]);
let mut expect = Cli::default();

expect.logger = true;
let expect = Cli {
logger: true,
..Default::default()
};

assert_eq!(from_args, expect);
}

#[test]
fn with_proxy() {
let from_args = Cli::from_str_args(vec!["http-server", "--proxy", "https://example.com"]);
let mut expect = Cli::default();

expect.proxy = Some(String::from("https://example.com"));
let expect = Cli {
proxy: Some(String::from("https://example.com")),
..Default::default()
};

assert_eq!(from_args, expect);
}
Expand Down