mirror of
https://github.com/veeso/termscp.git
synced 2026-04-09 11:41:54 -07:00
test: extend config and explorer regression coverage
This commit is contained in:
@@ -442,6 +442,34 @@ mod tests {
|
|||||||
assert!(deserialize::<UserHosts>(Box::new(toml_file)).is_err());
|
assert!(deserialize::<UserHosts>(Box::new(toml_file)).is_err());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_should_deserialize_webdav_bookmark_protocol_alias() {
|
||||||
|
let toml_file: tempfile::NamedTempFile = create_http_alias_toml_bookmarks();
|
||||||
|
toml_file.as_file().sync_all().unwrap();
|
||||||
|
toml_file.as_file().rewind().unwrap();
|
||||||
|
|
||||||
|
let hosts: UserHosts = deserialize(Box::new(toml_file)).unwrap();
|
||||||
|
let host = hosts.bookmarks.get("webdav").unwrap();
|
||||||
|
|
||||||
|
assert_eq!(host.protocol, FileTransferProtocol::WebDAV);
|
||||||
|
assert_eq!(host.address.as_deref(), Some("https://myserver:4445"));
|
||||||
|
assert_eq!(host.username.as_deref(), Some("omar"));
|
||||||
|
assert_eq!(host.password.as_deref(), Some("mypassword"));
|
||||||
|
assert_eq!(
|
||||||
|
host.remote_path.as_deref(),
|
||||||
|
Some(std::path::Path::new("/myshare/dir/subdir"))
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_should_fail_deserialize_bookmark_with_invalid_protocol() {
|
||||||
|
let toml_file: tempfile::NamedTempFile = create_invalid_protocol_toml_bookmarks();
|
||||||
|
toml_file.as_file().sync_all().unwrap();
|
||||||
|
toml_file.as_file().rewind().unwrap();
|
||||||
|
|
||||||
|
assert!(deserialize::<UserHosts>(Box::new(toml_file)).is_err());
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_config_serializer_bookmarks_serializer_serialize() {
|
fn test_config_serializer_bookmarks_serializer_serialize() {
|
||||||
let mut bookmarks: HashMap<String, Bookmark> = HashMap::with_capacity(2);
|
let mut bookmarks: HashMap<String, Bookmark> = HashMap::with_capacity(2);
|
||||||
@@ -693,6 +721,39 @@ mod tests {
|
|||||||
tmpfile
|
tmpfile
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn create_http_alias_toml_bookmarks() -> tempfile::NamedTempFile {
|
||||||
|
let mut tmpfile: tempfile::NamedTempFile = tempfile::NamedTempFile::new().unwrap();
|
||||||
|
let file_content: &str = r#"
|
||||||
|
[bookmarks]
|
||||||
|
|
||||||
|
[bookmarks.webdav]
|
||||||
|
protocol = "HTTPS"
|
||||||
|
address = "https://myserver:4445"
|
||||||
|
username = "omar"
|
||||||
|
password = "mypassword"
|
||||||
|
directory = "/myshare/dir/subdir"
|
||||||
|
|
||||||
|
[recents]
|
||||||
|
"#;
|
||||||
|
tmpfile.write_all(file_content.as_bytes()).unwrap();
|
||||||
|
tmpfile
|
||||||
|
}
|
||||||
|
|
||||||
|
fn create_invalid_protocol_toml_bookmarks() -> tempfile::NamedTempFile {
|
||||||
|
let mut tmpfile: tempfile::NamedTempFile = tempfile::NamedTempFile::new().unwrap();
|
||||||
|
let file_content: &str = r#"
|
||||||
|
[bookmarks]
|
||||||
|
|
||||||
|
[bookmarks.broken]
|
||||||
|
protocol = "GOPHER"
|
||||||
|
address = "gopher://myserver"
|
||||||
|
|
||||||
|
[recents]
|
||||||
|
"#;
|
||||||
|
tmpfile.write_all(file_content.as_bytes()).unwrap();
|
||||||
|
tmpfile
|
||||||
|
}
|
||||||
|
|
||||||
fn create_good_toml_theme() -> tempfile::NamedTempFile {
|
fn create_good_toml_theme() -> tempfile::NamedTempFile {
|
||||||
let mut tmpfile: tempfile::NamedTempFile = tempfile::NamedTempFile::new().unwrap();
|
let mut tmpfile: tempfile::NamedTempFile = tempfile::NamedTempFile::new().unwrap();
|
||||||
let file_content: &str = r##"auth_address = "Yellow"
|
let file_content: &str = r##"auth_address = "Yellow"
|
||||||
|
|||||||
@@ -1026,6 +1026,27 @@ mod tests {
|
|||||||
assert_eq!(formatter.fmt(&entry).as_str(), "喵喵喵喵喵喵喵…");
|
assert_eq!(formatter.fmt(&entry).as_str(), "喵喵喵喵喵喵喵…");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn should_ignore_unknown_formatter_keys() {
|
||||||
|
let entry = File {
|
||||||
|
path: PathBuf::from("/tmp/foo.txt"),
|
||||||
|
metadata: Metadata {
|
||||||
|
accessed: None,
|
||||||
|
created: None,
|
||||||
|
modified: None,
|
||||||
|
file_type: FileType::File,
|
||||||
|
size: 8192,
|
||||||
|
symlink: None,
|
||||||
|
uid: None,
|
||||||
|
gid: None,
|
||||||
|
mode: None,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
let formatter: Formatter = Formatter::new("before {UNKNOWN:12} after {NAME:8}");
|
||||||
|
|
||||||
|
assert_eq!(formatter.fmt(&entry).as_str(), "before after foo.txt ");
|
||||||
|
}
|
||||||
|
|
||||||
/// Dummy formatter, just yelds an 'A' at the end of the current string
|
/// Dummy formatter, just yelds an 'A' at the end of the current string
|
||||||
fn dummy_fmt(
|
fn dummy_fmt(
|
||||||
_fmt: &Formatter,
|
_fmt: &Formatter,
|
||||||
|
|||||||
Reference in New Issue
Block a user