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)]
 | 
			
		||||
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);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user