Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Database tests fail if no env variables are set and when they are run twice. #631

Open
mmartinv opened this issue Feb 27, 2024 · 1 comment
Labels
bug Something isn't working

Comments

@mmartinv
Copy link
Contributor

Running cargo test fails in database tests if no env variables are set:

 cargo test -p fdo-db --lib
    Finished test [unoptimized + debuginfo] target(s) in 0.09s
     Running unittests src/lib.rs (target/debug/deps/fdo_db-307ba6269451e378)

running 3 tests
test sqlite::tests::test_manufacturer_database ... FAILED
test sqlite::tests::test_owner_database ... FAILED
test sqlite::tests::test_rendezvous_database ... FAILED

failures:

---- sqlite::tests::test_manufacturer_database stdout ----
Current directory: Ok("/home/mmartinv/devel/src/github.com/fdo-rs/fido-device-onboard-rs/db")
thread 'sqlite::tests::test_manufacturer_database' panicked at db/src/sqlite.rs:35:14:
SQLITE_MANUFACTURER_DATABASE_URL must be set: NotPresent
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

---- sqlite::tests::test_owner_database stdout ----
Current directory: Ok("/home/mmartinv/devel/src/github.com/fdo-rs/fido-device-onboard-rs/db")
thread 'sqlite::tests::test_owner_database' panicked at db/src/sqlite.rs:103:51:
SQLITE_OWNER_DATABASE_URL must be set: NotPresent

---- sqlite::tests::test_rendezvous_database stdout ----
Current directory: Ok("/home/mmartinv/devel/src/github.com/fdo-rs/fido-device-onboard-rs/db")
thread 'sqlite::tests::test_rendezvous_database' panicked at db/src/sqlite.rs:221:14:
SQLITE_RENDEZVOUS_DATABASE_URL must be set: NotPresent


failures:
    sqlite::tests::test_manufacturer_database
    sqlite::tests::test_owner_database
    sqlite::tests::test_rendezvous_database

test result: FAILED. 0 passed; 3 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s

error: test failed, to rerun pass `-p fdo-db --lib`

It would be great if the databases were created and configured automatically before running the tests.
Also some of the database tests fail when running the tests twice:

export SQLITE_MANUFACTURER_DATABASE_URL=sqlite://manufacturer.db ; 
diesel migration run --migration-dir migrations/migrations_manufacturing_server_sqlite --database-url $SQLITE_MANUFACTURER_DATABASE_URL
Running migration 2023-10-03-152801_create_db

export SQLITE_OWNER_DATABASE_URL=sqlite://owner.db
diesel migration run --migration-dir migrations/migrations_owner_onboarding_server_sqlite --database-url $SQLITE_OWNER_DATABASE_URL
Running migration 2023-10-03-152801_create_db

export SQLITE_RENDEZVOUS_DATABASE_URL=sqlite://rendezvous.db ; 
diesel migration run --migration-dir migrations/migrations_rendezvous_server_sqlite --database-url $SQLITE_RENDEZVOUS_DATABASE_URL 
Running migration 2023-10-03-152801_create_db

mv *.db db/

# First execution goes well
cargo test -p fdo-db --lib
    Finished test [unoptimized + debuginfo] target(s) in 0.11s
     Running unittests src/lib.rs (target/debug/deps/fdo_db-307ba6269451e378)

running 3 tests
test sqlite::tests::test_rendezvous_database ... ok
test sqlite::tests::test_manufacturer_database ... ok
test sqlite::tests::test_owner_database ... ok

test result: ok. 3 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.14s

# Second execution fails
cargo test -p fdo-db --lib
    Finished test [unoptimized + debuginfo] target(s) in 0.09s
     Running unittests src/lib.rs (target/debug/deps/fdo_db-307ba6269451e378)

running 3 tests
test sqlite::tests::test_owner_database ... FAILED
test sqlite::tests::test_manufacturer_database ... ok
test sqlite::tests::test_rendezvous_database ... ok

failures:

---- sqlite::tests::test_owner_database stdout ----
Current directory: Ok("/home/mmartinv/devel/src/github.com/fdo-rs/fido-device-onboard-rs/db")
Error: UNIQUE constraint failed: owner_vouchers.guid


failures:
    sqlite::tests::test_owner_database

test result: FAILED. 2 passed; 1 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.10s
@mmartinv mmartinv added the bug Something isn't working label Feb 27, 2024
@mmartinv mmartinv changed the title Database tests fails if no env variables are set and when they are run twice. Database tests fail if no env variables are set and when they are run twice. Feb 27, 2024
@7flying
Copy link
Contributor

7flying commented Feb 27, 2024

The second failure is expected (and just in the owner database) since the test does not remove all the OVs. The tests expect an empty database at every run.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants