about summary refs log tree commit diff
path: root/tests/version.rs
blob: 0753367cf7bfd3828f1ec2b63a1813b4ec8b1db1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
use axum::body::Body;
use axum::http::{Request, StatusCode};
use http_body_util::BodyExt;
use serde_json::Value;
use tower::ServiceExt;

#[allow(dead_code)]
mod common;

#[tokio::test]
async fn version_returns_ok_with_json_record() {
    let response = genenetwork4::app()
        .oneshot(
            Request::builder()
                .uri("/version")
                .body(Body::empty())
                .unwrap(),
        )
        .await
        .unwrap();

    assert_eq!(response.status(), StatusCode::OK);
    assert_eq!(
        response.headers().get("content-type").unwrap(),
        "application/json"
    );

    let body = response.into_body().collect().await.unwrap().to_bytes();
    let record: Value = common::data(&body);

    assert_eq!(record["name"], "GeneNetwork4");
    assert_eq!(record["short_name"], "GN4AI");
    assert_eq!(record["version"], 4.0);
    assert_eq!(record["release"], 1);
    // Stamped at build time (see build.rs): check the shape, and that the
    // three provenance fields agree with each other.
    assert_eq!(record["date"].as_str().unwrap().len(), 8);
    let git = record["git"].as_str().unwrap();
    assert!(!git.is_empty());
    assert_eq!(
        record["dirty"].as_bool().unwrap(),
        git.ends_with("-dirty"),
        "`dirty` mirrors the -dirty suffix: {record}"
    );
    assert!(!record["branch"].as_str().unwrap().is_empty());
    let digest = record["source_digest"].as_str().unwrap();
    assert!(
        digest == "unknown" || (digest.len() == 16 && digest.chars().all(|c| c.is_ascii_hexdigit())),
        "a 64-bit hex digest, or unknown: {digest}"
    );
}