-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(#9): storage init #20
Changes from 12 commits
f7f8828
7de02f0
31d4db5
5bed624
5a92c06
6cfc7b3
b9c5748
72e0472
4bc3d1b
0d0e83b
9622a5b
7062ad5
3ae99e2
58a29ea
ff60e25
c160bca
0d3c5d5
32b8822
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -33,8 +33,10 @@ all. | |
authors = ["Aliaksei Bialíauski <[email protected]>", "Ivanchuk Ivan <[email protected]>"] | ||
|
||
[dependencies] | ||
env_logger = "0.11.3" | ||
anyhow = "1.0.86" | ||
log = { version = "0.4.21", features = [] } | ||
serde = { version = "1.0.203", features = ["derive"] } | ||
serde_json = "1.0.117" | ||
anyhow = "1.0.86" | ||
axum = "0.7.5" | ||
tokio = { version = "1.0.0", features = ["rt", "rt-multi-thread", "macros", "fs"] } |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
// The MIT License (MIT) | ||
// | ||
// Copyright (c) 2024 Aliaksei Bialiauski | ||
// | ||
// Permission is hereby granted, free of charge, to any person obtaining a copy | ||
// of this software and associated documentation files (the "Software"), to deal | ||
// in the Software without restriction, including without limitation the rights | ||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
// copies of the Software, and to permit persons to whom the Software is | ||
// furnished to do so, subject to the following conditions: | ||
// | ||
// The above copyright notice and this permission notice shall be included | ||
// in all copies or substantial portions of the Software. | ||
// | ||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
// FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE | ||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
// SOFTWARE. | ||
pub mod storage; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
// The MIT License (MIT) | ||
// | ||
// Copyright (c) 2024 Aliaksei Bialiauski | ||
// | ||
// Permission is hereby granted, free of charge, to any person obtaining a copy | ||
// of this software and associated documentation files (the "Software"), to deal | ||
// in the Software without restriction, including without limitation the rights | ||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
// copies of the Software, and to permit persons to whom the Software is | ||
// furnished to do so, subject to the following conditions: | ||
// | ||
// The above copyright notice and this permission notice shall be included | ||
// in all copies or substantial portions of the Software. | ||
// | ||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
// FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE | ||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
// SOFTWARE. | ||
use std::fmt::Error; | ||
use std::fs::File; | ||
|
||
use log::info; | ||
|
||
pub fn touch_storage() { | ||
let path = "fakehub.xml"; | ||
info!("Initializing XML storage: {path}"); | ||
let creating = File::create(path); | ||
let _ = match creating { | ||
Ok(file) => { | ||
info!("'{path}' initialized"); | ||
Ok::<File, Error>(file) | ||
} | ||
Err(err) => { | ||
panic!("fakehub storage failed to initialize in '{path}': {err}"); | ||
} | ||
}; | ||
} | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
use std::fs; | ||
use std::path::Path; | ||
|
||
use crate::xml::storage::touch_storage; | ||
|
||
fn clean() { | ||
fs::remove_file("fakehub.xml").unwrap(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i think better solution would be using temp files, like this There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @l3r8yJ we create this file inside There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @h1alexbel you can pass a temp directory and create file inside of it. I think that even better would be if |
||
} | ||
|
||
#[test] | ||
fn creates_xml_storage() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. best practise is to return |
||
touch_storage(); | ||
let storage = "fakehub.xml"; | ||
let exists = Path::new(storage).exists(); | ||
assert!( | ||
exists, | ||
"storage file '{storage}' was not created, but should" | ||
); | ||
clean(); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
might be we should return the file from
touch_storage
and pass it to next function instead of sharing it by name?