Fix the list related tests to change the updatable list back

Otherwise every odd number of test runs, there will be a change
in test/lists/updatable.list for Git.
This commit is contained in:
Paul van Tilburg 2018-01-01 22:17:56 +01:00
parent 7d056b5008
commit 4f622923fd
4 changed files with 25 additions and 16 deletions

3
Rocket.toml Normal file
View File

@ -0,0 +1,3 @@
[development]
address = "0.0.0.0"
port = 3000

View File

@ -112,13 +112,11 @@ mod tests {
let mut res = client.get("/lists/updatable").header(Accept::JSON).dispatch();
let body = res.body_string().unwrap();
let list = serde_json::from_str::<List>(body.as_str()).unwrap();
// Switch contentA with contentB and vice versa
let new_data = if list.data == "contentA" {
"contentB"
} else {
"contentA"
};
let new_json = json!({
assert_eq!(list.data, "Some content");
// Try to change the list data, then verify it was changed
let new_data = "New content";
let mut new_json: serde_json::Value = json!({
"id": "updatable",
"index": 1,
"data": new_data,
@ -129,8 +127,6 @@ mod tests {
"name": "Updatable",
"path": "test/lists/updatablelist"
});
// Try to change the list data, then verify it was changed
let res = client.put("/lists/updatable")
.header(ContentType::JSON)
.body(new_json.to_string())
@ -144,6 +140,14 @@ mod tests {
let list = serde_json::from_str::<List>(body.as_str()).unwrap();
assert_eq!(list.data, new_data);
// ... and change it back
*new_json.get_mut("data").unwrap() = json!("Some content");
let res = client.put("/lists/updatable")
.header(ContentType::JSON)
.body(new_json.to_string())
.dispatch();
assert_eq!(res.status(), Status::Ok);
// Try to change a list that doesn't exist
let res = client.put("/lists/doesntexit")
.header(ContentType::JSON)

View File

@ -116,20 +116,22 @@ mod tests {
let list = lists.iter_mut()
.find(|list| list.id == "updatable")
.unwrap();
assert_eq!(list.data, "Some content");
let new_data = match list.data.as_ref() {
"contentA" => "contentB",
_ => "contentA"
};
// Update the data van verify it has changed
let new_data = "New content";
list.update_data(&String::from(new_data));
assert_eq!(list.data, new_data);
// Verify that the data is written to the file of the list by
// loading them again
let lists = List::load_all(Some("test"));
let list = lists.iter()
let mut lists = List::load_all(Some("test"));
let list = lists.iter_mut()
.find(|list| list.id == "updatable")
.unwrap();
assert_eq!(list.data, new_data);
// ... and change it back again
list.update_data(&String::from("Some content"));
}
}

View File

@ -1 +1 @@
contentB
Some content