diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 785715e..4e1b6cc 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -11,7 +11,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Checkout Repository - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Start PostgreSQL run: | docker run --name postgres-test -e POSTGRES_USER=postgres -e POSTGRES_PASSWORD=postgres -e POSTGRES_DB=test_db -p 5432:5432 -d postgres:15 @@ -19,18 +19,9 @@ jobs: - name: Set TEST_DATABASE_URL run: echo "TEST_DATABASE_URL=postgres://postgres:postgres@localhost:5432/test_db" >> $GITHUB_ENV - - name: Install Rust and Cargo - run: | - curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y - source $HOME/.cargo/env - - - name: Run Tests - run: cargo test - - uses: shuttle-hq/deploy-action@main with: name: "root" deploy-key: ${{ secrets.SHUTTLE_API_KEY }} secrets: | ROOT_SECRET = '${{ secrets.ROOT_SECRET }}' - TEST_DATABASE_URL = '${{ secrets.TEST_DATABASE_URL }}' diff --git a/tests/integration_tests.rs b/tests/integration_tests.rs index 5d66d0c..8823679 100644 --- a/tests/integration_tests.rs +++ b/tests/integration_tests.rs @@ -91,7 +91,7 @@ async fn cleanup_test_data(pool: &PgPool) { DECLARE seq RECORD; BEGIN - -- Truncate tables if they exist + -- Droppign all the tables for cleanup purpose BEGIN TRUNCATE TABLE leaderboard, leetcode_stats, codeforces_stats, member RESTART IDENTITY CASCADE; EXCEPTION @@ -100,7 +100,7 @@ async fn cleanup_test_data(pool: &PgPool) { RAISE NOTICE 'Tables do not exist, skipping TRUNCATE.'; END; - -- Reset sequences only if they exist + -- Postgres stores the sequences of unique id outside of respective tables, so need to delete those too. FOR seq IN SELECT c.relname FROM pg_class c @@ -125,13 +125,11 @@ async fn cleanup_test_data(pool: &PgPool) { } #[tokio::test] +// Additional helper test to verify database connections and basic operations async fn test_database_connection() { let database_url = get_database_url(); println!("Database URL: {}", database_url); assert!(!database_url.is_empty(), "Database URL should not be empty"); - // let result = sqlx::query("SELECT 1").fetch_one(&pool).await; - - // assert!(result.is_ok(), "Database connection and query should work"); } //test @@ -241,8 +239,6 @@ async fn test_insert_members_and_update_stats() { ), Err(e) => { println!("Error fetching Codeforces stats: {:?}", e); - // Uncomment to fail test on fetch error - // panic!("Failed to fetch Codeforces stats") } } } @@ -280,5 +276,3 @@ async fn test_insert_members_and_update_stats() { cleanup_test_data(&pool).await; } - -// Additional helper test to verify database connections and basic operations