Skip to content

Commit

Permalink
feat: basic garage testing, formatting
Browse files Browse the repository at this point in the history
Signed-off-by: Christina Sørensen <[email protected]>
  • Loading branch information
cafkafk committed May 14, 2024
1 parent 5c833b9 commit 3c23cf9
Show file tree
Hide file tree
Showing 10 changed files with 68 additions and 12 deletions.
49 changes: 49 additions & 0 deletions nixos/tests/status.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/api/ha_registry/v1/routes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
10 changes: 3 additions & 7 deletions src/api/ha_registry/v1/status/handlers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Arc<Status>>
) -> Result<Json<Status>, StatusCode> {
pub async fn status(Extension(status): Extension<Arc<Status>>) -> Result<Json<Status>, 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 {
Expand Down
4 changes: 4 additions & 0 deletions src/api/ha_registry/v1/status/mod.rs
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
// SPDX-FileCopyrightText: 2024 Christina Sørensen
// SPDX-FileContributor: Christina Sørensen
//
// SPDX-License-Identifier: AGPL-3.0-only
pub mod handlers;
1 change: 0 additions & 1 deletion src/api/oci/v2/handlers/mod.rs

This file was deleted.

2 changes: 1 addition & 1 deletion src/api/oci/v2/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@

pub mod routes;

mod handlers;
mod oci;
File renamed without changes.
6 changes: 6 additions & 0 deletions src/api/oci/v2/oci/mod.rs
Original file line number Diff line number Diff line change
@@ -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;
2 changes: 1 addition & 1 deletion src/api/oci/v2/routes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use axum::{
Router,
};

use super::handlers::handlers::*;
use super::oci::handlers::*;

pub fn get_routes() -> Router {
Router::new()
Expand Down
4 changes: 3 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit 3c23cf9

Please sign in to comment.