Skip to content

Commit

Permalink
TEST: HTTP GET schema
Browse files Browse the repository at this point in the history
  • Loading branch information
slivingston committed Oct 31, 2024
1 parent df350aa commit 7643e36
Showing 1 changed file with 46 additions and 0 deletions.
46 changes: 46 additions & 0 deletions src/bin/rrhttp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -564,6 +564,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {

#[cfg(test)]
mod tests {
use std::collections::HashMap;
use std::io::Write;

use tempfile::NamedTempFile;
Expand Down Expand Up @@ -619,6 +620,51 @@ mod tests {
assert!(!config.is_valid(&req));
}

#[test]
fn test_get_schema() {
let config_data = "---
default: block
rules:
- verb: GET
uri: /api/cameras/rgb
schema:
- name: Base64
optional: true
type: bool
- name: Width
optional: true
type: int
range: [1, 800]
- name: Height
optional: true
type: int
range: [1, 600]
";
let mut config_file = NamedTempFile::new().unwrap();
write!(config_file, "{}", config_data).unwrap();
let config = Config::new_from_file(&config_file.path().to_string_lossy()).unwrap();

assert!(!config.is_valid(&Request {
verb: HttpVerb::Post,
uri: "/api/head".into(),
body: Some(json!({
"Pitch": 0,
"Roll": 0,
"Yaw": 0,
"Velocity": 75,
})),
query: None,
}));

let mut req = Request {
verb: HttpVerb::Get,
uri: "/api/cameras/rgb".into(),
body: None,
query: None,
};
assert!(config.is_valid(&req));
}

#[test]
fn test_post_schema() {
let config_data = "---
Expand Down

0 comments on commit 7643e36

Please sign in to comment.