test: Quests Create/Read/Update/Delete
This commit is contained in:
parent
01d3755ea6
commit
f5180a559b
3 changed files with 40 additions and 0 deletions
29
tests/io.rs
Normal file
29
tests/io.rs
Normal file
|
|
@ -0,0 +1,29 @@
|
||||||
|
use squad_quest::{config::Config,quest::{error::{QuestError}, Quest}};
|
||||||
|
use std::path::PathBuf;
|
||||||
|
|
||||||
|
const CONFIG_PATH: &str = "tests/io/config.toml";
|
||||||
|
|
||||||
|
// Note: Quest::delete uses Quest::load underneath,
|
||||||
|
// and Quest::save can override files,
|
||||||
|
// so this test covers full quest CRUD
|
||||||
|
#[test]
|
||||||
|
fn quest_crud() -> Result<(), QuestError> {
|
||||||
|
let config = Config::load(CONFIG_PATH.into());
|
||||||
|
|
||||||
|
let mut quests_path = PathBuf::from(CONFIG_PATH).parent().unwrap().to_owned();
|
||||||
|
quests_path.push(config.quests_path);
|
||||||
|
|
||||||
|
let quest = Quest::default();
|
||||||
|
|
||||||
|
println!("{:?}", quests_path.clone());
|
||||||
|
|
||||||
|
quest.save(quests_path.clone())?;
|
||||||
|
|
||||||
|
let filename = format!("{}.toml", quest.id);
|
||||||
|
|
||||||
|
let delete_path = quests_path.with_file_name(filename);
|
||||||
|
|
||||||
|
Quest::delete(delete_path)?;
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
10
tests/io/config.toml
Normal file
10
tests/io/config.toml
Normal file
|
|
@ -0,0 +1,10 @@
|
||||||
|
# Default config
|
||||||
|
|
||||||
|
# Path to quests folder relative to config
|
||||||
|
quests_path = "quests"
|
||||||
|
|
||||||
|
# Path to accounts folder relative to config
|
||||||
|
accounts_path = "accounts"
|
||||||
|
|
||||||
|
# Path to map .toml file relative to config
|
||||||
|
map = "map.toml"
|
||||||
1
tests/io/quests/.placeholder
Normal file
1
tests/io/quests/.placeholder
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
this file exists because git requires directory to have a file in order to commit it
|
||||||
Loading…
Add table
Add a link
Reference in a new issue