Add automated tests

Signed-off-by: trivernis <trivernis@protonmail.com>
pull/4/head
trivernis 3 years ago
parent 7c3b2a5051
commit faa7b4e17c

@ -44,4 +44,7 @@ jobs:
run: cargo build --features=client-api run: cargo build --features=client-api
- name: Build Plugin - name: Build Plugin
run: cargo build --features=tauri-plugin run: cargo build --features=tauri-plugin
- name: Test
run: cargo test --all-features

@ -11,3 +11,6 @@ pub mod tauri_plugin;
#[cfg(feature = "bromine")] #[cfg(feature = "bromine")]
pub use bromine; pub use bromine;
#[cfg(test)]
mod test;

@ -0,0 +1,2 @@
#[cfg(feature = "bromine")]
mod test_type_serialization;

@ -0,0 +1,54 @@
use crate::types::files::{
FilterExpression, GetFileThumbnailOfSizeRequest, SortDirection, SortKey, TagQuery,
};
use crate::types::identifier::FileIdentifier;
use bromine::payload::DynamicSerializer;
use bromine::prelude::IPCResult;
use serde::de::DeserializeOwned;
use serde::Serialize;
#[test]
fn it_serializes_file_identifier() {
test_serialization(FileIdentifier::ID(0)).unwrap();
}
#[test]
fn it_serializes_get_file_thumbnail_of_size_requests() {
test_serialization(GetFileThumbnailOfSizeRequest {
id: FileIdentifier::ID(0),
max_size: (u32::MAX, u32::MAX),
min_size: (0, 0),
})
.unwrap();
}
#[test]
fn it_serializes_tag_queries() {
test_serialization(TagQuery {
tag: String::from("Hello"),
negate: true,
})
.unwrap();
}
#[test]
fn it_serializes_filter_expressions() {
test_serialization(FilterExpression::Query(TagQuery {
tag: String::from("World"),
negate: false,
}))
.unwrap();
}
#[test]
fn it_serializes_sort_keys() {
test_serialization(SortKey::FileName(SortDirection::Descending)).unwrap();
}
fn test_serialization<T: Serialize + DeserializeOwned>(data: T) -> IPCResult<()> {
let serializer = DynamicSerializer::first_available();
let bytes = serializer.serialize(data)?;
let _: T = serializer.deserialize(&bytes[..])?;
Ok(())
}
Loading…
Cancel
Save