nushell/tests/command_config_test.rs

116 lines
2.9 KiB
Rust
Raw Normal View History

2019-09-10 12:08:01 +02:00
mod helpers;
use helpers as h;
use helpers::{Playground, Stub::*};
use std::path::PathBuf;
#[test]
fn has_default_configuration_file() {
2019-09-11 16:36:50 +02:00
let expected = "config.toml";
2019-09-10 12:08:01 +02:00
Playground::setup("config_test_1", |dirs, _| {
nu!(cwd: dirs.root(), "config");
assert_eq!(
2019-09-11 16:36:50 +02:00
dirs.config_path().join(expected),
nu::config_path().unwrap().join(expected)
2019-09-10 12:08:01 +02:00
);
})
}
#[test]
fn shows_path_of_configuration_file() {
2019-09-11 16:36:50 +02:00
let expected = "config.toml";
2019-09-10 12:08:01 +02:00
Playground::setup("config_test_2", |dirs, _| {
let actual = nu!(
cwd: dirs.test(),
"config --path | echo $it"
);
assert_eq!(PathBuf::from(actual), dirs.config_path().join(expected));
});
}
#[test]
fn use_different_configuration() {
Playground::setup("config_test_3", |dirs, sandbox| {
2019-09-11 16:36:50 +02:00
sandbox.with_files(vec![FileWithContent(
"test_3.toml",
r#"
2019-09-10 12:08:01 +02:00
caballero_1 = "Andrés N. Robalino"
caballero_2 = "Jonathan Turner"
caballero_3 = "Yehuda katz"
2019-09-11 16:36:50 +02:00
"#,
2019-09-10 12:08:01 +02:00
)]);
let actual = nu!(
cwd: dirs.root(),
"config --get caballero_1 --load {}/test_3.toml | echo $it",
dirs.test()
);
assert_eq!(actual, "Andrés N. Robalino");
});
2019-09-11 16:36:50 +02:00
h::delete_file_at(nu::config_path().unwrap().join("test_3.toml"));
2019-09-10 12:08:01 +02:00
}
#[test]
fn sets_configuration_value() {
Playground::setup("config_test_4", |dirs, sandbox| {
2019-09-11 16:36:50 +02:00
sandbox.with_files(vec![FileWithContent(
"test_4.toml",
r#"
2019-09-10 12:08:01 +02:00
caballero_1 = "Andrés N. Robalino"
caballero_2 = "Jonathan Turner"
caballero_3 = "Yehuda katz"
2019-09-11 16:36:50 +02:00
"#,
2019-09-10 12:08:01 +02:00
)]);
nu!(
cwd: dirs.test(),
"config --load test_4.toml --set [caballero_4 jonas]"
);
let actual = nu!(
2019-09-11 16:36:50 +02:00
cwd: dirs.root(),
r#"open "{}/test_4.toml" | get caballero_4 | echo $it"#,
dirs.config_path()
2019-09-10 12:08:01 +02:00
);
assert_eq!(actual, "jonas");
});
2019-09-11 16:36:50 +02:00
h::delete_file_at(nu::config_path().unwrap().join("test_4.toml"));
2019-09-10 12:08:01 +02:00
}
#[test]
fn removes_configuration_value() {
Playground::setup("config_test_5", |dirs, sandbox| {
2019-09-11 16:36:50 +02:00
sandbox.with_files(vec![FileWithContent(
"test_5.toml",
r#"
2019-09-10 12:08:01 +02:00
caballeros = [1, 1, 1]
podershell = [1, 1, 1]
2019-09-11 16:36:50 +02:00
"#,
2019-09-10 12:08:01 +02:00
)]);
nu!(
cwd: dirs.test(),
"config --load test_5.toml --remove podershell"
);
let actual = nu_error!(
2019-09-11 16:36:50 +02:00
cwd: dirs.root(),
r#"open "{}/test_5.toml" | get podershell | echo $it"#,
dirs.config_path()
2019-09-10 12:08:01 +02:00
);
assert!(actual.contains("Unknown column"));
2019-09-10 12:08:01 +02:00
});
2019-09-11 16:36:50 +02:00
h::delete_file_at(nu::config_path().unwrap().join("test_5.toml"));
}