Skip to content

Commit

Permalink
fix: few fixes from review
Browse files Browse the repository at this point in the history
Signed-off-by: simonsan <14062932+simonsan@users.noreply.github.com>
  • Loading branch information
simonsan committed Jan 26, 2024
1 parent 9e7c2c4 commit 78ab5a7
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 16 deletions.
10 changes: 6 additions & 4 deletions src/test_helpers.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use std::str::FromStr;
use std::{env, path::PathBuf, sync::Mutex, sync::OnceLock};

use axum::{
Expand Down Expand Up @@ -40,15 +39,18 @@ pub(crate) fn init_tracing() {
init_mutex();
}

/// When we initialise the global tracing subscriber, this must only happen once.
/// During tests, each test will initialise, to make sure we have at least tracing once.
/// When we initialize the global tracing subscriber, this must only happen once.
/// During tests, each test will initialize, to make sure we have at least tracing once.
/// This means that the init() call must be robust for this.
/// Since we do not need this in production code, it is located in the test code.
static TRACER: OnceLock<Mutex<usize>> = OnceLock::new();
fn init_mutex() {
TRACER.get_or_init(|| {
tracing_subscriber::registry()
.with(tracing_subscriber::EnvFilter::from_str("debug").unwrap())
.with(
tracing_subscriber::EnvFilter::try_from_default_env()
.unwrap_or_else(|_| "RUSTIC_SERVER_LOG_LEVEL=debug".into()),
)
.with(tracing_subscriber::fmt::layer())
.init();
Mutex::new(0)
Expand Down
20 changes: 8 additions & 12 deletions src/typed_path.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use axum_extra::routing::TypedPath;
use serde::Deserialize;
use serde_derive::Serialize;
use strum::{AsRefStr, Display, EnumVariantNames, IntoStaticStr};
use serde_derive::{Deserialize, Serialize};
use strum::{AsRefStr, Display, EnumString, EnumVariantNames, IntoStaticStr};

pub trait PathParts {
fn parts(&self) -> (Option<String>, Option<TpeKind>, Option<String>) {
Expand All @@ -26,28 +25,26 @@ pub trait PathParts {
Clone,
Copy,
PartialEq,
Eq,
Default,
Display,
Deserialize,
Serialize,
Deserialize,
IntoStaticStr,
AsRefStr,
EnumVariantNames,
EnumString,
)]
#[serde(rename_all = "lowercase")]
#[strum(serialize_all = "lowercase")]
#[strum(ascii_case_insensitive)]
pub enum TpeKind {
#[strum(serialize = "config")]
Config,
#[default]
#[strum(serialize = "data")]
Data,
#[strum(serialize = "index")]
Index,
#[strum(serialize = "keys")]
Keys,
#[strum(serialize = "locks")]
Locks,
#[strum(serialize = "snapshots")]
Snapshots,
}

Expand All @@ -70,8 +67,7 @@ impl PathParts for RepositoryConfigPath {
}
}

// A type safe route with `"/:repo/"` as its associated path.
// FIXED: removed trailing slash
// A type safe route with `"/:repo"` as its associated path.
#[derive(TypedPath, Deserialize)]
#[typed_path("/:repo")]
pub struct RepositoryPath {
Expand Down

0 comments on commit 78ab5a7

Please sign in to comment.