agama/rust/agama-server/tests/l10n.rs
Josef Reidinger e9b4908a72
allow minimal installed system without libzypp (#2512)
## Problem

- follow-up to #2493
- https://trello.com/c/czY7e3c0

For SLES16 the minimal system can be without libzypp. If it is case
together with onlyRequires flag, then software service crashes when
trying to load zypp.conf.


## Solution

Add check if file exists and if not, just log it and continue.
Also change as agreed modification of zypp.conf to explicitly write
onlyRequires if user explicitly mention it in profile to not just use
libzypp default.


## Testing

- *Tested manually*


## Documentation

*Remember to look at it from the user's perspective. Yes you have made
the compiler happy.*
*But will the **humans** even know about your contribution? Sometimes
they cannot miss it,*
*other times they need advertisement and explanation.*

*Look for relevant sections and adjust:*
- The description parts of the [JSON schema][profile.schema.json]
- Is the CLI affected? See [cli.md][] for a complete overview,
  change the `///` comments (rust doc)
  and update the .md with `cargo xtask markdown`
- <https://agama-project.github.io/> ([source][gh.io])
- Run: `git ls-files '*.md'`

[cli.md]:
https://github.com/agama-project/agama-project.github.io/blob/main/docs/user/cli.md
[profile.schema.json]:
https://github.com/agama-project/agama/blob/master/rust/agama-lib/share/profile.schema.json
[gh.io]: https://github.com/agama-project/agama-project.github.io/

---------

Co-authored-by: Ladislav Slezák <lslezak@suse.com>
2025-06-26 14:00:41 +02:00

133 lines
4.4 KiB
Rust

// Copyright (c) [2024] SUSE LLC
//
// All Rights Reserved.
//
// This program is free software; you can redistribute it and/or modify it
// under the terms of the GNU General Public License as published by the Free
// Software Foundation; either version 2 of the License, or (at your option)
// any later version.
//
// This program is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
// more details.
//
// You should have received a copy of the GNU General Public License along
// with this program; if not, contact SUSE LLC.
//
// To contact SUSE LLC about this file by physical or electronic mail, you may
// find current contact information at www.suse.com.
pub mod common;
use std::error::Error;
use agama_server::l10n::web::l10n_service;
use axum::{
body::Body,
http::{Request, StatusCode},
Router,
};
use common::{body_to_string, DBusServer};
use tokio::{sync::broadcast::channel, test};
use tower::ServiceExt;
async fn build_service(dbus: zbus::Connection) -> Router {
let (tx, _) = channel(16);
l10n_service(dbus, tx).await.unwrap()
}
#[test]
// FIXME: temporarily skip the test in CI
#[cfg(not(ci))]
async fn test_get_config() -> Result<(), Box<dyn Error>> {
let dbus_server = DBusServer::new().start().await?;
let service = build_service(dbus_server.connection()).await;
let request = Request::builder()
.uri("/config")
.body(Body::empty())
.unwrap();
let response = service.oneshot(request).await.unwrap();
assert_eq!(response.status(), StatusCode::OK);
Ok(())
}
#[test]
// FIXME: temporarily skip the test in CI
#[cfg(not(ci))]
async fn test_locales() -> Result<(), Box<dyn Error>> {
let dbus_server = DBusServer::new().start().await?;
let service = build_service(dbus_server.connection()).await;
let request = Request::builder()
.uri("/locales")
.body(Body::empty())
.unwrap();
let response = service.oneshot(request).await.unwrap();
assert_eq!(response.status(), StatusCode::OK);
let body = body_to_string(response.into_body()).await;
assert!(body.contains(r#""language":"English""#));
Ok(())
}
#[test]
// FIXME: temporarily skip the test in CI
#[cfg(not(ci))]
async fn test_keymaps() -> Result<(), Box<dyn Error>> {
let dbus_server = DBusServer::new().start().await?;
let service = build_service(dbus_server.connection()).await;
let request = Request::builder()
.uri("/keymaps")
.body(Body::empty())
.unwrap();
let response = service.oneshot(request).await.unwrap();
assert_eq!(response.status(), StatusCode::OK);
let body = body_to_string(response.into_body()).await;
assert!(body.contains(r#""id":"us""#));
Ok(())
}
#[test]
// FIXME: temporarily skip the test in CI
#[cfg(not(ci))]
async fn test_timezones() -> Result<(), Box<dyn Error>> {
let dbus_server = DBusServer::new().start().await?;
let service = build_service(dbus_server.connection()).await;
let request = Request::builder()
.uri("/timezones")
.body(Body::empty())
.unwrap();
let response = service.oneshot(request).await.unwrap();
assert_eq!(response.status(), StatusCode::OK);
let body = body_to_string(response.into_body()).await;
assert!(body.contains(r#""code":"Atlantic/Canary""#));
Ok(())
}
#[test]
// FIXME: temporarily skip the test in CI
#[cfg(not(ci))]
async fn test_set_config_locales() -> Result<(), Box<dyn Error>> {
let dbus_server = DBusServer::new().start().await?;
let service = build_service(dbus_server.connection()).await;
let content = "{\"locales\":[\"es_ES.UTF-8\"]}";
let body = Body::from(content);
let request = Request::patch("/config")
.header("Content-Type", "application/json")
.body(body)?;
let response = service.clone().oneshot(request).await?;
assert_eq!(response.status(), StatusCode::NO_CONTENT);
// check whether the value changed
let request = Request::get("/config")
.header("Content-Type", "application/json")
.body(Body::empty())?;
let response = service.oneshot(request).await?;
assert_eq!(response.status(), StatusCode::OK);
let body = body_to_string(response.into_body()).await;
assert!(body.contains(r#""locales":["es_ES.UTF-8"]"#));
// TODO: check whether the D-Bus value was synchronized
Ok(())
}