diff options
| author | Pjotr Prins <pjotr.public01@thebird.nl> | 2026-10-01 16:01:20 +0000 |
|---|---|---|
| committer | Pjotr <wrk@bosa.lan> | 2026-10-01 16:01:20 +0000 |
| commit | e8fe116ef4a996a8281bf0b43bed5e9d39c766c8 (patch) | |
| tree | 00170767d45e96ff4c53538201e50321265df38d /src | |
| parent | 457a463286c2feb1e6d90460acb65927177fcc09 (diff) | |
| download | genenetwork4-e8fe116ef4a996a8281bf0b43bed5e9d39c766c8.tar.gz | |
Add /version endpoint, extract shared python test helper.
* .gitignore: Add __pycache__. * src/lib.rs (app): Add /version route. (VersionInfo, version): New struct and handler, returning name, short_name, version, release, date, and git as a JSON record. * build.rs: New file. Embeds GN4_GIT_HASH and GN4_COMMIT_DATE via cargo:rustc-env, read from git rev-parse and git show of HEAD. * Cargo.toml (dependencies): Add serde with derive feature. [dev-dependencies]: Add serde_json. * tests/version.rs: New file. * test/python/server_test_case.py: New file. ServerTestCase, wait_for_port, BINARY, HOST, PORT moved here from test/python/test_hello_world.py. * test/python/test_hello_world.py: Use server_test_case.ServerTestCase instead of duplicating setUpClass and tearDownClass. * test/python/test_version.py: New file. * guix.scm: Add (gnu packages version-control) to use-modules. (genenetwork4-git)[native-inputs]: Add git-minimal. (genenetwork4-git)[arguments]<#:phases>[python-rest-test]: Run test/python with python3 -m unittest discover instead of invoking test_hello_world.py directly, so test_version.py also runs.
Diffstat (limited to 'src')
| -rw-r--r-- | src/lib.rs | 28 |
1 files changed, 26 insertions, 2 deletions
diff --git a/src/lib.rs b/src/lib.rs index d5bbaec..230b878 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,11 +1,35 @@ -use axum::{routing::get, Router}; +use axum::{routing::get, Json, Router}; +use serde::Serialize; /// Build the application router. Public so integration tests (tests/) and /// the binary (src/main.rs) can both use it without binding a real socket. pub fn app() -> Router { - Router::new().route("/", get(hello_world)) + Router::new() + .route("/", get(hello_world)) + .route("/version", get(version)) } async fn hello_world() -> &'static str { "Hello, world!" } + +#[derive(Serialize)] +struct VersionInfo { + name: &'static str, + short_name: &'static str, + version: f64, + release: u32, + date: &'static str, + git: &'static str, +} + +async fn version() -> Json<VersionInfo> { + Json(VersionInfo { + name: "GeneNetwork4", + short_name: "GN4AI", + version: 4.0, + release: 1, + date: env!("GN4_COMMIT_DATE"), + git: env!("GN4_GIT_HASH"), + }) +} |
