From b7082b2ec479cdea70a4b6678837f342f5700b30 Mon Sep 17 00:00:00 2001 From: Volkor <me@volkor.me> Date: Wed, 22 Mar 2023 15:36:58 +1100 Subject: [PATCH] db url in config, add more tests This hopefully fixes the tests in CI --- .gitea/workflows/test.yaml | 27 +++++++++++++++++++++++---- .gitignore | 2 +- config.sample.toml | 6 ++++-- config.toml | 6 ++++-- ephemeral.db | Bin 0 -> 12288 bytes src/main.rs | 6 +++++- 6 files changed, 37 insertions(+), 10 deletions(-) create mode 100644 ephemeral.db diff --git a/.gitea/workflows/test.yaml b/.gitea/workflows/test.yaml index c76fc9e..5baa313 100644 --- a/.gitea/workflows/test.yaml +++ b/.gitea/workflows/test.yaml @@ -1,12 +1,31 @@ # name: Format, check and test -name: cargo-check +name: format, check and test on: [push, pull_request] jobs: - check: - name: cargo check + format: + name: cargo fmt runs-on: ubuntu-latest steps: - uses: https://github.com/actions/checkout@v3 - uses: https://github.com/dtolnay/rust-toolchain@stable - - run: cargo check --all-features \ No newline at end of file + with: + components: rustfmt + - run: cargo fmt --all-features + + clippy: + name: cargo clippy + runs-on: ubuntu-latest + steps: + - uses: https://github.com/actions/checkout@v3 + - uses: https://github.com/dtolnay/rust-toolchain@stable + with: + components: clippy + - run: cargo clippy --all-features + test: + name: cargo test + runs-on: ubuntu-latest + steps: + - uses: https://github.com/actions/checkout@v3 + - uses: https://github.com/dtolnay/rust-toolchain@stable + - run: cargo test --all-features \ No newline at end of file diff --git a/.gitignore b/.gitignore index db1ea7c..56c238c 100644 --- a/.gitignore +++ b/.gitignore @@ -1,7 +1,7 @@ /target files.db /files/ -ephemeral.db +ephemeral-testing.db .timetracker ephemeral.db-shm ephemeral.db-wal diff --git a/config.sample.toml b/config.sample.toml index bef07c1..86b19f8 100644 --- a/config.sample.toml +++ b/config.sample.toml @@ -12,9 +12,11 @@ nginx_sendfile = false ## Available SQL backends: sqlite, postgres sql_backend = "sqlite" -# URL for postgres, see below for more information +# URL for the database, supporting both postgres and sqlite # https://www.postgresql.org/docs/current/libpq-connect.html#LIBPQ-CONNSTRING -postgres_url = "postgres://ephemeral:changeme@localhost:5432/ephemeral" +# url = "postgres://ephemeral:changeme@localhost:5432/ephemeral" + +url = "sqlite://ephemeral.db" [logging] # Controls the logging level of the ephemeral program, and the crates it uses. diff --git a/config.toml b/config.toml index 562edb5..4177af7 100644 --- a/config.toml +++ b/config.toml @@ -12,9 +12,11 @@ nginx_sendfile = false ## Available SQL backends: sqlite, postgres sql_backend = "sqlite" -# URL for postgres, see below for more information +# URL for the database, supporting both postgres and sqlite # https://www.postgresql.org/docs/current/libpq-connect.html#LIBPQ-CONNSTRING -postgres_url = "postgres://ephemeral:changeme@localhost:5432/ephemeral" +# url = "postgres://ephemeral:changeme@localhost:5432/ephemeral" + +url = "sqlite://ephemeral-testing.db" [logging] # Controls the logging level of the ephemeral program, and the crates it uses. diff --git a/ephemeral.db b/ephemeral.db new file mode 100644 index 0000000000000000000000000000000000000000..b95469fa030059c744925a09e1cbd0f6c7f05cbc GIT binary patch literal 12288 zcmeI%?JvVX90&00EHPqu*LdZ;swLtvNW3zXENW&dh!;}pjf*}^?>x*qk@(B}VXj?P z%Jj9!_qN`;>o@KFKKJUj<0FepM%!WJJCd%DNup_FlTt!RQ5{3-=(mD8iO2d)>!0L& z7Rmg@a#;lm<x?`gr#dtUKmY;|fB*y_009U<00RF@;KeTt>r+$O>#B6FJa!j}mJ{^) zq3xzwwM}YQw=9zyy+MP{j?ynJj&qmR>bALOHff_-JE%6#>ArbBm&r-)vouvdv}ygs zva*p{gWBeqx-#(Uy<m}Z%>tPhdSH>@VesQY=~ODOYud1`>)P9XQg54kOe9?)TWvD- zz1Vm#@A1AWQg%DNOtv`o)ZtP0$HWGOE<;sD#NE^@8+zdEQKUE8F?XvcmQ9UCBOBvl zhj~o0&$anA>bO1+Zdo_4G^f>KLVUT~;8jZ4_;Wh-Ulucesol_bc#xe<CElBB6YoU5 z(I5Z;2tWV=5P$##AOHafKmY;|_`?Dl+L%5wLP{e>sWd(9-ur%6vM0IF@zj1l`P%;} wVrhAOeo?)ays+hXH=&U6{$Ks+j|Kq<KmY;|fB*y_009U<00Izzz&{rF07J9F^8f$< literal 0 HcmV?d00001 diff --git a/src/main.rs b/src/main.rs index 86691f8..ba8a09f 100644 --- a/src/main.rs +++ b/src/main.rs @@ -54,12 +54,16 @@ async fn main() { let sql = CONFIG .get_string("database.sql_backend") .expect("Couldn't find 'sql_backend' in config. :("); + // Pipe SQL url to database initialization + let sqlurl = CONFIG + .get_string("database.url") + .expect("Couldn't find 'url' in config. :("); // This /might be able to be a match statement, but I couldn't figure it out and want to go to bed. // REVIEW: yeah do a match. Also I'm pretty sure there is an enum somewhere you can match instead of strings if sql == "sqlite" { tracing::info!("Using SQLite backend"); - let pool = SqlitePool::connect("sqlite:ephemeral.db").await.unwrap(); + let pool = SqlitePool::connect(&sqlurl).await.unwrap(); SQLITE.set(pool).unwrap(); } else if sql == "postgres" { tracing::info!("Using Postgres backend"); -- GitLab