Make introspection tests ordering independent.
With the new HashMap implementation, the maps on stable and nightly have different ordering. The introspection tests were relying on strict ordering. This commit adds a simple sorting of the results to prevent test failures.
This commit is contained in:
parent
b96879e2db
commit
85d5480d50
2 changed files with 56 additions and 15 deletions
|
@ -157,13 +157,14 @@ fn test_introspection_directives() {
|
||||||
let database = Database::new();
|
let database = Database::new();
|
||||||
let schema = RootNode::new(&database, EmptyMutation::<Database>::new());
|
let schema = RootNode::new(&database, EmptyMutation::<Database>::new());
|
||||||
|
|
||||||
let result = ::execute(q, None, &schema, &Variables::new(), &database).unwrap();
|
let mut result = crate::execute(q, None, &schema, &Variables::new(), &database).unwrap();
|
||||||
|
sort_schema_value(&mut result.0);
|
||||||
|
|
||||||
let expected = graphql_value!({
|
let mut expected = graphql_value!({
|
||||||
"__schema": {
|
"__schema": {
|
||||||
"directives": [
|
"directives": [
|
||||||
{
|
{
|
||||||
"name": "skip",
|
"name": "include",
|
||||||
"locations": [
|
"locations": [
|
||||||
"FIELD",
|
"FIELD",
|
||||||
"FRAGMENT_SPREAD",
|
"FRAGMENT_SPREAD",
|
||||||
|
@ -171,7 +172,7 @@ fn test_introspection_directives() {
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "include",
|
"name": "skip",
|
||||||
"locations": [
|
"locations": [
|
||||||
"FIELD",
|
"FIELD",
|
||||||
"FRAGMENT_SPREAD",
|
"FRAGMENT_SPREAD",
|
||||||
|
@ -181,6 +182,7 @@ fn test_introspection_directives() {
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
sort_schema_value(&mut expected);
|
||||||
|
|
||||||
assert_eq!(result, (expected, vec![]));
|
assert_eq!(result, (expected, vec![]));
|
||||||
}
|
}
|
||||||
|
@ -201,8 +203,6 @@ fn test_introspection_possible_types() {
|
||||||
|
|
||||||
let result = ::execute(doc, None, &schema, &Variables::new(), &database);
|
let result = ::execute(doc, None, &schema, &Variables::new(), &database);
|
||||||
|
|
||||||
println!("Result: {:#?}", result);
|
|
||||||
|
|
||||||
let (result, errors) = result.ok().expect("Query returned error");
|
let (result, errors) = result.ok().expect("Query returned error");
|
||||||
|
|
||||||
assert_eq!(errors, vec![]);
|
assert_eq!(errors, vec![]);
|
||||||
|
@ -237,9 +237,10 @@ fn test_builtin_introspection_query() {
|
||||||
let database = Database::new();
|
let database = Database::new();
|
||||||
let schema = RootNode::new(&database, EmptyMutation::<Database>::new());
|
let schema = RootNode::new(&database, EmptyMutation::<Database>::new());
|
||||||
|
|
||||||
let result = ::introspect(&schema, &database, IntrospectionFormat::default());
|
let mut result = crate::introspect(&schema, &database, IntrospectionFormat::default()).unwrap();
|
||||||
|
sort_schema_value(&mut result.0);
|
||||||
let expected = schema_introspection_result();
|
let expected = schema_introspection_result();
|
||||||
assert_eq!(result, Ok((expected, vec![])));
|
assert_eq!(result, (expected, vec![]));
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
@ -247,7 +248,10 @@ fn test_builtin_introspection_query_without_descriptions() {
|
||||||
let database = Database::new();
|
let database = Database::new();
|
||||||
let schema = RootNode::new(&database, EmptyMutation::<Database>::new());
|
let schema = RootNode::new(&database, EmptyMutation::<Database>::new());
|
||||||
|
|
||||||
let result = ::introspect(&schema, &database, IntrospectionFormat::WithoutDescriptions);
|
let mut result =
|
||||||
|
crate::introspect(&schema, &database, IntrospectionFormat::WithoutDescriptions).unwrap();
|
||||||
|
sort_schema_value(&mut result.0);
|
||||||
let expected = schema_introspection_result_without_descriptions();
|
let expected = schema_introspection_result_without_descriptions();
|
||||||
assert_eq!(result, Ok((expected, vec![])));
|
|
||||||
|
assert_eq!(result, (expected, vec![]));
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,40 @@
|
||||||
use value::{self, Value::Null};
|
use crate::value::{self, Value, Value::Null};
|
||||||
|
|
||||||
|
// Sort a nested schema Value.
|
||||||
|
// In particular, lists are sorted by the "name" key of children, if present.
|
||||||
|
// Only needed for comparisons.
|
||||||
|
pub(super) fn sort_schema_value(value: &mut Value) {
|
||||||
|
match value {
|
||||||
|
Value::Null | Value::Scalar(_) => {}
|
||||||
|
Value::List(ref mut items) => {
|
||||||
|
items.sort_by(|a, b| {
|
||||||
|
let name_a = a
|
||||||
|
.as_object_value()
|
||||||
|
.and_then(|v| v.get_field_value("name"))
|
||||||
|
.and_then(|v| v.as_scalar_value::<String>())
|
||||||
|
.map(|x| x.as_str())
|
||||||
|
.unwrap_or("");
|
||||||
|
let name_b = b
|
||||||
|
.as_object_value()
|
||||||
|
.and_then(|v| v.get_field_value("name"))
|
||||||
|
.and_then(|v| v.as_scalar_value::<String>())
|
||||||
|
.map(|x| x.as_str())
|
||||||
|
.unwrap_or("");
|
||||||
|
name_a.cmp(name_b)
|
||||||
|
});
|
||||||
|
for item in items.iter_mut() {
|
||||||
|
sort_schema_value(item);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Value::Object(ref mut obj) => {
|
||||||
|
obj.iter_mut()
|
||||||
|
.for_each(|(_key, item)| sort_schema_value(item));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub(crate) fn schema_introspection_result() -> value::Value {
|
pub(crate) fn schema_introspection_result() -> value::Value {
|
||||||
graphql_value!({
|
let mut v = graphql_value!({
|
||||||
"__schema": {
|
"__schema": {
|
||||||
"queryType": {
|
"queryType": {
|
||||||
"name": "Query"
|
"name": "Query"
|
||||||
|
@ -1274,11 +1307,13 @@ pub(crate) fn schema_introspection_result() -> value::Value {
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
})
|
});
|
||||||
|
sort_schema_value(&mut v);
|
||||||
|
v
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn schema_introspection_result_without_descriptions() -> value::Value {
|
pub(crate) fn schema_introspection_result_without_descriptions() -> value::Value {
|
||||||
graphql_value!({
|
let mut v = graphql_value!({
|
||||||
"__schema": {
|
"__schema": {
|
||||||
"queryType": {
|
"queryType": {
|
||||||
"name": "Query"
|
"name": "Query"
|
||||||
|
@ -2458,5 +2493,7 @@ pub(crate) fn schema_introspection_result_without_descriptions() -> value::Value
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
})
|
});
|
||||||
|
sort_schema_value(&mut v);
|
||||||
|
v
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue