1/*
2 * SPDX-License-Identifier: Apache-2.0
3 * SPDX-FileCopyrightText: 2026 The Contributors to Eclipse OpenSOVD (see CONTRIBUTORS)
4 *
5 * See the NOTICE file(s) distributed with this work for additional
6 * information regarding copyright ownership.
7 *
8 * This program and the accompanying materials are made available under the
9 * terms of the Apache License Version 2.0 which is available at
10 * https://www.apache.org/licenses/LICENSE-2.0
11 */
12
13use axum::http::StatusCode;
14use opensovd_cda_lib::cda_version;
15use reqwest::Method;
16
17use crate::util::{
18 http::{extract_field_from_json, response_to_json},
19 runtime::setup_integration_test,
20};
21
22fn assert_version_response(json: &serde_json::Value) {
23 let id = extract_field_from_json::<String>(json, "id").expect("Missing 'id' field");
24 assert_eq!(id, "version");
25
26 let data =
27 extract_field_from_json::<serde_json::Value>(json, "data").expect("Missing 'data' field");
28 let name = extract_field_from_json::<String>(&data, "name").expect("Missing 'data.name' field");
29 assert_eq!(name, "Eclipse OpenSOVD Classic Diagnostic Adapter");
30
31 let api =
32 extract_field_from_json::<serde_json::Value>(&data, "api").expect("Missing 'data.api'");
33 let api_version =
34 extract_field_from_json::<String>(&api, "version").expect("Missing 'data.api.version'");
35 assert_eq!(api_version, "1.1");
36
37 let implementation = extract_field_from_json::<serde_json::Value>(&data, "implementation")
38 .expect("Missing 'data.implementation'");
39 let impl_version = extract_field_from_json::<String>(&implementation, "version")
40 .expect("Missing 'data.implementation.version'");
41 assert_eq!(impl_version, cda_version());
42}
43
[docs]44/// [[ itest~sovd-api-version-endpoint, Version Endpoint Integration Test ]]
45#[tokio::test]
46async fn test_version_endpoint() {
47 let (runtime, _lock) = setup_integration_test(true).await.unwrap();
48 let host = &runtime.config.server.address;
49 let port = runtime.config.server.port;
50
51 // Test app-scoped version endpoint
52 let app_url = reqwest::Url::parse(&format!(
53 "http://{host}:{port}/vehicle/v15/apps/sovd2uds/data/version"
54 ))
55 .expect("Invalid URL");
56
57 let response =
58 crate::util::http::send_request(StatusCode::OK, Method::GET, None, None, app_url)
59 .await
60 .expect("GET app version endpoint failed");
61
62 let json = response_to_json(&response).expect("Failed to parse version response");
63 assert_version_response(&json);
64
65 // Test global version endpoint
66 let global_url = reqwest::Url::parse(&format!("http://{host}:{port}/vehicle/v15/data/version"))
67 .expect("Invalid URL");
68
69 let response =
70 crate::util::http::send_request(StatusCode::OK, Method::GET, None, None, global_url)
71 .await
72 .expect("GET global version endpoint failed");
73
74 let json = response_to_json(&response).expect("Failed to parse version response");
75 assert_version_response(&json);
76}