use assert_cmd::Command;
use predicates::prelude::*;
mod helpers;
use helpers::{TestContext, setup_test_cmd};
#[test]
fn test_config_list_default() {
let ctx = TestContext::new("http://localhost:38080".to_string());
ctx.write_config();
let mut cmd = setup_test_cmd(&ctx);
cmd.arg("config")
.arg("list")
.assert()
.success()
.stdout(predicates::str::contains("server.url = http://localhost:38080"))
.stdout(predicates::str::contains("output.format = table"))
.stdout(predicates::str::contains("output.color = true"))
.stdout(predicates::str::contains("log.level = info"));
}
#[test]
fn test_config_get_server_url() {
let ctx = TestContext::new("http://localhost:38080".to_string());
ctx.write_config();
let mut cmd = setup_test_cmd(&ctx);
cmd.arg("config")
.arg("get")
.arg("server.url")
.assert()
.success()
.stdout(predicates::str::contains("http://localhost:38080"));
}
#[test]
fn test_config_set_output_format() {
let ctx = TestContext::new("http://localhost:38080".to_string());
ctx.write_config();
let mut cmd = setup_test_cmd(&ctx);
cmd.arg("config")
.arg("set")
.arg("output.format")
.arg("json")
.assert()
.success()
.stdout(predicates::str::contains("Set output.format"));
let mut cmd = setup_test_cmd(&ctx);
cmd.arg("config")
.arg("get")
.arg("output.format")
.assert()
.success()
.stdout(predicates::str::contains("json"));
}
#[test]
fn test_config_reset() {
let ctx = TestContext::new("http://localhost:38080".to_string());
ctx.write_config();
let mut cmd = setup_test_cmd(&ctx);
cmd.arg("config")
.arg("reset")
.assert()
.success()
.stdout(predicates::str::contains("Configuration reset"));
let mut cmd = setup_test_cmd(&ctx);
cmd.arg("config")
.arg("list")
.assert()
.success();
}
#[test]
fn test_config_get_nonexistent_key() {
let ctx = TestContext::new("http://localhost:38080".to_string());
ctx.write_config();
let mut cmd = setup_test_cmd(&ctx);
cmd.arg("config")
.arg("get")
.arg("nonexistent.key")
.assert()
.failure()
.stderr(predicates::str::contains("Unknown config key"));
}