From 3c23cf9b4b3f7d951d4ec40d03615cd86439e159 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christina=20S=C3=B8rensen?= Date: Tue, 14 May 2024 10:39:08 +0200 Subject: [PATCH] feat: basic garage testing, formatting MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Christina Sørensen --- nixos/tests/status.nix | 49 ++++++++++++++++++++ src/api/ha_registry/v1/routes.rs | 2 +- src/api/ha_registry/v1/status/handlers.rs | 10 ++-- src/api/ha_registry/v1/status/mod.rs | 4 ++ src/api/oci/v2/handlers/mod.rs | 1 - src/api/oci/v2/mod.rs | 2 +- src/api/oci/v2/{handlers => oci}/handlers.rs | 0 src/api/oci/v2/oci/mod.rs | 6 +++ src/api/oci/v2/routes.rs | 2 +- src/main.rs | 4 +- 10 files changed, 68 insertions(+), 12 deletions(-) delete mode 100644 src/api/oci/v2/handlers/mod.rs rename src/api/oci/v2/{handlers => oci}/handlers.rs (100%) create mode 100644 src/api/oci/v2/oci/mod.rs diff --git a/nixos/tests/status.nix b/nixos/tests/status.nix index f22e770..e94cee3 100644 --- a/nixos/tests/status.nix +++ b/nixos/tests/status.nix @@ -11,6 +11,55 @@ nixosTest { name = "ha-registry status test"; nodes = { + s3 = let + s3_port = 3900; + rpc_port = 3901; + admin_api_port = 3903; + in + {pkgs, ...}: { + users = { + groups.garage = {}; + + users.garage = { + isSystemUser = true; + createHome = false; + group = "garage"; + }; + }; + + services = { + garage = { + enable = true; + package = pkgs.garage; + + settings = { + #metadata_dir = "/srv/storage/garage/meta"; + #data_dir = "/srv/storage/garage/data"; + #metadata_fsync = false; # synchronous mode for the database engine + + db_engine = "lmdb"; + replication_mode = "none"; + compression_level = -1; + + # For inter-node comms + rpc_bind_addr = "[::]:${builtins.toString rpc_port}"; + rpc_secret = "4425f5c26c5e11581d3223904324dcb5b5d5dfb14e5e7f35e38c595424f5f1e6"; + # rpc_public_addr = "127.0.0.1:3901"; + + # Standard S3 api endpoint + s3_api = { + s3_region = "helios"; + api_bind_addr = "[::]:${builtins.toString s3_port}"; + }; + + # Admin api endpoint + admin = { + api_bind_addr = "[::]:${builtins.toString admin_api_port}"; + }; + }; + }; + }; + }; haregistry = {...}: { imports = [ ../modules/ha-registry.nix diff --git a/src/api/ha_registry/v1/routes.rs b/src/api/ha_registry/v1/routes.rs index 35e830c..98c4439 100644 --- a/src/api/ha_registry/v1/routes.rs +++ b/src/api/ha_registry/v1/routes.rs @@ -5,7 +5,7 @@ use axum::{routing::get, Router}; -use super::status::{self, handlers::status}; +use super::status::handlers::status; pub fn get_routes() -> Router { Router::new().route("/status", get(status)) diff --git a/src/api/ha_registry/v1/status/handlers.rs b/src/api/ha_registry/v1/status/handlers.rs index f375256..1d9de6d 100644 --- a/src/api/ha_registry/v1/status/handlers.rs +++ b/src/api/ha_registry/v1/status/handlers.rs @@ -5,18 +5,14 @@ use std::sync::Arc; -use crate::data::status::{Status, ServerState}; +use crate::data::status::Status; use axum::{http::StatusCode, Extension, Json}; /// Handler for returning the server status. -pub async fn status( - Extension(status): Extension> -) -> Result, StatusCode> { +pub async fn status(Extension(status): Extension>) -> Result, StatusCode> { match Arc::into_inner(status) { Some(status) => Ok(Json(status)), - None => { - Err(StatusCode::INTERNAL_SERVER_ERROR) - }, + None => Err(StatusCode::INTERNAL_SERVER_ERROR), } } // pub async fn status() -> StatusCode { diff --git a/src/api/ha_registry/v1/status/mod.rs b/src/api/ha_registry/v1/status/mod.rs index c3d4495..33422d2 100644 --- a/src/api/ha_registry/v1/status/mod.rs +++ b/src/api/ha_registry/v1/status/mod.rs @@ -1 +1,5 @@ +// SPDX-FileCopyrightText: 2024 Christina Sørensen +// SPDX-FileContributor: Christina Sørensen +// +// SPDX-License-Identifier: AGPL-3.0-only pub mod handlers; diff --git a/src/api/oci/v2/handlers/mod.rs b/src/api/oci/v2/handlers/mod.rs deleted file mode 100644 index c3d4495..0000000 --- a/src/api/oci/v2/handlers/mod.rs +++ /dev/null @@ -1 +0,0 @@ -pub mod handlers; diff --git a/src/api/oci/v2/mod.rs b/src/api/oci/v2/mod.rs index 86ced7e..58dfc64 100644 --- a/src/api/oci/v2/mod.rs +++ b/src/api/oci/v2/mod.rs @@ -5,4 +5,4 @@ pub mod routes; -mod handlers; +mod oci; diff --git a/src/api/oci/v2/handlers/handlers.rs b/src/api/oci/v2/oci/handlers.rs similarity index 100% rename from src/api/oci/v2/handlers/handlers.rs rename to src/api/oci/v2/oci/handlers.rs diff --git a/src/api/oci/v2/oci/mod.rs b/src/api/oci/v2/oci/mod.rs new file mode 100644 index 0000000..a5942fb --- /dev/null +++ b/src/api/oci/v2/oci/mod.rs @@ -0,0 +1,6 @@ +// SPDX-FileCopyrightText: 2024 Christina Sørensen +// SPDX-FileContributor: Christina Sørensen +// +// SPDX-License-Identifier: AGPL-3.0-only + +pub mod handlers; diff --git a/src/api/oci/v2/routes.rs b/src/api/oci/v2/routes.rs index 222cb30..8cb508c 100644 --- a/src/api/oci/v2/routes.rs +++ b/src/api/oci/v2/routes.rs @@ -8,7 +8,7 @@ use axum::{ Router, }; -use super::handlers::handlers::*; +use super::oci::handlers::*; pub fn get_routes() -> Router { Router::new() diff --git a/src/main.rs b/src/main.rs index abb4076..1092644 100644 --- a/src/main.rs +++ b/src/main.rs @@ -50,7 +50,9 @@ async fn main() { trace!("{config:#?}"); - let status = Arc::new(Status { server_state: ServerState::Healthy }); + let status = Arc::new(Status { + server_state: ServerState::Healthy, + }); let app = Router::new() .route(