Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tests: add test case for openapi/tag and openapi/xml #581

Merged
merged 1 commit into from
Dec 25, 2023
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
3 changes: 1 addition & 2 deletions crates/oapi/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -169,8 +169,7 @@ macro_rules! impl_to_schema_primitive {
pub mod oapi {
pub use super::*;
}
// Create `salvo-oapi` module so we can use `salvo-oapi-macros` directly
// from `salvo-oapi` crate. ONLY FOR INTERNAL USE!

#[doc(hidden)]
pub mod __private {
pub use inventory;
Expand Down
53 changes: 53 additions & 0 deletions crates/oapi/src/openapi/tag.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,3 +84,56 @@ impl Tag {
self
}
}

#[cfg(test)]
mod tests {
use super::Tag;
use super::ExternalDocs;

#[test]
fn tag_new() {
let tag = Tag::new("tag name");
assert_eq!(tag.name, "tag name");
assert!(tag.description.is_none());
assert!(tag.external_docs.is_none());
assert!(tag.extensions.is_none());

let tag = tag.name("new tag name");
assert_eq!(tag.name, "new tag name");

let tag = tag.description("description");
assert!(tag.description.is_some());

let tag = tag.external_docs(ExternalDocs::new(""));
assert!(tag.external_docs.is_some());
}

#[test]
fn from_string() {
let name = "tag name".to_string();
let tag = Tag::from(name);
assert_eq!(tag.name, "tag name".to_string());
}

#[test]
fn from_string_ref() {
let name = "tag name".to_string();
let tag = Tag::from(&name);
assert_eq!(tag.name, "tag name".to_string());
}

#[test]
fn from_str() {
let name = "tag name";
let tag = Tag::from(name);
assert_eq!(tag.name, "tag name");
}

#[test]
fn cmp() {
let tag1 = Tag::new("a");
let tag2 = Tag::new("b");

assert!(tag1 < tag2);
}
}
17 changes: 16 additions & 1 deletion crates/oapi/src/openapi/xml.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,12 +95,27 @@ mod tests {

#[test]
fn xml_new() {
let xml = Xml::new();
let mut xml = Xml::new();

assert!(xml.name.is_none());
assert!(xml.namespace.is_none());
assert!(xml.prefix.is_none());
assert!(xml.attribute.is_none());
assert!(xml.wrapped.is_none());

xml = xml.name("name");
assert!(xml.name.is_some());

xml = xml.namespace("namespave");
assert!(xml.namespace.is_some());

xml = xml.prefix("prefix");
assert!(xml.prefix.is_some());

xml = xml.attribute(true);
assert!(xml.attribute.is_some());

xml = xml.wrapped(true);
assert!(xml.wrapped.is_some());
}
}