httpd: Move `test` utility mod from inside `api` to root

Signed-off-by: xphoniex <dj.2dixx@gmail.com>
This commit is contained in:
xphoniex 2023-02-17 12:41:33 +00:00 committed by Alexis Sellier
parent c1b6ceb141
commit f290f6b4a5
8 changed files with 19 additions and 17 deletions

View File

@ -1,5 +1,4 @@
#[cfg(test)]
pub mod test;
pub mod auth;
use std::collections::HashMap;
use std::sync::Arc;
@ -21,7 +20,6 @@ use radicle::identity::Id;
use radicle::storage::{ReadRepository, ReadStorage};
use radicle::Profile;
mod auth;
mod axum_extra;
mod error;
mod json;
@ -70,6 +68,11 @@ impl Context {
pub fn profile(&self) -> &Arc<Profile> {
&self.profile
}
#[cfg(test)]
pub fn sessions(&self) -> &Arc<RwLock<HashMap<SessionId, auth::Session>>> {
&self.sessions
}
}
pub fn router(ctx: Context) -> Router {

View File

@ -74,7 +74,7 @@ mod routes {
use axum::http::StatusCode;
use serde_json::json;
use crate::api::test::{self, get, HEAD};
use crate::test::{self, get, HEAD};
#[tokio::test]
async fn test_delegates_projects() {

View File

@ -562,7 +562,7 @@ mod routes {
use pretty_assertions::assert_eq;
use serde_json::json;
use crate::api::test::{self, get, patch, post, HEAD, HEAD_1, ISSUE_ID, PATCH_ID};
use crate::test::{self, get, patch, post, HEAD, HEAD_1, ISSUE_ID, PATCH_ID};
const CREATED_ISSUE_ID: &str = "b56febfba1e7dd20f4aea43ca2fe9dcf1fd448ba";

View File

@ -125,10 +125,8 @@ mod routes {
use axum::http::StatusCode;
use radicle_cli::commands::rad_web::{self, SessionInfo};
use crate::api::{
auth::{AuthState, Session},
test::{self, get, post, put},
};
use crate::api::auth::{AuthState, Session};
use crate::test::{self, get, post, put};
#[tokio::test]
async fn test_session() {

View File

@ -29,7 +29,7 @@ mod routes {
use axum::http::StatusCode;
use serde_json::json;
use crate::api::test::{self, get};
use crate::test::{self, get};
#[tokio::test]
async fn test_stats() {

View File

@ -203,7 +203,7 @@ mod routes {
use axum::http::{Method, StatusCode};
use tower::ServiceExt;
use crate::api::test;
use crate::test;
#[tokio::test]
async fn test_invalid_route_returns_404() {

View File

@ -17,6 +17,8 @@ use tracing::Span;
mod api;
mod git;
#[cfg(test)]
mod test;
#[derive(Debug, Clone)]
pub struct Options {
@ -30,9 +32,11 @@ pub async fn run(options: Options) -> anyhow::Result<()> {
.output()
.context("'git' command must be available")?
.stdout;
tracing::info!("{}", str::from_utf8(&git_version)?.trim());
let profile = Arc::new(radicle::Profile::load()?);
tracing::info!("using radicle home at {}", profile.home().display());
let ctx = api::Context::new(profile.clone());

View File

@ -136,21 +136,18 @@ pub fn seed(dir: &Path) -> Context {
)
.unwrap();
Context {
profile: Arc::new(profile),
sessions: Default::default(),
}
Context::new(Arc::new(profile))
}
/// Adds an authorized session to the Context::sessions HashMap.
pub async fn create_session(ctx: Context) {
let issued_at = OffsetDateTime::now_utc();
let mut sessions = ctx.sessions.write().await;
let mut sessions = ctx.sessions().write().await;
sessions.insert(
String::from("u9MGAkkfkMOv0uDDB2WeUHBT7HbsO2Dy"),
auth::Session {
status: auth::AuthState::Authorized,
public_key: ctx.profile.public_key,
public_key: ctx.profile().public_key,
issued_at,
expires_at: issued_at
.checked_add(auth::AUTHORIZED_SESSIONS_EXPIRATION)