Skip to content

Commit

Permalink
Add tests for rust code
Browse files Browse the repository at this point in the history
  • Loading branch information
nadzyah committed Feb 2, 2024
1 parent 8a1791f commit 5b8b306
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 3 deletions.
2 changes: 1 addition & 1 deletion client/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ The client contains of two modules:

For now, the library contains the function to return a sample certification status. It depends on the environment variable `CERTIFICATION_STATUS` and accepts the following values:

* `0`: The system has not been seen (default behaviour).
* `0`: The system has not been seen (default behaviour even if the env variable is not defined).
* `1`: The system is partially certified (we haven't seen this specific system, but some of its hardware components have been tested on other systems).
* `2`: This system has been certified (but probably for other Ubuntu release).

Expand Down
2 changes: 1 addition & 1 deletion client/hwlib/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ rand = "0.8.5"
reqwest = { version = "0.11.24", features = ["json"] }
serde = { version = "1.0.196", features = ["derive"] }
smbios-lib = "0.9.1"
tokio = { version = "1.35.1", features = ["full"] }
tokio = { version = "1.35.1", features = ["full", "test-util"] }
pyo3 = { version = "0.14", features = ["extension-module"] }
serde_json = "1.0.113"
once_cell = "1.19.0"
2 changes: 1 addition & 1 deletion client/hwlib/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
mod models;
pub mod models;
pub mod py_bindings;
use models::devices;
use models::rbody::{
Expand Down
34 changes: 34 additions & 0 deletions client/hwlib/tests/test_cert_status.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
use hwlib::get_certification_status;
use hwlib::models::rbody::CertificationStatusResponse;

const SERVER_URL: &str = "https://example.com";

#[tokio::test]
async fn test_get_certification_status_not_seen() {
std::env::set_var("CERTIFICATION_STATUS", "0");
let response = get_certification_status(SERVER_URL).await.unwrap();
assert!(matches!(response, CertificationStatusResponse::NotSeen(_)));
std::env::remove_var("CERTIFICATION_STATUS");
}

#[tokio::test]
async fn test_get_certification_status_partially_certified() {
std::env::set_var("CERTIFICATION_STATUS", "1");
let response = get_certification_status(SERVER_URL).await.unwrap();
assert!(matches!(
response,
CertificationStatusResponse::RelatedCertifiedSystemExists(_)
));
std::env::remove_var("CERTIFICATION_STATUS");
}

#[tokio::test]
async fn test_get_certification_status_certified() {
std::env::set_var("CERTIFICATION_STATUS", "2");
let response = get_certification_status(SERVER_URL).await.unwrap();
assert!(matches!(
response,
CertificationStatusResponse::Certified(_)
));
std::env::remove_var("CERTIFICATION_STATUS");
}

0 comments on commit 5b8b306

Please sign in to comment.