Skip to content

Commit

Permalink
feat(oca-rs): add tests for building oca from base, building from oth…
Browse files Browse the repository at this point in the history
…er bundle, and building with references
  • Loading branch information
olichwiruk committed Nov 14, 2023
1 parent f66e77c commit 2711d87
Show file tree
Hide file tree
Showing 2 changed files with 96 additions and 31 deletions.
31 changes: 0 additions & 31 deletions oca/src/facade/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,34 +40,3 @@ impl Facade {
}
}
}

#[cfg(test)]
mod test {
use super::*;
use crate::{data_storage::InMemoryDataStorage, facade::build::Error};

#[test]
fn facade_build_from_ocafile_from_base() -> Result<(), Vec<Error>> {
let db = InMemoryDataStorage::new();
let db_cache = InMemoryDataStorage::new();
let cache_storage_config = SQLiteConfig::build().unwrap();
let ocafile = r#"
ADD ATTRIBUTE d=Text i=Text passed=Boolean
ADD META en PROPS name="Entrance credential" description="Entrance credential"
ADD CHARACTER_ENCODING ATTRS d=utf-8 i=utf-8 passed=utf-8
ADD CONFORMANCE ATTRS d=M i=M passed=M
ADD LABEL en ATTRS d="Schema digest" i="Credential Issuee" passed="Passed"
ADD INFORMATION en ATTRS d="Schema digest" i="Credential Issuee" passed="Enables or disables passing"
"#.to_string();
let mut facade =
Facade::new(Box::new(db), Box::new(db_cache), cache_storage_config);

let result = facade.build_from_ocafile(ocafile)?;

assert_eq!(
result.said.unwrap().to_string(),
"EF5ERATRBBN_ewEo9buQbznirhBmvrSSC0O2GIR4Gbfs"
);
Ok(())
}
}
96 changes: 96 additions & 0 deletions oca/tests/build_from_ocafile.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
use oca_rs::{
data_storage::{DataStorage, InMemoryDataStorage},
facade::build::Error,
repositories::SQLiteConfig,
Facade,
};

#[cfg(test)]
mod test {
use super::*;

#[test]
fn build_from_base() -> Result<(), Vec<Error>> {
let db = InMemoryDataStorage::new();
let db_cache = InMemoryDataStorage::new();
let cache_storage_config = SQLiteConfig::build().unwrap();
let ocafile = r#"
ADD ATTRIBUTE d=Text i=Text passed=Boolean
ADD META en PROPS name="Entrance credential" description="Entrance credential"
ADD CHARACTER_ENCODING ATTRS d=utf-8 i=utf-8 passed=utf-8
ADD CONFORMANCE ATTRS d=M i=M passed=M
ADD LABEL en ATTRS d="Schema digest" i="Credential Issuee" passed="Passed"
ADD INFORMATION en ATTRS d="Schema digest" i="Credential Issuee" passed="Enables or disables passing"
"#.to_string();
let mut facade =
Facade::new(Box::new(db), Box::new(db_cache), cache_storage_config);

let result = facade.build_from_ocafile(ocafile)?;

assert_eq!(
result.said.unwrap().to_string(),
"EF5ERATRBBN_ewEo9buQbznirhBmvrSSC0O2GIR4Gbfs"
);
Ok(())
}

#[test]
fn build_from_other_bundle() -> Result<(), Vec<Error>> {
let db = InMemoryDataStorage::new();
let db_cache = InMemoryDataStorage::new();
let cache_storage_config = SQLiteConfig::build().unwrap();
let mut facade =
Facade::new(Box::new(db), Box::new(db_cache), cache_storage_config);
let other_ocafile = r#"
ADD ATTRIBUTE d=Text i=Text passed=Boolean
ADD META en PROPS name="Entrance credential" description="Entrance credential"
ADD CHARACTER_ENCODING ATTRS d=utf-8 i=utf-8 passed=utf-8
ADD CONFORMANCE ATTRS d=M i=M passed=M
ADD LABEL en ATTRS d="Schema digest" i="Credential Issuee" passed="Passed"
ADD INFORMATION en ATTRS d="Schema digest" i="Credential Issuee" passed="Enables or disables passing"
"#.to_string();
facade.build_from_ocafile(other_ocafile)?;

let ocafile = r#"
FROM EF5ERATRBBN_ewEo9buQbznirhBmvrSSC0O2GIR4Gbfs
ADD ATTRIBUTE x=Text
"#.to_string();
let result = facade.build_from_ocafile(ocafile)?;

assert_eq!(
result.said.unwrap().to_string(),
"EBBLFLhdLLgmVOLJO0G6Bqa4-JhFyP8-E0HikwjuRB6w"
);
Ok(())
}

#[test]
fn build_with_references() -> Result<(), Vec<Error>> {
let db = InMemoryDataStorage::new();
let db_cache = InMemoryDataStorage::new();
let cache_storage_config = SQLiteConfig::build().unwrap();
let mut facade =
Facade::new(Box::new(db), Box::new(db_cache), cache_storage_config);
let first_ocafile = r#"
ADD ATTRIBUTE a=Text
"#.to_string();
facade.build_from_ocafile(first_ocafile)?;
let second_ocafile = r#"
-- name=other
ADD ATTRIBUTE b=Text
"#.to_string();
facade.build_from_ocafile(second_ocafile)?;

let ocafile = r#"
ADD ATTRIBUTE A=refs:EI_5ohTYptgOrXldUfZujgd7vcXK9zwa6aNqk4-UDWzq
ADD ATTRIBUTE B=refn:other
"#.to_string();
let result = facade.build_from_ocafile(ocafile)?;

assert_eq!(
result.said.unwrap().to_string(),
"EPZNx7Vbl06cYdsAKbRVtgxUOoLcap61Go7ueau1RjEN"
);
Ok(())
}
}

0 comments on commit 2711d87

Please sign in to comment.