Got 404 working again.
Some checks failed
Gitea Actions Demo / Explore-Gitea-Actions (push) Failing after 1s
Some checks failed
Gitea Actions Demo / Explore-Gitea-Actions (push) Failing after 1s
This commit is contained in:
parent
aa4a5b9b7c
commit
0dbf75d0c6
48
src/lib.rs
48
src/lib.rs
@ -14,6 +14,7 @@ use message::{
|
|||||||
action::{Action, MsgAction},
|
action::{Action, MsgAction},
|
||||||
wrapper::{Addition, CalcValue, Calculation, Message, Operand, Query},
|
wrapper::{Addition, CalcValue, Calculation, Message, Operand, Query},
|
||||||
};
|
};
|
||||||
|
pub use mtterror::MTTError;
|
||||||
use name::{Name, NameType};
|
use name::{Name, NameType};
|
||||||
use queue::{
|
use queue::{
|
||||||
data_director::{Include, Path, RegMsg, Register},
|
data_director::{Include, Path, RegMsg, Register},
|
||||||
@ -104,48 +105,11 @@ impl MoreThanText {
|
|||||||
output
|
output
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_document(&self) -> String {
|
pub fn get_document(&self, name: &str, id: &str) -> Result<String, MTTError> {
|
||||||
"something".to_string()
|
if name == "page" {
|
||||||
}
|
Ok("something".to_string())
|
||||||
}
|
} else {
|
||||||
|
Err(MTTError::DocumentNotFound(name.to_string()))
|
||||||
#[cfg(test)]
|
|
||||||
mod mtts {
|
|
||||||
use super::*;
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn are_session_ids_unique() {
|
|
||||||
let mut mtt = MoreThanText::new();
|
|
||||||
let count = 10;
|
|
||||||
let mut result: Vec<Uuid> = Vec::new();
|
|
||||||
for _ in 0..count {
|
|
||||||
let id = mtt.validate_session(None);
|
|
||||||
assert!(!result.contains(&id), "found {} in {:?}", id, result);
|
|
||||||
result.push(id);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn bad_session_id_returns_new_id() {
|
|
||||||
let mut mtt = MoreThanText::new();
|
|
||||||
let id1 = mtt.validate_session(Some("stuff".to_string()));
|
|
||||||
let id2 = mtt.validate_session(Some("stuff".to_string()));
|
|
||||||
assert_ne!(id1, id2);
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn creates_new_session_if_bad_or_expired() {
|
|
||||||
let mut mtt = MoreThanText::new();
|
|
||||||
let id1 = mtt.validate_session(Some(Uuid::nil().to_string()));
|
|
||||||
let id2 = mtt.validate_session(Some(Uuid::nil().to_string()));
|
|
||||||
assert_ne!(id1, id2);
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn returns_same_session_id_when_valid() {
|
|
||||||
let mut mtt = MoreThanText::new();
|
|
||||||
let id = mtt.validate_session(None);
|
|
||||||
let result = mtt.validate_session(Some(id.to_string()));
|
|
||||||
assert_eq!(result, id);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
53
src/main.rs
53
src/main.rs
@ -8,7 +8,7 @@ use axum::{
|
|||||||
use clap::Parser;
|
use clap::Parser;
|
||||||
//use morethantext::{ActionType, ErrorType, MoreThanText};
|
//use morethantext::{ActionType, ErrorType, MoreThanText};
|
||||||
//use morethantext::{MoreThanText, MsgAction, Query};
|
//use morethantext::{MoreThanText, MsgAction, Query};
|
||||||
use morethantext::MoreThanText;
|
use morethantext::{MTTError, MoreThanText};
|
||||||
use std::{collections::HashMap, convert::Infallible};
|
use std::{collections::HashMap, convert::Infallible};
|
||||||
use tokio::{spawn, sync::mpsc::channel};
|
use tokio::{spawn, sync::mpsc::channel};
|
||||||
use tower_cookies::{Cookie, CookieManagerLayer, Cookies};
|
use tower_cookies::{Cookie, CookieManagerLayer, Cookies};
|
||||||
@ -91,38 +91,30 @@ async fn mtt_conn(
|
|||||||
_body: String,
|
_body: String,
|
||||||
) -> impl IntoResponse {
|
) -> impl IntoResponse {
|
||||||
let (tx, mut rx) = channel(1);
|
let (tx, mut rx) = channel(1);
|
||||||
/*
|
|
||||||
let _action = match method {
|
|
||||||
//Method::GET => MsgAction::Query(Query::new()),
|
|
||||||
//Method::GET => ActionType::Get,
|
|
||||||
//Method::POST => ActionType::Add,
|
|
||||||
//Method::PATCH => ActionType::Update,
|
|
||||||
_ => unreachable!("reouter should prevent this"),
|
|
||||||
};
|
|
||||||
*/
|
|
||||||
let _doc = match path.get("document") {
|
|
||||||
Some(result) => result.clone(),
|
|
||||||
None => "root".to_string(),
|
|
||||||
};
|
|
||||||
spawn(async move {
|
spawn(async move {
|
||||||
//tx.send(state.get_document(sess_id.0, action, doc, body))
|
match method {
|
||||||
tx.send(state.get_document()).await.unwrap();
|
Method::GET => match path.get("document") {
|
||||||
|
Some(doc) => tx.send(state.get_document(doc, "home")).await.unwrap(),
|
||||||
|
None => tx.send(state.get_document("page", "home")).await.unwrap(),
|
||||||
|
},
|
||||||
|
_ => unreachable!("reouter should prevent this"),
|
||||||
|
}
|
||||||
});
|
});
|
||||||
let reply = rx.recv().await.unwrap();
|
let reply = rx.recv().await.unwrap();
|
||||||
/*
|
let mut result = "".to_string();
|
||||||
let status = match reply.get_error() {
|
let mut status = StatusCode::OK;
|
||||||
Some(err) => match err {
|
match reply {
|
||||||
ErrorType::DocumentAlreadyExists => StatusCode::CONFLICT,
|
Ok(data) => {
|
||||||
ErrorType::DocumentInvalidRequest => StatusCode::BAD_REQUEST,
|
result = data.clone();
|
||||||
ErrorType::DocumentNotFound => StatusCode::NOT_FOUND,
|
}
|
||||||
// _ => StatusCode::INTERNAL_SERVER_ERROR,
|
Err(err) => {
|
||||||
},
|
status = match err {
|
||||||
None => StatusCode::OK,
|
MTTError::DocumentNotFound(_) => StatusCode::NOT_FOUND,
|
||||||
};
|
_ => StatusCode::INTERNAL_SERVER_ERROR,
|
||||||
(status, reply.get_document())
|
};
|
||||||
*/
|
}
|
||||||
let status = StatusCode::OK;
|
}
|
||||||
(status, reply)
|
(status, result)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
@ -195,7 +187,6 @@ mod servers {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
#[ignore]
|
|
||||||
async fn receive_file_not_found() {
|
async fn receive_file_not_found() {
|
||||||
let uri = "/something";
|
let uri = "/something";
|
||||||
let app = create_app(MoreThanText::new()).await;
|
let app = create_app(MoreThanText::new()).await;
|
||||||
|
|||||||
23
tests/lib_document_test.rs
Normal file
23
tests/lib_document_test.rs
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
use morethantext::{MTTError, MoreThanText};
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn get_home_page() {
|
||||||
|
let mtt = MoreThanText::new();
|
||||||
|
match mtt.get_document("page", "home") {
|
||||||
|
Ok(_) => {}
|
||||||
|
Err(err) => assert!(false, "got error {:?}", err),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn errors_on_missing_page() {
|
||||||
|
let mtt = MoreThanText::new();
|
||||||
|
let doc_name = "missing";
|
||||||
|
match mtt.get_document(doc_name, "home") {
|
||||||
|
Ok(data) => assert!(false, "got '{}', should have been not found error", data),
|
||||||
|
Err(err) => match err {
|
||||||
|
MTTError::DocumentNotFound(result) => assert_eq!(result, doc_name),
|
||||||
|
_ => unreachable!("got {:?}, should have been not found", err),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
38
tests/lib_session_test.rs
Normal file
38
tests/lib_session_test.rs
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
use morethantext::MoreThanText;
|
||||||
|
use uuid::Uuid;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn are_session_ids_unique() {
|
||||||
|
let mut mtt = MoreThanText::new();
|
||||||
|
let count = 10;
|
||||||
|
let mut result: Vec<Uuid> = Vec::new();
|
||||||
|
for _ in 0..count {
|
||||||
|
let id = mtt.validate_session(None);
|
||||||
|
assert!(!result.contains(&id), "found {} in {:?}", id, result);
|
||||||
|
result.push(id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn bad_session_id_returns_new_id() {
|
||||||
|
let mut mtt = MoreThanText::new();
|
||||||
|
let id1 = mtt.validate_session(Some("stuff".to_string()));
|
||||||
|
let id2 = mtt.validate_session(Some("stuff".to_string()));
|
||||||
|
assert_ne!(id1, id2);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn creates_new_session_if_bad_or_expired() {
|
||||||
|
let mut mtt = MoreThanText::new();
|
||||||
|
let id1 = mtt.validate_session(Some(Uuid::nil().to_string()));
|
||||||
|
let id2 = mtt.validate_session(Some(Uuid::nil().to_string()));
|
||||||
|
assert_ne!(id1, id2);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn returns_same_session_id_when_valid() {
|
||||||
|
let mut mtt = MoreThanText::new();
|
||||||
|
let id = mtt.validate_session(None);
|
||||||
|
let result = mtt.validate_session(Some(id.to_string()));
|
||||||
|
assert_eq!(result, id);
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user