Skip to content

Commit

Permalink
Add junit reporting, migration tests
Browse files Browse the repository at this point in the history
  • Loading branch information
cmackenzie1 committed Feb 1, 2025
1 parent 4e0b36b commit ea369d5
Show file tree
Hide file tree
Showing 2 changed files with 95 additions and 3 deletions.
12 changes: 9 additions & 3 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ name: CI

on:
push:
branches: [ "main" ]
branches: ["main"]
pull_request:
branches: [ "main" ]
branches: ["main"]

env:
CARGO_TERM_COLOR: always
Expand Down Expand Up @@ -36,4 +36,10 @@ jobs:
uses: codecov/codecov-action@v5
with:
files: lcov.info
token: ${{ secrets.CODECOV_TOKEN }}
token: ${{ secrets.CODECOV_TOKEN }}

- name: Upload test results to Codecov
if: ${{ !cancelled() }}
uses: codecov/test-results-action@v1
with:
token: ${{ secrets.CODECOV_TOKEN }}
86 changes: 86 additions & 0 deletions torii-auth-email/src/migrations/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,89 @@ impl PluginMigration for AddPasswordHashColumn {
Ok(())
}
}

#[cfg(test)]
mod tests {
use super::*;

use sqlx::SqlitePool;

#[tokio::test]
async fn test_migration_up_down_up() -> Result<(), Error> {
let pool = SqlitePool::connect("sqlite::memory:")
.await
.expect("Failed to create test pool");

// Create users table first since we're adding a column to it
sqlx::query(
r#"
CREATE TABLE users (
id TEXT PRIMARY KEY,
email TEXT NOT NULL UNIQUE,
name TEXT,
email_verified_at TIMESTAMP,
created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP
)
"#,
)
.execute(&pool)
.await
.expect("Failed to create users table");

let migration = AddPasswordHashColumn;

// First up migration
migration.up(&pool).await?;

// Verify column exists
let has_column = sqlx::query(
r#"
SELECT 1 FROM pragma_table_info('users')
WHERE name = 'password_hash'
"#,
)
.fetch_optional(&pool)
.await?;
assert!(
has_column.is_some(),
"Column should exist after up migration"
);

// Down migration
migration.down(&pool).await?;

// Verify column was removed
let has_column = sqlx::query(
r#"
SELECT 1 FROM pragma_table_info('users')
WHERE name = 'password_hash'
"#,
)
.fetch_optional(&pool)
.await?;
assert!(
has_column.is_none(),
"Column should not exist after down migration"
);

// Second up migration
migration.up(&pool).await?;

// Verify column exists again
let has_column = sqlx::query(
r#"
SELECT 1 FROM pragma_table_info('users')
WHERE name = 'password_hash'
"#,
)
.fetch_optional(&pool)
.await?;
assert!(
has_column.is_some(),
"Column should exist after second up migration"
);

Ok(())
}
}

0 comments on commit ea369d5

Please sign in to comment.