Added request.
All checks were successful
MoreThanText/morethantext/pipeline/head This commit looks good
All checks were successful
MoreThanText/morethantext/pipeline/head This commit looks good
This commit is contained in:
parent
6bb7add4b0
commit
4bca78a2f8
53
src/lib.rs
53
src/lib.rs
@ -16,8 +16,6 @@ use std::{
|
|||||||
};
|
};
|
||||||
use uuid::Uuid;
|
use uuid::Uuid;
|
||||||
|
|
||||||
struct Request;
|
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
enum Field {
|
enum Field {
|
||||||
Static(String),
|
Static(String),
|
||||||
@ -28,7 +26,7 @@ impl From<String> for Field {
|
|||||||
fn from(value: String) -> Self {
|
fn from(value: String) -> Self {
|
||||||
match Uuid::try_from(value.as_str()) {
|
match Uuid::try_from(value.as_str()) {
|
||||||
Ok(data) => return Field::Uuid(data),
|
Ok(data) => return Field::Uuid(data),
|
||||||
Err(_) => {},
|
Err(_) => {}
|
||||||
}
|
}
|
||||||
Field::Static(value)
|
Field::Static(value)
|
||||||
}
|
}
|
||||||
@ -38,7 +36,7 @@ impl From<&str> for Field {
|
|||||||
fn from(value: &str) -> Self {
|
fn from(value: &str) -> Self {
|
||||||
match Uuid::try_from(value) {
|
match Uuid::try_from(value) {
|
||||||
Ok(data) => return Field::Uuid(data),
|
Ok(data) => return Field::Uuid(data),
|
||||||
Err(_) => {},
|
Err(_) => {}
|
||||||
}
|
}
|
||||||
Field::Static(value.into())
|
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 {
|
struct Record {
|
||||||
data: HashMap<String, Field>,
|
data: HashMap<String, Field>,
|
||||||
}
|
}
|
||||||
@ -279,7 +322,7 @@ mod responses {
|
|||||||
match rec.get(col).unwrap() {
|
match rec.get(col).unwrap() {
|
||||||
Field::Static(txt) => {
|
Field::Static(txt) => {
|
||||||
assert_eq!(txt.clone(), fields.next().unwrap().to_string())
|
assert_eq!(txt.clone(), fields.next().unwrap().to_string())
|
||||||
},
|
}
|
||||||
_ => unreachable!("should have been static"),
|
_ => unreachable!("should have been static"),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user