Skip to content

Commit 9bb20ad

Browse files
committed
test on-db file hosting
1 parent a2412c3 commit 9bb20ad

File tree

1 file changed

+20
-12
lines changed

1 file changed

+20
-12
lines changed

tests/index.rs

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -719,28 +719,36 @@ async fn test_routing_with_db_fs_and_prefix() {
719719
state
720720
.db
721721
.connection
722-
.execute(format!("DROP TABLE IF EXISTS sqlpage_files; {create_table_sql}").as_str())
722+
.execute(format!("DROP TABLE IF EXISTS sqlpage_files; {create_table_sql}").as_ref())
723723
.await
724724
.unwrap();
725725

726726
// Insert test file into database using database-specific syntax
727-
let db_kind = state.db.connection.any_kind();
728-
let insert_sql = match db_kind {
729-
sqlx::any::AnyKind::Mssql => {
730-
"INSERT INTO sqlpage_files(path, contents) VALUES (?, CONVERT(VARBINARY(MAX), ?))"
731-
}
732-
_ => "INSERT INTO sqlpage_files(path, contents) VALUES (?, ?)",
727+
let insert_sql = match state.db.connection.any_kind() {
728+
sqlx::any::AnyKind::Mssql => "INSERT INTO sqlpage_files(path, contents) VALUES ('on_db.sql', CONVERT(VARBINARY(MAX), 'select ''text'' as component, ''Hi from db !'' AS contents;'))",
729+
_ => "INSERT INTO sqlpage_files(path, contents) VALUES ('on_db.sql', 'select ''text'' as component, ''Hi from db !'' AS contents;')"
733730
};
734-
735-
sqlx::query(insert_sql)
736-
.bind("tests/sql_test_files/it_works_simple.sql")
737-
.bind("SELECT 'It works !' as message;")
738-
.execute(&state.db.connection)
731+
state
732+
.db
733+
.connection
734+
.execute(insert_sql)
739735
.await
740736
.unwrap();
741737

742738
let app_data = actix_web::web::Data::new(state);
743739

740+
// Test on_db.sql
741+
let resp = req_path_with_app_data("/prefix/on_db.sql", app_data.clone())
742+
.await
743+
.unwrap();
744+
assert_eq!(resp.status(), http::StatusCode::OK);
745+
let body = test::read_body(resp).await;
746+
let body_str = String::from_utf8(body.to_vec()).unwrap();
747+
assert!(
748+
body_str.contains("Hi from db !"),
749+
"{body_str}\nexpected to contain: Hi from db !"
750+
);
751+
744752
// Test basic routing with prefix
745753
let resp = req_path_with_app_data(
746754
"/prefix/tests/sql_test_files/it_works_simple.sql",

0 commit comments

Comments
 (0)