-
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
) * Update file_storage.rs * Update file_storage.rs * Update file_storage.rs * Update file_storage.rs
- Loading branch information
1 parent
9f8258b
commit bd7fa43
Showing
1 changed file
with
40 additions
and
4 deletions.
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 |
---|---|---|
@@ -1,13 +1,49 @@ | ||
use std::fs::{File, OpenOptions}; | ||
|
||
#[allow(dead_code)] | ||
#[derive(Default)] | ||
pub(crate) struct FileStorage {} | ||
pub(crate) struct FileStorage { | ||
filename: String, | ||
file: File, | ||
} | ||
|
||
impl From<&str> for FileStorage { | ||
fn from(filename: &str) -> Self { | ||
FileStorage::from(filename.to_string()) | ||
} | ||
} | ||
|
||
impl From<String> for FileStorage { | ||
fn from(filename: String) -> Self { | ||
FileStorage { | ||
file: OpenOptions::new() | ||
.write(true) | ||
.create(true) | ||
.read(true) | ||
.open(&filename) | ||
.unwrap(), | ||
filename, | ||
} | ||
} | ||
} | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
use super::*; | ||
use crate::test_utilities::test_file::TestFile; | ||
use std::path::Path; | ||
|
||
#[test] | ||
fn create_new_file() { | ||
let test_file = TestFile::from("./file_storage_test01.agdb"); | ||
let _storage = FileStorage::from(test_file.file_name().as_str()); | ||
|
||
assert!(Path::new(test_file.file_name()).exists()); | ||
} | ||
|
||
#[test] | ||
fn file_storage() { | ||
let _storage = FileStorage::default(); | ||
fn open_existing_file() { | ||
let test_file = TestFile::from("./file_storage_test02.agdb"); | ||
File::create(test_file.file_name()).unwrap(); | ||
let _storage = FileStorage::from(test_file.file_name().clone()); | ||
} | ||
} |