Skip to content

Commit

Permalink
Move util tests to utils folder
Browse files Browse the repository at this point in the history
Related-to: TOR-3521

Signed-off-by: Leonardo Held <[email protected]>
  • Loading branch information
leonheldattoradex committed Aug 20, 2024
1 parent 7a58112 commit 4b322eb
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 9 deletions.
1 change: 0 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ use tokio::sync::mpsc::Sender;

mod dbus;
mod utils;
mod utils_test;

use utils::{load_cert, load_private_key, read_device_id, parse_payload};

Expand Down
2 changes: 2 additions & 0 deletions src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ use serde_json;
use crate::CertificateDer;
use crate::PrivateKeyDer;

mod tests;

// blocking
pub fn load_cert<P: AsRef<Path>>(filename: P) -> Result<CertificateDer<'static>> {
let certfile =
Expand Down
File renamed without changes.
File renamed without changes.
14 changes: 6 additions & 8 deletions src/utils_test.rs → src/utils/tests.rs
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
// Copyright 2024 Toradex A.G.
// SPDX-License-Identifier: Apache-2.0

use std::path::{Path};

use crate::utils::{load_cert, load_private_key, read_device_id, parse_payload};

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

use std::path::Path;
use crate::utils::{load_cert, load_private_key, read_device_id, parse_payload};


#[test]
fn test_load_cert() {
let cert_path = Path::new("src/test_data/client.crt");
let cert_path = Path::new("src/utils/test_data/client.crt");
let result = load_cert(cert_path);
assert!(result.is_ok(), "Failed to load certificate: {:?}", result.err());

Expand All @@ -22,14 +20,14 @@ mod tests {

#[test]
fn test_load_private_key() {
let key_path = Path::new("src/test_data/client.key");
let key_path = Path::new("src/utils/test_data/client.key");
let result = load_private_key(key_path);
assert!(result.is_ok(), "Failed to load private key: {:?}", result.err());
}

#[test]
fn test_read_device_id() {
let cert_path = Path::new("src/test_data/client.crt");
let cert_path = Path::new("src/utils/test_data/client.crt");
let cert = load_cert(cert_path).expect("Failed to load cert");
let result = read_device_id(&cert);
assert!(result.is_ok(), "Failed to read device id: {:?}", result.err());
Expand Down

0 comments on commit 4b322eb

Please sign in to comment.