Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
teclator committed Mar 21, 2024
1 parent f35ef04 commit af3ce48
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 26 deletions.
4 changes: 2 additions & 2 deletions rust/agama-server/src/web/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ async fn build_service_status_proxy<'a>(
/// ).await.unwrap();
/// let router: Router<HelloWorldState> = Router::new()
/// .route("/hello", get(hello))
/// .merge(progress)
/// .merge(progress_router)
/// .with_state(HelloWorldState {});
/// });
/// ```
Expand Down Expand Up @@ -238,7 +238,7 @@ async fn build_progress_proxy<'a>(
/// ```no_run
/// # use axum::{extract::State, routing::get, Json, Router};
/// # use agama_lib::connection;
/// # use agama_server::web::common::service_status_router;
/// # use agama_server::web::common::{issues_router, service_status_router};
/// # use tokio_test;
///
/// # tokio_test::block_on(async {
Expand Down
23 changes: 19 additions & 4 deletions rust/agama-server/tests/network.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use agama_lib::network::{
};
use agama_server::network::{
self,
model::{self, Ipv4Method, Ipv6Method},
model::{self, GeneralState, Ipv4Method, Ipv6Method, NetworkStateItems},
Adapter, NetworkAdapterError, NetworkService, NetworkState,
};
use async_trait::async_trait;
Expand All @@ -21,7 +21,10 @@ pub struct NetworkTestAdapter(network::NetworkState);

#[async_trait]
impl Adapter for NetworkTestAdapter {
async fn read(&self) -> Result<network::NetworkState, NetworkAdapterError> {
async fn read(
&self,
_: Vec<NetworkStateItems>,
) -> Result<network::NetworkState, NetworkAdapterError> {
Ok(self.0.clone())
}

Expand All @@ -34,12 +37,18 @@ impl Adapter for NetworkTestAdapter {
async fn test_read_connections() -> Result<(), Box<dyn Error>> {
let mut server = DBusServer::new().start().await?;

let general_state = GeneralState {
wireless_enabled: false,
connectivity: true,
networking_enabled: true,
};

let device = model::Device {
name: String::from("eth0"),
type_: DeviceType::Ethernet,
};
let eth0 = model::Connection::new("eth0".to_string(), DeviceType::Ethernet);
let state = NetworkState::new(vec![device], vec![eth0]);
let state = NetworkState::new(general_state, vec![], vec![device], vec![eth0]);
let adapter = NetworkTestAdapter(state);

NetworkService::start(&server.connection(), adapter).await?;
Expand Down Expand Up @@ -143,12 +152,18 @@ async fn test_add_bond_connection() -> Result<(), Box<dyn Error>> {
async fn test_update_connection() -> Result<(), Box<dyn Error>> {
let mut server = DBusServer::new().start().await?;

let general_state = GeneralState {
wireless_enabled: false,
connectivity: true,
networking_enabled: true,
};

let device = model::Device {
name: String::from("eth0"),
type_: DeviceType::Ethernet,
};
let eth0 = model::Connection::new("eth0".to_string(), DeviceType::Ethernet);
let state = NetworkState::new(vec![device], vec![eth0]);
let state = NetworkState::new(general_state, vec![], vec![device], vec![eth0]);
let adapter = NetworkTestAdapter(state);

NetworkService::start(&server.connection(), adapter).await?;
Expand Down
29 changes: 9 additions & 20 deletions rust/agama-server/tests/service.rs
Original file line number Diff line number Diff line change
@@ -1,41 +1,30 @@
pub mod common;

use agama_server::{
service,
web::{generate_token, MainServiceBuilder, ServiceConfig},
};
use agama_server::web::{generate_token, MainServiceBuilder, ServiceConfig};
use axum::{
body::Body,
http::{Method, Request, StatusCode},
response::Response,
routing::get,
Router,
};
use common::{body_to_string, DBusServer};
use common::body_to_string;
use std::{error::Error, path::PathBuf};
use tokio::{sync::broadcast::channel, test};
use tower::ServiceExt;

async fn build_service() -> Router {
let (tx, _) = channel(16);
let server = DBusServer::new().start().await.unwrap();
service(
ServiceConfig::default(),
tx,
server.connection(),
public_dir(),
)
.await
.unwrap()
}

fn public_dir() -> PathBuf {
std::env::current_dir().unwrap().join("public")
}

#[test]
async fn test_ping() -> Result<(), Box<dyn Error>> {
let web_service = build_service().await;
let config = ServiceConfig::default();
let (tx, _) = channel(16);
let web_service = MainServiceBuilder::new(tx, public_dir())
.add_service("/protected", get(protected))
.with_config(config)
.build();

let request = Request::builder()
.uri("/api/ping")
.body(Body::empty())
Expand Down

0 comments on commit af3ce48

Please sign in to comment.