-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #31 from tinythings/isbm-init-tests
Add unit tests
- Loading branch information
Showing
4 changed files
with
125 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
name: Unit/Integration Testing | ||
|
||
on: | ||
push: | ||
branches: | ||
- "master" | ||
pull_request: | ||
|
||
env: | ||
CARGO_TERM_COLOR: always | ||
# RUSTFLAGS: -D warnings | ||
|
||
jobs: | ||
unit_tests: | ||
name: Unit and Static Type tests | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Install latest nextest release | ||
uses: taiki-e/install-action@nextest | ||
|
||
- uses: actions/checkout@v2 | ||
- name: Run test target | ||
run: | | ||
make test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
#[cfg(test)] | ||
mod dataconv_test { | ||
use libsysinspect::util::dataconv; | ||
use serde_yaml::{self, Value}; | ||
use std::collections::HashMap; | ||
|
||
#[test] | ||
fn test_dataconv_int() { | ||
let m = serde_yaml::from_str::<HashMap<String, Value>>("foo: 1").unwrap(); | ||
let v = m.get("foo").unwrap(); | ||
let i = dataconv::as_int(Some(v).cloned()); | ||
assert!(i == 1); | ||
} | ||
|
||
#[test] | ||
fn test_dataconv_bool() { | ||
let m = serde_yaml::from_str::<HashMap<String, Value>>("foo: true").unwrap(); | ||
let v = m.get("foo").unwrap(); | ||
let i = dataconv::as_bool(Some(v).cloned()); | ||
assert!(i); | ||
} | ||
|
||
#[test] | ||
fn test_dataconv_str() { | ||
let m = serde_yaml::from_str::<HashMap<String, Value>>("foo: \"Darth Vader\"").unwrap(); | ||
let v = m.get("foo").unwrap(); | ||
let i = dataconv::as_str(Some(v).cloned()); | ||
assert!(i.eq("Darth Vader")); | ||
} | ||
|
||
#[test] | ||
fn test_dataconv_str_opt() { | ||
let m = serde_yaml::from_str::<HashMap<String, Value>>("foo: \"Darth Vader\"").unwrap(); | ||
let v = m.get("foo").unwrap(); | ||
let i = dataconv::as_str_opt(Some(v).cloned()); | ||
assert!(i.is_some(), "Data must contain something"); | ||
assert!(i.unwrap_or_default().eq("Darth Vader"), "Data must be a Luke's father"); | ||
} | ||
|
||
#[test] | ||
fn test_dataconv_bool_opt() { | ||
let m = serde_yaml::from_str::<HashMap<String, Value>>("foo: true").unwrap(); | ||
let v = m.get("foo").unwrap(); | ||
let i = dataconv::as_bool_opt(Some(v).cloned()); | ||
assert!(i.is_some(), "Data must contain something"); | ||
assert!(i.unwrap_or(false), "Data must be true"); | ||
} | ||
|
||
#[test] | ||
fn test_dataconv_int_opt() { | ||
let m = serde_yaml::from_str::<HashMap<String, Value>>("foo: 1").unwrap(); | ||
let v = m.get("foo").unwrap(); | ||
let i = dataconv::as_int_opt(Some(v).cloned()); | ||
assert!(i.is_some(), "Data must contain something"); | ||
assert!(i.unwrap_or(0) == 1, "Data must be 1"); | ||
} | ||
|
||
#[test] | ||
fn test_dataconv_str_list() { | ||
let m = serde_yaml::from_str::<HashMap<String, Value>>("foo: \"bar,spam,baz,toto\"").unwrap(); | ||
let v = m.get("foo").unwrap(); | ||
let l = dataconv::as_str_list(Some(v).cloned()); | ||
assert!(l.len() == 4, "Data length must be 4"); | ||
assert!( | ||
l == vec!["bar".to_string(), "spam".to_string(), "baz".to_string(), "toto".to_string()], | ||
"Vector must be the same" | ||
); | ||
} | ||
|
||
#[test] | ||
fn test_dataconv_str_list_opt() { | ||
let m = serde_yaml::from_str::<HashMap<String, Value>>("foo: \"bar,spam,baz,toto\"").unwrap(); | ||
let v = m.get("foo").unwrap(); | ||
let l = dataconv::as_str_list_opt(Some(v).cloned()); | ||
assert!(l.is_some(), "Data must contain something"); | ||
assert!(l.clone().unwrap().len() == 4, "Data length must be 4"); | ||
assert!( | ||
l.unwrap() == vec!["bar".to_string(), "spam".to_string(), "baz".to_string(), "toto".to_string()], | ||
"Vector must be the same" | ||
); | ||
} | ||
|
||
#[test] | ||
fn test_dataconv_to_str() { | ||
let m = serde_yaml::from_str::<HashMap<String, Value>>("foo: \"bar,spam,baz,toto\"").unwrap(); | ||
let v = m.get("foo").unwrap(); | ||
let s = dataconv::to_string(Some(v).cloned()); | ||
assert!(s.is_some(), "Data must contain something"); | ||
let s = s.unwrap(); | ||
assert!(s.eq("bar,spam,baz,toto")); | ||
} | ||
} |