From d64226efee73471bce5eb938431bd7e44bae4a8a Mon Sep 17 00:00:00 2001 From: Thomas Lamprecht Date: Mon, 1 Mar 2021 17:36:15 +0100 Subject: [PATCH] disks/zfs: fix test input and enforce check for config key we test for the config key in the API so it makes sense to have as test here too. Actually it would be better if we'd have a expect Value defined here and enforce that it matches, but better than nothing. Fix the input for test 1, where tabs got replaced by spaces, as else it fails Signed-off-by: Thomas Lamprecht --- src/tools/disks/zpool_status.rs | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/src/tools/disks/zpool_status.rs b/src/tools/disks/zpool_status.rs index c7b213a6..555d47ff 100644 --- a/src/tools/disks/zpool_status.rs +++ b/src/tools/disks/zpool_status.rs @@ -372,14 +372,20 @@ pub fn zpool_status(pool: &str) -> Result, Error> { #[cfg(test)] fn test_parse(output: &str) -> Result<(), Error> { + let mut found_config = false; + for (k, v) in parse_zpool_status(&output)? { - println!("{} => {}", k,v); + println!("<{}> => '{}'", k, v); if k == "config" { let vdev_list = parse_zpool_status_config_tree(&v)?; let _tree = vdev_list_to_tree(&vdev_list); found_config = true; } } + if !found_config { + bail!("got zpool status without config key"); + } + Ok(()) } @@ -389,21 +395,21 @@ fn test_zpool_status_parser() -> Result<(), Error> { let output = r###" pool: tank state: DEGRADED status: One or more devices could not be opened. Sufficient replicas exist for - the pool to continue functioning in a degraded state. + the pool to continue functioning in a degraded state. action: Attach the missing device and online it using 'zpool online'. - see: http://www.sun.com/msg/ZFS-8000-2Q + see: http://www.sun.com/msg/ZFS-8000-2Q scrub: none requested config: - NAME STATE READ WRITE CKSUM - tank DEGRADED 0 0 0 - mirror-0 DEGRADED 0 0 0 - c1t0d0 ONLINE 0 0 0 - c1t2d0 ONLINE 0 0 0 - c1t1d0 UNAVAIL 0 0 0 cannot open - mirror-1 DEGRADED 0 0 0 - tank1 DEGRADED 0 0 0 - tank2 DEGRADED 0 0 0 + NAME STATE READ WRITE CKSUM + tank DEGRADED 0 0 0 + mirror-0 DEGRADED 0 0 0 + c1t0d0 ONLINE 0 0 0 + c1t2d0 ONLINE 0 0 0 + c1t1d0 UNAVAIL 0 0 0 cannot open + mirror-1 DEGRADED 0 0 0 + tank1 DEGRADED 0 0 0 + tank2 DEGRADED 0 0 0 errors: No known data errors "###;