Skip to content

Commit a5cbb0d

Browse files
tests: Add more asserts of HTTP body
1 parent 7f6f63d commit a5cbb0d

File tree

1 file changed

+29
-5
lines changed

1 file changed

+29
-5
lines changed

aw-server/tests/api.rs

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,15 @@ extern crate rocket;
66
extern crate aw_datastore;
77
extern crate aw_server;
88

9-
// TODO: Validate return data on more places
10-
119
#[cfg(test)]
1210
mod api_tests {
13-
use chrono::{DateTime, Utc};
14-
use rocket::http::{ContentType, Header, Status};
11+
use std::collections::HashMap;
1512
use std::path::PathBuf;
1613
use std::sync::Mutex;
1714

15+
use chrono::{DateTime, Utc};
16+
use rocket::http::{ContentType, Header, Status};
17+
1818
use aw_server::config;
1919
use aw_server::endpoints;
2020

@@ -44,6 +44,9 @@ mod api_tests {
4444
.dispatch();
4545
debug!("{:?}", res.body_string());
4646
assert_eq!(res.status(), rocket::http::Status::Ok);
47+
let buckets: HashMap<String, Bucket> =
48+
serde_json::from_str(&res.body_string().unwrap()).unwrap();
49+
assert_eq!(buckets.len(), 0);
4750

4851
// Try to fetch non-existing bucket
4952
res = client
@@ -91,8 +94,18 @@ mod api_tests {
9194
.header(ContentType::JSON)
9295
.dispatch();
9396
debug!("{:?}", res.body_string());
94-
// TODO: assert data
9597
assert_eq!(res.status(), rocket::http::Status::Ok);
98+
let buckets: HashMap<String, Bucket> =
99+
serde_json::from_str(&res.body_string().unwrap()).unwrap();
100+
assert_eq!(buckets.len(), 1);
101+
let bucket = buckets.get("id").unwrap();
102+
assert_eq!(bucket.id, "id");
103+
assert_eq!(bucket._type, "type");
104+
assert_eq!(bucket.client, "client");
105+
assert_eq!(bucket.hostname, "hostname");
106+
assert_eq!(bucket.events, None);
107+
assert_eq!(bucket.metadata.start, None);
108+
assert_eq!(bucket.metadata.end, None);
96109

97110
// Get newly created bucket
98111
res = client
@@ -134,6 +147,17 @@ mod api_tests {
134147
.dispatch();
135148
debug!("{:?}", res.body_string());
136149
assert_eq!(res.status(), rocket::http::Status::NotFound);
150+
151+
// Get empty list of buckets
152+
let mut res = client
153+
.get("/api/0/buckets/")
154+
.header(ContentType::JSON)
155+
.dispatch();
156+
debug!("{:?}", res.body_string());
157+
assert_eq!(res.status(), rocket::http::Status::Ok);
158+
let buckets: HashMap<String, Bucket> =
159+
serde_json::from_str(&res.body_string().unwrap()).unwrap();
160+
assert_eq!(buckets.len(), 0);
137161
}
138162

139163
#[test]

0 commit comments

Comments
 (0)