tests now working via make file
This commit is contained in:
13
server/Makefile
Normal file
13
server/Makefile
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
# Makefile
|
||||||
|
|
||||||
|
test: reset_db run_tests
|
||||||
|
|
||||||
|
reset_db:
|
||||||
|
@echo "Resetting test database..."
|
||||||
|
@./scripts/reset_test_db.sh
|
||||||
|
|
||||||
|
run_tests:
|
||||||
|
@echo "Running tests..."
|
||||||
|
@cargo test
|
||||||
|
|
||||||
|
.PHONY: test
|
||||||
9
server/scripts/reset_test_db.sh
Executable file
9
server/scripts/reset_test_db.sh
Executable file
@@ -0,0 +1,9 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
# scripts/reset_test_db.sh
|
||||||
|
|
||||||
|
DATABASE_URL=${TEST_DATABASE_URL:-"postgres://multi_psql_dev:3@localhost:5432/multi_rust_test"}
|
||||||
|
|
||||||
|
echo "Reset db script"
|
||||||
|
yes | sqlx database drop --database-url "$DATABASE_URL"
|
||||||
|
sqlx database create --database-url "$DATABASE_URL"
|
||||||
|
echo "Test database reset complete."
|
||||||
@@ -142,6 +142,33 @@ async fn test_create_table_success(#[future] pool: PgPool) {
|
|||||||
.await;
|
.await;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[rstest]
|
||||||
|
#[tokio::test]
|
||||||
|
async fn test_fail_on_invalid_decimal_format(#[future] pool: PgPool) {
|
||||||
|
let pool = pool.await;
|
||||||
|
let invalid_types = vec![
|
||||||
|
"decimal(0,0)", // precision too small
|
||||||
|
"decimal(5,10)", // scale > precision
|
||||||
|
"decimal(10)", // missing scale
|
||||||
|
"decimal(a,b)", // non-numeric
|
||||||
|
];
|
||||||
|
|
||||||
|
for invalid_type in invalid_types {
|
||||||
|
let request = PostTableDefinitionRequest {
|
||||||
|
profile_name: "default".into(),
|
||||||
|
table_name: format!("table_{}", invalid_type),
|
||||||
|
columns: vec![ColumnDefinition {
|
||||||
|
name: "amount".into(),
|
||||||
|
field_type: invalid_type.into(),
|
||||||
|
}],
|
||||||
|
..Default::default()
|
||||||
|
};
|
||||||
|
|
||||||
|
let result = post_table_definition(&pool, request).await;
|
||||||
|
assert_eq!(result.unwrap_err().code(), Code::InvalidArgument);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[rstest]
|
#[rstest]
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
async fn test_create_table_with_link(
|
async fn test_create_table_with_link(
|
||||||
|
|||||||
Reference in New Issue
Block a user