Added request.
All checks were successful
MoreThanText/morethantext/pipeline/head This commit looks good

This commit is contained in:
Jeff Baskin 2025-02-18 09:54:05 -05:00
parent 6bb7add4b0
commit 4bca78a2f8

View File

@ -16,8 +16,6 @@ use std::{
};
use uuid::Uuid;
struct Request;
#[derive(Clone)]
enum Field {
Static(String),
@ -28,7 +26,7 @@ impl From<String> for Field {
fn from(value: String) -> Self {
match Uuid::try_from(value.as_str()) {
Ok(data) => return Field::Uuid(data),
Err(_) => {},
Err(_) => {}
}
Field::Static(value)
}
@ -38,7 +36,7 @@ impl From<&str> for Field {
fn from(value: &str) -> Self {
match Uuid::try_from(value) {
Ok(data) => return Field::Uuid(data),
Err(_) => {},
Err(_) => {}
}
Field::Static(value.into())
}
@ -107,6 +105,51 @@ mod fields {
}
}
struct Request {
id: Option<Field>,
}
impl Request {
fn new<F>(mut id: Option<F>) -> Self
where
F: Into<Field>,
{
let result: Option<Field>;
match id {
Some(data) => {
result = Some(data.into());
}
None => result = None,
}
Self { id: result }
}
}
#[cfg(test)]
mod requests {
use super::*;
#[test]
fn create_request_no_id() {
let input: Option<String> = None;
let req = Request::new(input);
assert!(req.id.is_none());
}
#[test]
fn create_request_with_uuid() {
let id = Uuid::new_v4();
let req = Request::new(Some(id));
match req.id {
Some(field) => match (field) {
Field::Uuid(data) => assert_eq!(data, id),
_ => unreachable!("Should have been a uuid"),
},
None => unreachable!("Should producer data"),
}
}
}
struct Record {
data: HashMap<String, Field>,
}
@ -279,7 +322,7 @@ mod responses {
match rec.get(col).unwrap() {
Field::Static(txt) => {
assert_eq!(txt.clone(), fields.next().unwrap().to_string())
},
}
_ => unreachable!("should have been static"),
}
}