|
| 1 | +use std::fs; |
| 2 | +use std::process::Command; |
| 3 | + |
| 4 | +use tempfile::tempdir; |
| 5 | + |
| 6 | +fn combined_output(output: &std::process::Output) -> String { |
| 7 | + format!( |
| 8 | + "{}{}", |
| 9 | + String::from_utf8_lossy(&output.stdout), |
| 10 | + String::from_utf8_lossy(&output.stderr) |
| 11 | + ) |
| 12 | +} |
| 13 | + |
| 14 | +#[test] |
| 15 | +fn logs_paths_accepts_default_lines() { |
| 16 | + let home = tempdir().unwrap(); |
| 17 | + let cache = tempdir().unwrap(); |
| 18 | + let logs_dir = cache.path().join("cortex").join("logs"); |
| 19 | + fs::create_dir_all(&logs_dir).unwrap(); |
| 20 | + fs::write(logs_dir.join("cortex.log"), "log\n").unwrap(); |
| 21 | + |
| 22 | + let output = Command::new(env!("CARGO_BIN_EXE_Cortex")) |
| 23 | + .args(["logs", "--paths"]) |
| 24 | + .env("HOME", home.path()) |
| 25 | + .env("XDG_CACHE_HOME", cache.path()) |
| 26 | + .env_remove("CORTEX_HOME") |
| 27 | + .output() |
| 28 | + .unwrap(); |
| 29 | + |
| 30 | + assert!( |
| 31 | + output.status.success(), |
| 32 | + "logs --paths should accept default --lines:\n{}", |
| 33 | + combined_output(&output) |
| 34 | + ); |
| 35 | +} |
| 36 | + |
| 37 | +#[test] |
| 38 | +fn logs_paths_rejects_viewing_flags() { |
| 39 | + for args in [ |
| 40 | + ["logs", "--paths", "--follow"].as_slice(), |
| 41 | + ["logs", "--paths", "--level", "error"].as_slice(), |
| 42 | + ["logs", "--paths", "--lines", "5"].as_slice(), |
| 43 | + ] { |
| 44 | + let output = Command::new(env!("CARGO_BIN_EXE_Cortex")) |
| 45 | + .args(args) |
| 46 | + .output() |
| 47 | + .unwrap(); |
| 48 | + |
| 49 | + assert!(!output.status.success(), "expected {:?} to fail", args); |
| 50 | + let output = combined_output(&output); |
| 51 | + assert!( |
| 52 | + output.contains("cannot be used with") || output.contains("conflict"), |
| 53 | + "expected conflict error for {:?}, got:\n{}", |
| 54 | + args, |
| 55 | + output |
| 56 | + ); |
| 57 | + } |
| 58 | +} |
0 commit comments