Tests: search integration on UUIDv7 ids, and in checks

1a5b596 · Gabriel Morell · 2026-10-23 06:07

5 files +30 -14
Message
{commit_body(@commit)}

Files changed

modified .forgejo/workflows/checks.yml
+22 −11
@@ -1,14 +1,10 @@
1 1 name: checks
2 2 # A pull request's build and tests: the workspace compiled with the
3 −# Dockerfile's toolchain, and its unit tests and tests/jobs_upsert.rs
4 −# run. Every pull request — the security update PRs gg-security opens
5 −# (dependency-updates.yml) most of all, since a bump that resolves isn't
6 −# one that builds.
7 −#
8 −# tests/search_integration.rs is left out: it still uses i64 ids from
9 −# before the UUIDv7 migration and doesn't compile. Once it does, test
10 −# the whole workspace here with a postgres:17 service and
11 −# DMS_TEST_DATABASE_URL pointing at it, as gitgud's checks.yml does.
3 +# Dockerfile's toolchain and `cargo test` against a throwaway Postgres
4 +# (tests/search_integration.rs runs only when DMS_TEST_DATABASE_URL is
5 +# set, each test in a schema of its own). Every pull request — the
6 +# security update PRs gg-security opens (dependency-updates.yml) most of
7 +# all, since a bump that resolves isn't one that builds.
12 8 on:
13 9 pull_request:
14 10 workflow_dispatch:
@@ -19,6 +15,21 @@ permissions:
19 15 jobs:
20 16 test:
21 17 runs-on: self-hosted
18 + # As compose.yml's database.
19 + services:
20 + postgres:
21 + image: postgres:17
22 + env:
23 + POSTGRES_DB: dms
24 + POSTGRES_USER: dms_user
25 + POSTGRES_PASSWORD: dms_password
26 + options: >-
27 + --health-cmd "pg_isready -U dms_user -d dms"
28 + --health-interval 5s
29 + --health-timeout 5s
30 + --health-retries 20
31 + env:
32 + DMS_TEST_DATABASE_URL: postgres://dms_user:dms_password@postgres:5432/dms
22 33 steps:
23 34 - uses: actions/checkout@v4
24 35
@@ -38,7 +49,7 @@ jobs:
38 49 echo "$HOME/.cargo/bin" >> "$GITHUB_PATH"
39 50
40 51 - name: Build
41 − run: cargo build --locked --workspace
52 + run: cargo build --locked --workspace --all-targets
42 53
43 54 - name: Test
44 − run: cargo test --locked --workspace --lib --bins --test jobs_upsert
55 + run: cargo test --locked --workspace
modified tests/search_integration.rs
+8 −3
@@ -10,6 +10,7 @@ use chrono::Utc;
10 10 use migration::MigratorTrait;
11 11 use sea_orm::{ActiveModelTrait, ConnectOptions, ConnectionTrait, Database, DatabaseConnection, Set, Statement};
12 12 use std::sync::atomic::{AtomicUsize, Ordering};
13 +use uuid::Uuid;
13 14
14 15 use dms::entities::{tags as tags_entity, uploads, users};
15 16 use dms::handlers::uploads::{run_search_for_user, SearchSources};
@@ -72,9 +73,12 @@ impl Drop for SchemaGuard {
72 73 }
73 74 }
74 75
75 −async fn make_user(db: &DatabaseConnection, username: &str) -> i64 {
76 +// Ids are UUIDv7s the application assigns (the columns have no default), so
77 +// the fixtures set them the same way.
78 +async fn make_user(db: &DatabaseConnection, username: &str) -> Uuid {
76 79 let now = Utc::now();
77 80 let user = users::ActiveModel {
81 + id: Set(Uuid::now_v7()),
78 82 username: Set(username.to_string()),
79 83 email: Set(format!("{username}@test")),
80 84 password_hash: Set("x".into()),
@@ -87,9 +91,10 @@ async fn make_user(db: &DatabaseConnection, username: &str) -> i64 {
87 91 user.insert(db).await.expect("insert user").id
88 92 }
89 93
90 −async fn make_upload(db: &DatabaseConnection, user_id: i64, file_name: &str) -> i64 {
94 +async fn make_upload(db: &DatabaseConnection, user_id: Uuid, file_name: &str) -> Uuid {
91 95 let now = Utc::now();
92 96 let m = uploads::ActiveModel {
97 + id: Set(Uuid::now_v7()),
93 98 user_id: Set(user_id),
94 99 file_name_original: Set(file_name.to_string()),
95 100 file_name_generated: Set(format!("gen/{file_name}")),
@@ -223,7 +228,7 @@ async fn search_namespace_wildcard_returns_all_uploads_in_ns() {
223 228 .await
224 229 .expect("search");
225 230 assert_eq!(result.total, 2, "wildcard ns should match all tags in 'species'");
226 − let ids: std::collections::HashSet<i64> = result.rows.iter().map(|r| r.id).collect();
231 + let ids: std::collections::HashSet<Uuid> = result.rows.iter().map(|r| r.id).collect();
227 232 assert!(ids.contains(&u1));
228 233 assert!(ids.contains(&u2));
229 234 assert!(!ids.contains(&u3));

Parents: bdf9305