fix: use documented swapon show columns
This commit is contained in:
@@ -11,17 +11,17 @@ use std::os::unix::fs::PermissionsExt;
|
||||
|
||||
use super::model::ActiveSwap;
|
||||
|
||||
fn swapon_show_args() -> [&'static str; 4] {
|
||||
[
|
||||
"--show=NAME,TYPE,SIZE,PRIO",
|
||||
"--bytes",
|
||||
"--raw",
|
||||
"--noheadings",
|
||||
]
|
||||
}
|
||||
|
||||
pub(super) fn read_active_swaps() -> anyhow::Result<Vec<ActiveSwap>> {
|
||||
let out = Command::new("swapon")
|
||||
.args([
|
||||
"--show",
|
||||
"--bytes",
|
||||
"--raw",
|
||||
"--noheadings",
|
||||
"--output",
|
||||
"NAME,TYPE,SIZE,PRIO",
|
||||
])
|
||||
.output()?;
|
||||
let out = Command::new("swapon").args(swapon_show_args()).output()?;
|
||||
if !out.status.success() {
|
||||
anyhow::bail!(
|
||||
"swapon --show failed: {}",
|
||||
@@ -111,6 +111,20 @@ pub(super) fn run(program: &str, args: &[&str]) -> anyhow::Result<()> {
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn swapon_uses_the_documented_show_columns_form() {
|
||||
assert_eq!(
|
||||
swapon_show_args(),
|
||||
[
|
||||
"--show=NAME,TYPE,SIZE,PRIO",
|
||||
"--bytes",
|
||||
"--raw",
|
||||
"--noheadings"
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn parse_swapon_empty() {
|
||||
let got = parse_swapon_output("").expect("parse");
|
||||
|
||||
Reference in New Issue
Block a user