implemented notifications and messages
This commit is contained in:
parent
28a3812812
commit
695ac6daa2
12 changed files with 1023 additions and 315 deletions
|
@ -22,6 +22,10 @@ impl Channel {
|
|||
pub fn get_name(&self) -> &str {
|
||||
&self.name
|
||||
}
|
||||
|
||||
pub fn set_name(&mut self, name: String) {
|
||||
self.name = name;
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
|
@ -31,11 +35,28 @@ pub struct User {
|
|||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
pub struct Msg {
|
||||
pub struct Message {
|
||||
id: Id,
|
||||
content: String,
|
||||
}
|
||||
|
||||
impl Message {
|
||||
pub fn new(content: String) -> Self {
|
||||
let id = Id::from_now();
|
||||
Self { id, content }
|
||||
}
|
||||
|
||||
pub fn get_id(&self) -> Id {
|
||||
self.id
|
||||
}
|
||||
pub fn get_content(&self) -> &str {
|
||||
&self.content
|
||||
}
|
||||
pub fn set_content(&mut self, content: String) {
|
||||
self.content = content;
|
||||
}
|
||||
}
|
||||
|
||||
pub trait SerDeser: Serialize + DeserializeOwned {
|
||||
fn ser(&self) -> Vec<u8>;
|
||||
fn deser(input: &[u8]) -> Option<Self>;
|
||||
|
|
64
harsh-server/src/storage/tests.rs
Normal file
64
harsh-server/src/storage/tests.rs
Normal file
|
@ -0,0 +1,64 @@
|
|||
use super::*;
|
||||
#[test]
|
||||
fn test_list() {
|
||||
let db = sled::open("/tmp/test-db").unwrap();
|
||||
db.insert("/some/path/123", b"hello1").unwrap();
|
||||
db.insert("/some/path/1234", b"hello2").unwrap();
|
||||
db.insert("/some/path/12345", b"hello3").unwrap();
|
||||
let results = list(&db, "/some/path/".to_string());
|
||||
assert_eq!(
|
||||
results,
|
||||
vec![
|
||||
Id::from_string("123").unwrap(),
|
||||
Id::from_string("1234").unwrap(),
|
||||
Id::from_string("12345").unwrap()
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn test_channels() {
|
||||
use telecomande::{Executor, SimpleExecutor};
|
||||
// cleaning;
|
||||
std::fs::remove_dir_all("/tmp/db-test").ok();
|
||||
|
||||
// instantiation
|
||||
let store = SimpleExecutor::new(StorageProc::new("/tmp/db-test")).spawn();
|
||||
let remote = store.remote();
|
||||
|
||||
// insertion
|
||||
let (cmd, rec) = StorageCmd::new_channel_create("a-channel");
|
||||
remote.send(cmd).unwrap();
|
||||
let id = rec.await.unwrap();
|
||||
|
||||
// query all
|
||||
let (cmd, rec) = StorageCmd::new_channel_list();
|
||||
remote.send(cmd).unwrap();
|
||||
let result = rec.await.unwrap();
|
||||
assert_eq!(result.len(), 1);
|
||||
let first = result[0];
|
||||
assert_eq!(first, id);
|
||||
|
||||
// query property
|
||||
let (cmd, rec) = StorageCmd::new_channel_get_name(id);
|
||||
remote.send(cmd).unwrap();
|
||||
let result = rec.await.unwrap();
|
||||
assert_eq!(result.unwrap(), "a-channel".to_string());
|
||||
|
||||
// insertion
|
||||
let (cmd, rec) = StorageCmd::new_channel_create("b-channel");
|
||||
remote.send(cmd).unwrap();
|
||||
let id2 = rec.await.unwrap();
|
||||
|
||||
// query all
|
||||
let (cmd, rec) = StorageCmd::new_channel_list();
|
||||
remote.send(cmd).unwrap();
|
||||
let result = rec.await.unwrap();
|
||||
assert_eq!(result.len(), 2);
|
||||
|
||||
// query property
|
||||
let (cmd, rec) = StorageCmd::new_channel_get_name(id2);
|
||||
remote.send(cmd).unwrap();
|
||||
let result = rec.await.unwrap();
|
||||
assert_eq!(result.unwrap(), "b-channel".to_string());
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue