Skip to content

Commit

Permalink
Merge pull request #15 from ChristophWurst/test/config-integration-tests
Browse files Browse the repository at this point in the history
Config integration tests
  • Loading branch information
ChristophWurst authored Nov 22, 2017
2 parents fcbfb7c + d2a9725 commit 816e94b
Show file tree
Hide file tree
Showing 33 changed files with 3,000 additions and 4 deletions.
2 changes: 1 addition & 1 deletion .vscode/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,4 @@
]
}
]
}
}
8 changes: 8 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,7 @@ openssl = "0.9"
pathdiff = "0.1.0"
walkdir = "2.0.1"
xdg = "2.1.0"

[dev-dependencies]
fs_extra = "1.0.0"
tempdir = "0.3"
58 changes: 57 additions & 1 deletion src/config/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ pub fn init_config(app_path: &Path) -> Result<(), error::Error> {
));
}

let mut config_file = File::create(path_buf)?;
let mut config_file = File::create(&path_buf)?;

config_file.write_all(
r#"[packaging]
Expand Down Expand Up @@ -132,8 +132,64 @@ pub fn get_config(path: &Path) -> Result<AppConfig, error::Error> {

#[cfg(test)]
mod tests {
use std::fs::File;
use std::path::PathBuf;

use fs_extra::dir::{copy, CopyOptions};
use tempdir::TempDir;

use super::*;

fn prepare_fs_test(id: &'static str) -> (PathBuf, TempDir) {
let mut src = PathBuf::from("./tests/apps");
src.push(id);

let tmp = TempDir::new("krankerl").unwrap();
let options = CopyOptions::new();
copy(&src, tmp.path(), &options).expect("copy app files");

let mut app_path = tmp.path().to_path_buf();
app_path.push(id);
(app_path, tmp)
}

#[test]
fn test_init_creates_config() {
let (app_path, tmp) = prepare_fs_test("app1");

let mut krankl_path = app_path.clone();
krankl_path.push("krankerl.toml");
File::open(&krankl_path).unwrap_err();

init_config(&app_path).unwrap();

File::open(&krankl_path).unwrap();
tmp.close().unwrap();
}

#[test]
fn test_init_stops_if_config_exists() {
let (app_path, tmp) = prepare_fs_test("app2");

let mut krankl_path = app_path.clone();
krankl_path.push("krankerl.toml");
File::open(&krankl_path).unwrap();

init_config(&app_path).unwrap_err();

File::open(&krankl_path).unwrap();
tmp.close().unwrap();
}

#[test]
fn test_load_config() {
let (app_path, tmp) = prepare_fs_test("app3");

load_config(&app_path).unwrap();

tmp.close().unwrap();
}

#[test]
fn test_parse_empty_config() {
let toml = r#""#;
Expand Down
2 changes: 1 addition & 1 deletion src/config/krankerl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use std::fs::OpenOptions;
use std::io::prelude::*;
use xdg;

use super::super::error;
use error;

#[derive(Debug, Deserialize, Serialize)]
pub struct Config {
Expand Down
2 changes: 1 addition & 1 deletion src/config/mod.rs
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
pub mod app;
pub mod krankerl;
pub mod krankerl;
4 changes: 4 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
extern crate base64;
extern crate flate2;
#[cfg(test)]
extern crate fs_extra;
extern crate futures;
extern crate futures_cpupool;
extern crate globset;
Expand All @@ -13,6 +15,8 @@ extern crate pathdiff;
extern crate serde_derive;
extern crate serde_json;
extern crate tar;
#[cfg(test)]
extern crate tempdir;
extern crate tokio_core;
extern crate toml;
extern crate walkdir;
Expand Down
Loading

0 comments on commit 816e94b

Please sign in to comment.