Refactored test.
This commit is contained in:
		
							
								
								
									
										31
									
								
								src/lib.rs
									
									
									
									
									
								
							
							
						
						
									
										31
									
								
								src/lib.rs
									
									
									
									
									
								
							@@ -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)]
 | 
					#[cfg(test)]
 | 
				
			||||||
mod queries {
 | 
					mod queries {
 | 
				
			||||||
    use super::*;
 | 
					    use super::*;
 | 
				
			||||||
@@ -79,6 +94,7 @@ mod queries {
 | 
				
			|||||||
        let db = Database::new();
 | 
					        let db = Database::new();
 | 
				
			||||||
        let output = db.execute("{pointless}").await;
 | 
					        let output = db.execute("{pointless}").await;
 | 
				
			||||||
        let expected = r#"{"data":{"pointless":"this is pointless."}}"#;
 | 
					        let expected = r#"{"data":{"pointless":"this is pointless."}}"#;
 | 
				
			||||||
 | 
					        support::compare(&db, &output, &expected);
 | 
				
			||||||
        assert!(
 | 
					        assert!(
 | 
				
			||||||
            output == expected,
 | 
					            output == expected,
 | 
				
			||||||
            "Got '{}' instead of '{}'.",
 | 
					            "Got '{}' instead of '{}'.",
 | 
				
			||||||
@@ -96,13 +112,7 @@ mod queries {
 | 
				
			|||||||
            .await;
 | 
					            .await;
 | 
				
			||||||
        let output = db.execute(r#"{tables{name}}"#).await;
 | 
					        let output = db.execute(r#"{tables{name}}"#).await;
 | 
				
			||||||
        let expected = r#"{"data":{"tables":[{"name":"fred"},{"name":"barney"}]}}"#;
 | 
					        let expected = r#"{"data":{"tables":[{"name":"fred"},{"name":"barney"}]}}"#;
 | 
				
			||||||
        assert!(
 | 
					        support::compare(&db, &output, &expected);
 | 
				
			||||||
            output == expected,
 | 
					 | 
				
			||||||
            "\n\n{}\nGot:  {}\nWant: {}\n\n",
 | 
					 | 
				
			||||||
            &db.schema.sdl(),
 | 
					 | 
				
			||||||
            output,
 | 
					 | 
				
			||||||
            expected
 | 
					 | 
				
			||||||
        );
 | 
					 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -118,11 +128,6 @@ mod mutations {
 | 
				
			|||||||
            .await;
 | 
					            .await;
 | 
				
			||||||
        let expected = r#"{"data":{"createTable":{"name":"william"}}}"#;
 | 
					        let expected = r#"{"data":{"createTable":{"name":"william"}}}"#;
 | 
				
			||||||
        println!("{}", &db.schema.sdl());
 | 
					        println!("{}", &db.schema.sdl());
 | 
				
			||||||
        assert!(
 | 
					        support::compare(&db, &output, &expected);
 | 
				
			||||||
            output == expected,
 | 
					 | 
				
			||||||
            "Got '{}' instead of '{}'.",
 | 
					 | 
				
			||||||
            output,
 | 
					 | 
				
			||||||
            expected
 | 
					 | 
				
			||||||
        )
 | 
					 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user