Added backend.
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:
@@ -1,7 +1,4 @@
|
||||
use crate::{
|
||||
Field,
|
||||
queue::Message,
|
||||
};
|
||||
use crate::{queue::Message, Field};
|
||||
use std::{
|
||||
sync::mpsc::{channel, Receiver, Sender},
|
||||
thread::spawn,
|
||||
@@ -10,7 +7,7 @@ use uuid::Uuid;
|
||||
|
||||
#[derive(Clone)]
|
||||
pub enum SessionMessage {
|
||||
New(Field),
|
||||
New(Field),
|
||||
Validate(Option<Field>),
|
||||
}
|
||||
|
||||
@@ -21,11 +18,12 @@ impl From<Option<Field>> for SessionMessage {
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
pub mod crete_session_message {
|
||||
pub mod create_session_message {
|
||||
use super::*;
|
||||
|
||||
fn create_session_new() -> SessionMessage {
|
||||
SessionMessage::New(Uuid::new_v4().into())
|
||||
pub fn create_session_new() -> (SessionMessage, Uuid) {
|
||||
let id = Uuid::new_v4();
|
||||
(SessionMessage::New(id.into()), id)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -38,16 +36,12 @@ mod sessionmessages {
|
||||
let text = "afield";
|
||||
let id = Some(text.into());
|
||||
match id.into() {
|
||||
SessionMessage::Validate(result) => {
|
||||
match result {
|
||||
Some(data) => {
|
||||
match data {
|
||||
Field::Static(output) => assert_eq!(output, text),
|
||||
_ => unreachable!("should have returned static text"),
|
||||
}
|
||||
},
|
||||
None => unreachable!("shoulf have returned data"),
|
||||
}
|
||||
SessionMessage::Validate(result) => match result {
|
||||
Some(data) => match data {
|
||||
Field::Static(output) => assert_eq!(output, text),
|
||||
_ => unreachable!("should have returned static text"),
|
||||
},
|
||||
None => unreachable!("shoulf have returned data"),
|
||||
},
|
||||
_ => unreachable!("should have been a vaqlidate"),
|
||||
}
|
||||
@@ -61,10 +55,7 @@ struct Session {
|
||||
|
||||
impl Session {
|
||||
fn new(tx: Sender<Message>, rx: Receiver<Message>) -> Self {
|
||||
Self {
|
||||
tx: tx,
|
||||
rx: rx,
|
||||
}
|
||||
Self { tx: tx, rx: rx }
|
||||
}
|
||||
|
||||
fn start(queue_tx: Sender<Message>) {
|
||||
@@ -87,15 +78,15 @@ impl Session {
|
||||
|
||||
#[cfg(test)]
|
||||
mod sessions {
|
||||
use std::time::Duration;
|
||||
use super::*;
|
||||
use std::time::Duration;
|
||||
|
||||
#[test]
|
||||
fn gets_registered() {
|
||||
let (tx, rx) = channel();
|
||||
Session::start(tx);
|
||||
match rx.recv().unwrap() {
|
||||
Message::Register(_) => {},
|
||||
Message::Register(_) => {}
|
||||
_ => unreachable!("should register the service"),
|
||||
}
|
||||
}
|
||||
@@ -113,11 +104,9 @@ mod sessions {
|
||||
let req: SessionMessage = data.into();
|
||||
sender.send(req.into()).unwrap();
|
||||
match rx.recv_timeout(Duration::from_millis(500)).unwrap() {
|
||||
Message::SessMsg(data) => {
|
||||
match data {
|
||||
SessionMessage::New(_) => {},
|
||||
_ => unreachable!("should have been a new session"),
|
||||
}
|
||||
Message::SessMsg(data) => match data {
|
||||
SessionMessage::New(_) => {}
|
||||
_ => unreachable!("should have been a new session"),
|
||||
},
|
||||
_ => unreachable!("should have been a session message response"),
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user