Skip to content

Commit

Permalink
reorganize file storage test mod & import
Browse files Browse the repository at this point in the history
  • Loading branch information
ewilken committed Dec 29, 2020
1 parent 9c2b3fb commit c4c9a57
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 15 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "hap"
version = "0.1.0-pre.4"
version = "0.1.0-pre.5"
authors = ["Elias Wilken <[email protected]>"]
edition = "2018"
description = "Rust implementation of the Apple HomeKit Accessory Protocol (HAP)"
Expand Down
2 changes: 1 addition & 1 deletion codegen/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "hap-codegen"
version = "0.1.0-pre.4"
version = "0.1.0-pre.5"
authors = ["Elias Wilken <[email protected]>"]
edition = "2018"
description = "Rust implementation of the Apple HomeKit Accessory Protocol (HAP)"
Expand Down
35 changes: 22 additions & 13 deletions src/storage/file_storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use async_trait::async_trait;
use tokio::task::spawn_blocking;
use uuid::Uuid;

use crate::{pairing::Pairing, server::ServerPersistence, storage::Storage, BonjourStatusFlag, Config, Error, Result};
use crate::{pairing::Pairing, server::ServerPersistence, storage::Storage, Config, Error, Result};

/// `FileStorage` is an implementor of the `Storage` trait that stores data to the file system.
#[derive(Debug)]
Expand Down Expand Up @@ -221,16 +221,25 @@ impl Storage for FileStorage {
}
}

#[tokio::test]
/// Ensure we can write a config, then a shorter one, without corrupting data.
async fn test_shorten_config() {
let mut config = Default::default();
let mut storage = FileStorage::new(&std::env::temp_dir()).await.unwrap();
storage.save_config(&config).await.unwrap();
config.status_flag = BonjourStatusFlag::Zero;
storage.save_config(&config).await.unwrap();
assert_eq!(
storage.load_config().await.unwrap().status_flag,
BonjourStatusFlag::Zero
)
#[cfg(test)]
mod tests {
use super::*;

use crate::BonjourStatusFlag;

#[tokio::test]
/// Ensure we can write a config, then a shorter one, without corrupting data.
async fn test_shorten_config() {
let mut config = Default::default();
let mut storage = FileStorage::new(&std::env::temp_dir()).await.unwrap();

storage.save_config(&config).await.unwrap();
config.status_flag = BonjourStatusFlag::Zero;
storage.save_config(&config).await.unwrap();

assert_eq!(
storage.load_config().await.unwrap().status_flag,
BonjourStatusFlag::Zero
)
}
}

0 comments on commit c4c9a57

Please sign in to comment.