summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Guschin <saintruler@gmail.com>2021-04-18 17:14:14 +0400
committerAndrew Guschin <saintruler@gmail.com>2021-04-18 17:14:14 +0400
commit96faf9ab96fbd35cd173ff76c02932fc22b74d9b (patch)
treefacea20b2339589f4b74f355635bf0dd74f87f7e
parent0ad35b9b50dfaa1083f3f5acc633ec769bc10e37 (diff)
Added test for validating schemas
-rw-r--r--schemas/post.json3
-rw-r--r--src/tests.rs20
2 files changed, 22 insertions, 1 deletions
diff --git a/schemas/post.json b/schemas/post.json
index f427dd7..a7a3a36 100644
--- a/schemas/post.json
+++ b/schemas/post.json
@@ -6,5 +6,6 @@
"body": { "type": "string" },
"published": { "type": "boolean" }
},
- "required": ["id", "title", "body", "published"]
+ "required": ["id", "title", "body", "published"],
+ "additionalProperties": false
}
diff --git a/src/tests.rs b/src/tests.rs
new file mode 100644
index 0000000..919ba01
--- /dev/null
+++ b/src/tests.rs
@@ -0,0 +1,20 @@
+#[cfg(test)]
+mod tests {
+ use crate::validator::Validator;
+ use crate::models::Post;
+ use serde_json;
+
+ #[test]
+ fn test_post_schemas_correspondence() {
+ let p = Post {
+ id: 0,
+ title: "Title".to_string(),
+ body: "Body".to_string(),
+ published: true,
+ hidden: false
+ };
+ let v = Validator::from_file("schemas/post.json").unwrap();
+ let json = serde_json::to_string(&p).unwrap();
+ assert_eq!(v.check(&json), true);
+ }
+}