mirror of
https://github.com/amigan/rustypaste-pretty.git
synced 2024-11-21 03:49:47 -05:00
test(project): add tests
This commit is contained in:
parent
f67e611781
commit
4c988a446d
6 changed files with 235 additions and 25 deletions
115
Cargo.lock
generated
115
Cargo.lock
generated
|
@ -14,7 +14,7 @@ dependencies = [
|
||||||
"futures-sink",
|
"futures-sink",
|
||||||
"log",
|
"log",
|
||||||
"pin-project 0.4.28",
|
"pin-project 0.4.28",
|
||||||
"tokio",
|
"tokio 0.2.25",
|
||||||
"tokio-util",
|
"tokio-util",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
@ -25,7 +25,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "177837a10863f15ba8d3ae3ec12fac1099099529ed20083a27fdfe247381d0dc"
|
checksum = "177837a10863f15ba8d3ae3ec12fac1099099529ed20083a27fdfe247381d0dc"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"actix-codec",
|
"actix-codec",
|
||||||
"actix-rt",
|
"actix-rt 1.1.1",
|
||||||
"actix-service",
|
"actix-service",
|
||||||
"actix-utils",
|
"actix-utils",
|
||||||
"derive_more",
|
"derive_more",
|
||||||
|
@ -65,7 +65,7 @@ checksum = "452299e87817ae5673910e53c243484ca38be3828db819b6011736fc6982e874"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"actix-codec",
|
"actix-codec",
|
||||||
"actix-connect",
|
"actix-connect",
|
||||||
"actix-rt",
|
"actix-rt 1.1.1",
|
||||||
"actix-service",
|
"actix-service",
|
||||||
"actix-threadpool",
|
"actix-threadpool",
|
||||||
"actix-utils",
|
"actix-utils",
|
||||||
|
@ -114,6 +114,16 @@ dependencies = [
|
||||||
"syn",
|
"syn",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "actix-macros"
|
||||||
|
version = "0.2.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "c2f86cd6857c135e6e9fe57b1619a88d1f94a7df34c00e11fe13e64fd3438837"
|
||||||
|
dependencies = [
|
||||||
|
"quote",
|
||||||
|
"syn",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "actix-multipart"
|
name = "actix-multipart"
|
||||||
version = "0.3.0"
|
version = "0.3.0"
|
||||||
|
@ -151,13 +161,24 @@ version = "1.1.1"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "143fcc2912e0d1de2bcf4e2f720d2a60c28652ab4179685a1ee159e0fb3db227"
|
checksum = "143fcc2912e0d1de2bcf4e2f720d2a60c28652ab4179685a1ee159e0fb3db227"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"actix-macros",
|
"actix-macros 0.1.3",
|
||||||
"actix-threadpool",
|
"actix-threadpool",
|
||||||
"copyless",
|
"copyless",
|
||||||
"futures-channel",
|
"futures-channel",
|
||||||
"futures-util",
|
"futures-util",
|
||||||
"smallvec",
|
"smallvec",
|
||||||
"tokio",
|
"tokio 0.2.25",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "actix-rt"
|
||||||
|
version = "2.2.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "bc7d7cd957c9ed92288a7c3c96af81fa5291f65247a76a34dac7b6af74e52ba0"
|
||||||
|
dependencies = [
|
||||||
|
"actix-macros 0.2.1",
|
||||||
|
"futures-core",
|
||||||
|
"tokio 1.9.0",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
@ -167,13 +188,13 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "45407e6e672ca24784baa667c5d32ef109ccdd8d5e0b5ebb9ef8a67f4dfb708e"
|
checksum = "45407e6e672ca24784baa667c5d32ef109ccdd8d5e0b5ebb9ef8a67f4dfb708e"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"actix-codec",
|
"actix-codec",
|
||||||
"actix-rt",
|
"actix-rt 1.1.1",
|
||||||
"actix-service",
|
"actix-service",
|
||||||
"actix-utils",
|
"actix-utils",
|
||||||
"futures-channel",
|
"futures-channel",
|
||||||
"futures-util",
|
"futures-util",
|
||||||
"log",
|
"log",
|
||||||
"mio",
|
"mio 0.6.23",
|
||||||
"mio-uds",
|
"mio-uds",
|
||||||
"num_cpus",
|
"num_cpus",
|
||||||
"slab",
|
"slab",
|
||||||
|
@ -196,8 +217,8 @@ version = "1.0.1"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "47239ca38799ab74ee6a8a94d1ce857014b2ac36f242f70f3f75a66f691e791c"
|
checksum = "47239ca38799ab74ee6a8a94d1ce857014b2ac36f242f70f3f75a66f691e791c"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"actix-macros",
|
"actix-macros 0.1.3",
|
||||||
"actix-rt",
|
"actix-rt 1.1.1",
|
||||||
"actix-server",
|
"actix-server",
|
||||||
"actix-service",
|
"actix-service",
|
||||||
"log",
|
"log",
|
||||||
|
@ -238,7 +259,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "2e9022dec56632d1d7979e59af14f0597a28a830a9c1c7fec8b2327eb9f16b5a"
|
checksum = "2e9022dec56632d1d7979e59af14f0597a28a830a9c1c7fec8b2327eb9f16b5a"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"actix-codec",
|
"actix-codec",
|
||||||
"actix-rt",
|
"actix-rt 1.1.1",
|
||||||
"actix-service",
|
"actix-service",
|
||||||
"bitflags",
|
"bitflags",
|
||||||
"bytes 0.5.6",
|
"bytes 0.5.6",
|
||||||
|
@ -259,9 +280,9 @@ checksum = "e641d4a172e7faa0862241a20ff4f1f5ab0ab7c279f00c2d4587b77483477b86"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"actix-codec",
|
"actix-codec",
|
||||||
"actix-http",
|
"actix-http",
|
||||||
"actix-macros",
|
"actix-macros 0.1.3",
|
||||||
"actix-router",
|
"actix-router",
|
||||||
"actix-rt",
|
"actix-rt 1.1.1",
|
||||||
"actix-server",
|
"actix-server",
|
||||||
"actix-service",
|
"actix-service",
|
||||||
"actix-testing",
|
"actix-testing",
|
||||||
|
@ -358,7 +379,7 @@ checksum = "b381e490e7b0cfc37ebc54079b0413d8093ef43d14a4e4747083f7fa47a9e691"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"actix-codec",
|
"actix-codec",
|
||||||
"actix-http",
|
"actix-http",
|
||||||
"actix-rt",
|
"actix-rt 1.1.1",
|
||||||
"actix-service",
|
"actix-service",
|
||||||
"base64",
|
"base64",
|
||||||
"bytes 0.5.6",
|
"bytes 0.5.6",
|
||||||
|
@ -814,7 +835,7 @@ dependencies = [
|
||||||
"http",
|
"http",
|
||||||
"indexmap",
|
"indexmap",
|
||||||
"slab",
|
"slab",
|
||||||
"tokio",
|
"tokio 0.2.25",
|
||||||
"tokio-util",
|
"tokio-util",
|
||||||
"tracing",
|
"tracing",
|
||||||
"tracing-futures",
|
"tracing-futures",
|
||||||
|
@ -1075,12 +1096,25 @@ dependencies = [
|
||||||
"kernel32-sys",
|
"kernel32-sys",
|
||||||
"libc",
|
"libc",
|
||||||
"log",
|
"log",
|
||||||
"miow",
|
"miow 0.2.2",
|
||||||
"net2",
|
"net2",
|
||||||
"slab",
|
"slab",
|
||||||
"winapi 0.2.8",
|
"winapi 0.2.8",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "mio"
|
||||||
|
version = "0.7.13"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "8c2bdb6314ec10835cd3293dd268473a835c02b7b352e788be788b3c6ca6bb16"
|
||||||
|
dependencies = [
|
||||||
|
"libc",
|
||||||
|
"log",
|
||||||
|
"miow 0.3.7",
|
||||||
|
"ntapi",
|
||||||
|
"winapi 0.3.9",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "mio-uds"
|
name = "mio-uds"
|
||||||
version = "0.6.8"
|
version = "0.6.8"
|
||||||
|
@ -1089,7 +1123,7 @@ checksum = "afcb699eb26d4332647cc848492bbc15eafb26f08d0304550d5aa1f612e066f0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"iovec",
|
"iovec",
|
||||||
"libc",
|
"libc",
|
||||||
"mio",
|
"mio 0.6.23",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
@ -1104,6 +1138,15 @@ dependencies = [
|
||||||
"ws2_32-sys",
|
"ws2_32-sys",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "miow"
|
||||||
|
version = "0.3.7"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "b9f1c5b025cda876f66ef43a113f91ebc9f4ccef34843000e0adf6ebbab84e21"
|
||||||
|
dependencies = [
|
||||||
|
"winapi 0.3.9",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "net2"
|
name = "net2"
|
||||||
version = "0.2.37"
|
version = "0.2.37"
|
||||||
|
@ -1136,6 +1179,15 @@ dependencies = [
|
||||||
"version_check 0.9.3",
|
"version_check 0.9.3",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "ntapi"
|
||||||
|
version = "0.3.6"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "3f6bb902e437b6d86e03cce10a7e2af662292c5dfef23b65899ea3ac9354ad44"
|
||||||
|
dependencies = [
|
||||||
|
"winapi 0.3.9",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "num-traits"
|
name = "num-traits"
|
||||||
version = "0.1.43"
|
version = "0.1.43"
|
||||||
|
@ -1164,12 +1216,19 @@ dependencies = [
|
||||||
"libc",
|
"libc",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "once_cell"
|
||||||
|
version = "1.8.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "692fcb63b64b1758029e0a96ee63e049ce8c5948587f2f7208df04625e5f6b56"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "oops"
|
name = "oops"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"actix-files",
|
"actix-files",
|
||||||
"actix-multipart",
|
"actix-multipart",
|
||||||
|
"actix-rt 2.2.0",
|
||||||
"actix-web",
|
"actix-web",
|
||||||
"byte-unit",
|
"byte-unit",
|
||||||
"config",
|
"config",
|
||||||
|
@ -1823,7 +1882,7 @@ dependencies = [
|
||||||
"lazy_static",
|
"lazy_static",
|
||||||
"libc",
|
"libc",
|
||||||
"memchr",
|
"memchr",
|
||||||
"mio",
|
"mio 0.6.23",
|
||||||
"mio-uds",
|
"mio-uds",
|
||||||
"pin-project-lite 0.1.12",
|
"pin-project-lite 0.1.12",
|
||||||
"signal-hook-registry",
|
"signal-hook-registry",
|
||||||
|
@ -1831,6 +1890,22 @@ dependencies = [
|
||||||
"winapi 0.3.9",
|
"winapi 0.3.9",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "tokio"
|
||||||
|
version = "1.9.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "4b7b349f11a7047e6d1276853e612d152f5e8a352c61917887cc2169e2366b4c"
|
||||||
|
dependencies = [
|
||||||
|
"autocfg",
|
||||||
|
"libc",
|
||||||
|
"mio 0.7.13",
|
||||||
|
"once_cell",
|
||||||
|
"parking_lot",
|
||||||
|
"pin-project-lite 0.2.7",
|
||||||
|
"signal-hook-registry",
|
||||||
|
"winapi 0.3.9",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "tokio-util"
|
name = "tokio-util"
|
||||||
version = "0.3.1"
|
version = "0.3.1"
|
||||||
|
@ -1842,7 +1917,7 @@ dependencies = [
|
||||||
"futures-sink",
|
"futures-sink",
|
||||||
"log",
|
"log",
|
||||||
"pin-project-lite 0.1.12",
|
"pin-project-lite 0.1.12",
|
||||||
"tokio",
|
"tokio 0.2.25",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
@ -1901,7 +1976,7 @@ dependencies = [
|
||||||
"rand 0.7.3",
|
"rand 0.7.3",
|
||||||
"smallvec",
|
"smallvec",
|
||||||
"thiserror",
|
"thiserror",
|
||||||
"tokio",
|
"tokio 0.2.25",
|
||||||
"url",
|
"url",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
@ -1920,7 +1995,7 @@ dependencies = [
|
||||||
"resolv-conf",
|
"resolv-conf",
|
||||||
"smallvec",
|
"smallvec",
|
||||||
"thiserror",
|
"thiserror",
|
||||||
"tokio",
|
"tokio 0.2.25",
|
||||||
"trust-dns-proto",
|
"trust-dns-proto",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
|
@ -21,6 +21,9 @@ rand = "0.8.4"
|
||||||
version = "4.0.12"
|
version = "4.0.12"
|
||||||
features = ["serde"]
|
features = ["serde"]
|
||||||
|
|
||||||
|
[dev-dependencies]
|
||||||
|
actix-rt = "2.2.0"
|
||||||
|
|
||||||
[profile.dev]
|
[profile.dev]
|
||||||
opt-level = 0
|
opt-level = 0
|
||||||
debug = true
|
debug = true
|
||||||
|
|
|
@ -3,7 +3,7 @@ use config::{self, ConfigError};
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
|
|
||||||
/// Configuration values.
|
/// Configuration values.
|
||||||
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
|
#[derive(Debug, Clone, Default, serde::Serialize, serde::Deserialize)]
|
||||||
pub struct Config {
|
pub struct Config {
|
||||||
/// Server configuration.
|
/// Server configuration.
|
||||||
pub server: ServerConfig,
|
pub server: ServerConfig,
|
||||||
|
@ -12,7 +12,7 @@ pub struct Config {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Server configuration.
|
/// Server configuration.
|
||||||
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
|
#[derive(Debug, Clone, Default, serde::Serialize, serde::Deserialize)]
|
||||||
pub struct ServerConfig {
|
pub struct ServerConfig {
|
||||||
/// The socket address to bind.
|
/// The socket address to bind.
|
||||||
pub address: String,
|
pub address: String,
|
||||||
|
@ -27,7 +27,7 @@ pub struct ServerConfig {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Paste configuration.
|
/// Paste configuration.
|
||||||
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
|
#[derive(Debug, Clone, Default, serde::Serialize, serde::Deserialize)]
|
||||||
pub struct PasteConfig {
|
pub struct PasteConfig {
|
||||||
/// Pet names configuration.
|
/// Pet names configuration.
|
||||||
pub pet_names: PetNamesConfig,
|
pub pet_names: PetNamesConfig,
|
||||||
|
@ -38,7 +38,7 @@ pub struct PasteConfig {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Pet names configuration.
|
/// Pet names configuration.
|
||||||
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
|
#[derive(Debug, Clone, Default, serde::Serialize, serde::Deserialize)]
|
||||||
pub struct PetNamesConfig {
|
pub struct PetNamesConfig {
|
||||||
/// Use pet names instead of original file names.
|
/// Use pet names instead of original file names.
|
||||||
pub enabled: bool,
|
pub enabled: bool,
|
||||||
|
@ -49,7 +49,7 @@ pub struct PetNamesConfig {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Random string configuration.
|
/// Random string configuration.
|
||||||
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
|
#[derive(Debug, Clone, Default, serde::Serialize, serde::Deserialize)]
|
||||||
pub struct RandomConfig {
|
pub struct RandomConfig {
|
||||||
/// Use random strings instead of original file names.
|
/// Use random strings instead of original file names.
|
||||||
pub enabled: bool,
|
pub enabled: bool,
|
||||||
|
@ -67,3 +67,25 @@ impl Config {
|
||||||
config.try_into()
|
config.try_into()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod test {
|
||||||
|
use super::*;
|
||||||
|
use std::env;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_parse_config() -> Result<(), ConfigError> {
|
||||||
|
let file_name = PathBuf::from(env!("CARGO_MANIFEST_DIR"))
|
||||||
|
.join("config.toml")
|
||||||
|
.to_str()
|
||||||
|
.unwrap()
|
||||||
|
.to_string();
|
||||||
|
env::set_var(
|
||||||
|
format!("{}_SERVER__ADDRESS", env!("CARGO_PKG_NAME")),
|
||||||
|
"0.0.1.1",
|
||||||
|
);
|
||||||
|
let config = Config::parse(&file_name)?;
|
||||||
|
assert_eq!("0.0.1.1", config.server.address);
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
55
src/file.rs
55
src/file.rs
|
@ -63,3 +63,58 @@ pub fn save(mut file_name: &str, bytes: &[u8], config: &Config) -> IoResult<Stri
|
||||||
.unwrap_or_default()
|
.unwrap_or_default()
|
||||||
.to_string())
|
.to_string())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod test {
|
||||||
|
use super::*;
|
||||||
|
use crate::config::{PetNamesConfig, RandomConfig};
|
||||||
|
use std::env;
|
||||||
|
use std::fs;
|
||||||
|
use std::path::PathBuf;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_save_file() -> IoResult<()> {
|
||||||
|
let mut config = Config::default();
|
||||||
|
config.server.upload_path = env::current_dir()?;
|
||||||
|
config.paste.pet_names = PetNamesConfig {
|
||||||
|
enabled: true,
|
||||||
|
words: 3,
|
||||||
|
separator: String::from("_"),
|
||||||
|
};
|
||||||
|
let file_name = save("test.txt", &[65, 66, 67], &config)?;
|
||||||
|
assert_eq!("ABC", fs::read_to_string(&file_name)?);
|
||||||
|
assert_eq!(
|
||||||
|
Some("txt"),
|
||||||
|
PathBuf::from(&file_name)
|
||||||
|
.extension()
|
||||||
|
.map(|v| v.to_str())
|
||||||
|
.flatten()
|
||||||
|
);
|
||||||
|
fs::remove_file(file_name)?;
|
||||||
|
|
||||||
|
config.paste.default_extension = String::from("bin");
|
||||||
|
config.paste.pet_names.enabled = false;
|
||||||
|
config.paste.random = RandomConfig {
|
||||||
|
enabled: true,
|
||||||
|
length: 10,
|
||||||
|
};
|
||||||
|
let file_name = save("random", &[120, 121, 122], &config)?;
|
||||||
|
assert_eq!("xyz", fs::read_to_string(&file_name)?);
|
||||||
|
assert_eq!(
|
||||||
|
Some("bin"),
|
||||||
|
PathBuf::from(&file_name)
|
||||||
|
.extension()
|
||||||
|
.map(|v| v.to_str())
|
||||||
|
.flatten()
|
||||||
|
);
|
||||||
|
fs::remove_file(file_name)?;
|
||||||
|
|
||||||
|
config.paste.random.enabled = false;
|
||||||
|
let file_name = save("test.file", &[116, 101, 115, 116], &config)?;
|
||||||
|
assert_eq!("test.file", &file_name);
|
||||||
|
assert_eq!("test", fs::read_to_string(&file_name)?);
|
||||||
|
fs::remove_file(file_name)?;
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -45,3 +45,34 @@ impl ContentDisposition {
|
||||||
.ok_or_else(|| error::ErrorBadRequest("file data not present"))
|
.ok_or_else(|| error::ErrorBadRequest("file data not present"))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod test {
|
||||||
|
use super::*;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_content_disposition() -> Result<(), ActixError> {
|
||||||
|
assert!(ContentDisposition::try_from(None).is_err());
|
||||||
|
|
||||||
|
let actix_content_disposition = Some(ActixContentDisposition {
|
||||||
|
disposition: DispositionType::FormData,
|
||||||
|
parameters: vec![
|
||||||
|
DispositionParam::Name(String::from("file")),
|
||||||
|
DispositionParam::Filename(String::from("x.txt")),
|
||||||
|
],
|
||||||
|
});
|
||||||
|
let content_disposition = ContentDisposition::try_from(actix_content_disposition)?;
|
||||||
|
assert!(content_disposition.has_form_field("file"));
|
||||||
|
assert!(!content_disposition.has_form_field("test"));
|
||||||
|
assert_eq!("x.txt", content_disposition.get_file_name()?);
|
||||||
|
|
||||||
|
let actix_content_disposition = Some(ActixContentDisposition {
|
||||||
|
disposition: DispositionType::Attachment,
|
||||||
|
parameters: vec![DispositionParam::Name(String::from("file"))],
|
||||||
|
});
|
||||||
|
let content_disposition = ContentDisposition::try_from(actix_content_disposition)?;
|
||||||
|
assert!(!content_disposition.has_form_field("file"));
|
||||||
|
assert!(content_disposition.get_file_name().is_err());
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -91,3 +91,27 @@ pub fn configure_routes(cfg: &mut web::ServiceConfig) {
|
||||||
.service(upload)
|
.service(upload)
|
||||||
.route("", web::head().to(HttpResponse::MethodNotAllowed));
|
.route("", web::head().to(HttpResponse::MethodNotAllowed));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
use super::*;
|
||||||
|
use actix_web::{http, test, App};
|
||||||
|
|
||||||
|
#[actix_rt::test]
|
||||||
|
async fn test_index() {
|
||||||
|
let mut app = test::init_service(App::new().service(index)).await;
|
||||||
|
let req = test::TestRequest::with_header("content-type", "text/plain").to_request();
|
||||||
|
let resp = test::call_service(&mut app, req).await;
|
||||||
|
assert!(resp.status().is_success());
|
||||||
|
}
|
||||||
|
|
||||||
|
#[actix_rt::test]
|
||||||
|
async fn test_serve() {
|
||||||
|
let mut app = test::init_service(App::new().service(serve)).await;
|
||||||
|
let req = test::TestRequest::default().to_request();
|
||||||
|
let resp = test::call_service(&mut app, req).await;
|
||||||
|
assert_eq!(http::StatusCode::NOT_FOUND, resp.status());
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: add test for upload
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue