mirror of
https://github.com/meilisearch/meilisearch.git
synced 2024-11-23 02:27:40 +08:00
test(http): setting enum serialize/deserialize
This commit is contained in:
parent
dc636d190d
commit
84c1dda39d
10
Cargo.lock
generated
10
Cargo.lock
generated
@ -911,6 +911,7 @@ dependencies = [
|
|||||||
"rayon",
|
"rayon",
|
||||||
"serde",
|
"serde",
|
||||||
"serde_json",
|
"serde_json",
|
||||||
|
"serde_test",
|
||||||
"stderrlog",
|
"stderrlog",
|
||||||
"structopt",
|
"structopt",
|
||||||
"tempfile",
|
"tempfile",
|
||||||
@ -2079,6 +2080,15 @@ dependencies = [
|
|||||||
"serde",
|
"serde",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "serde_test"
|
||||||
|
version = "1.0.125"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "b4bb5fef7eaf5a97917567183607ac4224c5b451c15023930f23b937cce879fe"
|
||||||
|
dependencies = [
|
||||||
|
"serde",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "serde_urlencoded"
|
name = "serde_urlencoded"
|
||||||
version = "0.6.1"
|
version = "0.6.1"
|
||||||
|
@ -37,3 +37,6 @@ fst = "0.4.5"
|
|||||||
|
|
||||||
# Temporary fix for bitvec, remove once fixed. (https://github.com/bitvecto-rs/bitvec/issues/105)
|
# Temporary fix for bitvec, remove once fixed. (https://github.com/bitvecto-rs/bitvec/issues/105)
|
||||||
funty = "=1.1"
|
funty = "=1.1"
|
||||||
|
|
||||||
|
[dev-dependencies]
|
||||||
|
serde_test = "1.0.125"
|
||||||
|
@ -242,7 +242,7 @@ enum UpdateMetaProgress {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
|
||||||
#[serde(deny_unknown_fields)]
|
#[serde(deny_unknown_fields)]
|
||||||
#[serde(rename_all = "camelCase")]
|
#[serde(rename_all = "camelCase")]
|
||||||
struct Settings {
|
struct Settings {
|
||||||
@ -993,3 +993,62 @@ async fn main() -> anyhow::Result<()> {
|
|||||||
let addr = SocketAddr::from_str(&opt.http_listen_addr)?;
|
let addr = SocketAddr::from_str(&opt.http_listen_addr)?;
|
||||||
Ok(warp::serve(routes).run(addr).await)
|
Ok(warp::serve(routes).run(addr).await)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
use serde_test::{assert_de_tokens, assert_ser_tokens, Token};
|
||||||
|
|
||||||
|
use milli::update::Setting;
|
||||||
|
|
||||||
|
use crate::Settings;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn serialize_settings() {
|
||||||
|
let settings = Settings {
|
||||||
|
displayed_attributes: Setting::Set(vec!["name".to_string()]),
|
||||||
|
searchable_attributes: Setting::Reset,
|
||||||
|
faceted_attributes: Setting::NotSet,
|
||||||
|
criteria: Setting::NotSet,
|
||||||
|
stop_words: Default::default(),
|
||||||
|
};
|
||||||
|
|
||||||
|
assert_ser_tokens(&settings, &[
|
||||||
|
Token::Struct { name: "Settings", len: 3 },
|
||||||
|
Token::Str("displayedAttributes"),
|
||||||
|
Token::Some,
|
||||||
|
Token::Seq { len: Some(1) },
|
||||||
|
Token::Str("name"),
|
||||||
|
Token::SeqEnd,
|
||||||
|
Token::Str("searchableAttributes"),
|
||||||
|
Token::None,
|
||||||
|
Token::Str("facetedAttributes"),
|
||||||
|
Token::None,
|
||||||
|
Token::StructEnd,
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn deserialize_settings() {
|
||||||
|
let settings = Settings {
|
||||||
|
displayed_attributes: Setting::Set(vec!["name".to_string()]),
|
||||||
|
searchable_attributes: Setting::Reset,
|
||||||
|
faceted_attributes: Setting::Reset,
|
||||||
|
criteria: Setting::NotSet,
|
||||||
|
stop_words: Setting::NotSet,
|
||||||
|
};
|
||||||
|
|
||||||
|
assert_de_tokens(&settings, &[
|
||||||
|
Token::Struct { name: "Settings", len: 3 },
|
||||||
|
Token::Str("displayedAttributes"),
|
||||||
|
Token::Some,
|
||||||
|
Token::Seq { len: Some(1) },
|
||||||
|
Token::Str("name"),
|
||||||
|
Token::SeqEnd,
|
||||||
|
Token::Str("searchableAttributes"),
|
||||||
|
Token::None,
|
||||||
|
Token::Str("facetedAttributes"),
|
||||||
|
Token::None,
|
||||||
|
Token::StructEnd,
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -14,11 +14,11 @@ use crate::facet::FacetType;
|
|||||||
use crate::update::{ClearDocuments, IndexDocuments, UpdateIndexingStep};
|
use crate::update::{ClearDocuments, IndexDocuments, UpdateIndexingStep};
|
||||||
use crate::update::index_documents::{IndexDocumentsMethod, Transform};
|
use crate::update::index_documents::{IndexDocumentsMethod, Transform};
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone, PartialEq)]
|
||||||
pub enum Setting<T> {
|
pub enum Setting<T> {
|
||||||
Set(T),
|
Set(T),
|
||||||
NotSet,
|
|
||||||
Reset,
|
Reset,
|
||||||
|
NotSet,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T> Default for Setting<T> {
|
impl<T> Default for Setting<T> {
|
||||||
|
Loading…
Reference in New Issue
Block a user