mirror of
https://github.com/teloxide/teloxide.git
synced 2025-01-09 11:43:57 +01:00
fix test
This commit is contained in:
parent
ca69b6385c
commit
45183d4dcd
1 changed files with 23 additions and 11 deletions
|
@ -73,29 +73,41 @@ impl std::error::Error for UnserializerError {}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test() {
|
fn test() {
|
||||||
use crate::serde_multipart::unserializers::string::StringUnserializer;
|
use crate::{
|
||||||
|
serde_multipart::unserializers::{
|
||||||
|
input_file::InputFileUnserializer, string::StringUnserializer,
|
||||||
|
},
|
||||||
|
types::InputFile,
|
||||||
|
};
|
||||||
|
|
||||||
use serde::Serialize;
|
use serde::Serialize;
|
||||||
|
|
||||||
use crate::{
|
use std::{borrow::Cow, path::Path};
|
||||||
serde_multipart::unserializers::input_file::InputFileUnserializer, types::InputFile,
|
|
||||||
};
|
|
||||||
use std::borrow::Cow;
|
|
||||||
|
|
||||||
let value = String::from("test");
|
let value = String::from("test");
|
||||||
assert_eq!(value.serialize(StringUnserializer), Ok(value));
|
assert!(matches!(value.serialize(StringUnserializer), Ok(v) if v == value));
|
||||||
|
|
||||||
let value = InputFile::Url(reqwest::Url::parse("http://example.com").unwrap());
|
let url = reqwest::Url::parse("http://example.com").unwrap();
|
||||||
assert_eq!(value.serialize(InputFileUnserializer::NotMem), Ok(value));
|
let value = InputFile::Url(url.clone());
|
||||||
|
assert!(
|
||||||
|
matches!(value.serialize(InputFileUnserializer::NotMem), Ok(InputFile::Url(v)) if v == url)
|
||||||
|
);
|
||||||
|
|
||||||
let value = InputFile::FileId(String::from("file_id"));
|
let value = InputFile::FileId(String::from("file_id"));
|
||||||
assert_eq!(value.serialize(InputFileUnserializer::NotMem), Ok(value));
|
assert!(
|
||||||
|
matches!(value.serialize(InputFileUnserializer::NotMem), Ok(InputFile::FileId(v)) if v == "file_id")
|
||||||
|
);
|
||||||
|
|
||||||
let value = InputFile::Memory {
|
let value = InputFile::Memory {
|
||||||
file_name: String::from("name"),
|
file_name: String::from("name"),
|
||||||
data: Cow::Owned(vec![1, 2, 3]),
|
data: Cow::Owned(vec![1, 2, 3]),
|
||||||
};
|
};
|
||||||
assert_eq!(value.serialize(InputFileUnserializer::memory()), Ok(value));
|
assert!(
|
||||||
|
matches!(value.serialize(InputFileUnserializer::memory()), Ok(InputFile::Memory { file_name, data }) if file_name == "name" && *data == [1, 2, 3])
|
||||||
|
);
|
||||||
|
|
||||||
let value = InputFile::File("a/b/c".into());
|
let value = InputFile::File("a/b/c".into());
|
||||||
assert_eq!(value.serialize(InputFileUnserializer::NotMem), Ok(value));
|
assert!(
|
||||||
|
matches!(value.serialize(InputFileUnserializer::NotMem), Ok(InputFile::File(v)) if v == Path::new("a/b/c"))
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue