Refactored test.

This commit is contained in:
Jeff Baskin 2022-07-01 12:29:02 -04:00
parent 9ebc7bef5e
commit adb4740a10

View File

@ -70,6 +70,21 @@ impl Database {
}
}
#[cfg(test)]
mod support {
use super::*;
pub fn compare(db: &Database, output: &str, expected: &str) {
assert!(
output == expected,
"\n\n{}\nGot: {}\nWant: {}\n\n",
&db.schema.sdl(),
output,
expected
);
}
}
#[cfg(test)]
mod queries {
use super::*;
@ -79,6 +94,7 @@ mod queries {
let db = Database::new();
let output = db.execute("{pointless}").await;
let expected = r#"{"data":{"pointless":"this is pointless."}}"#;
support::compare(&db, &output, &expected);
assert!(
output == expected,
"Got '{}' instead of '{}'.",
@ -96,13 +112,7 @@ mod queries {
.await;
let output = db.execute(r#"{tables{name}}"#).await;
let expected = r#"{"data":{"tables":[{"name":"fred"},{"name":"barney"}]}}"#;
assert!(
output == expected,
"\n\n{}\nGot: {}\nWant: {}\n\n",
&db.schema.sdl(),
output,
expected
);
support::compare(&db, &output, &expected);
}
}
@ -118,11 +128,6 @@ mod mutations {
.await;
let expected = r#"{"data":{"createTable":{"name":"william"}}}"#;
println!("{}", &db.schema.sdl());
assert!(
output == expected,
"Got '{}' instead of '{}'.",
output,
expected
)
support::compare(&db, &output, &expected);
}
}