From 0147072652a7928476f904d5f5fc7bc3552de367 Mon Sep 17 00:00:00 2001 From: Arvin Schnell Date: Thu, 30 Jan 2025 16:47:33 +0100 Subject: [PATCH] - added unit tests --- testsuite/SystemInfo/Makefile.am | 4 +- testsuite/SystemInfo/df.cc | 63 ++++++++++++++++++++++++++++++++ 2 files changed, 65 insertions(+), 2 deletions(-) create mode 100644 testsuite/SystemInfo/df.cc diff --git a/testsuite/SystemInfo/Makefile.am b/testsuite/SystemInfo/Makefile.am index 1720e0fc..db8f7e34 100644 --- a/testsuite/SystemInfo/Makefile.am +++ b/testsuite/SystemInfo/Makefile.am @@ -12,8 +12,8 @@ check_PROGRAMS = \ btrfs-subvolume-get-default.test btrfs-subvolume-list.test \ btrfs-subvolume-show.test btrfs-qgroup-show-60.test \ btrfs-qgroup-show-602.test btrfs-qgroup-show-62.test \ - cryptsetup-status.test \ - cryptsetup-bitlk-dump.test cryptsetup-luks-dump.test dasdview.test \ + cryptsetup-status.test cryptsetup-bitlk-dump.test \ + cryptsetup-luks-dump.test dasdview.test df.test \ dir.test dmraid.test dumpe2fs.test resize2fs.test ntfsresize.test \ dmsetup-info.test dmsetup-table.test lsattr.test lsscsi.test lvs.test \ mdadm-detail.test mdlinks.test \ diff --git a/testsuite/SystemInfo/df.cc b/testsuite/SystemInfo/df.cc new file mode 100644 index 00000000..3fc8c252 --- /dev/null +++ b/testsuite/SystemInfo/df.cc @@ -0,0 +1,63 @@ + +#define BOOST_TEST_DYN_LINK +#define BOOST_TEST_MODULE libstorage + +#include +#include + +#include "storage/SystemInfo/CmdDf.h" +#include "storage/Utils/Mockup.h" +#include "storage/Utils/StorageDefines.h" + + +using namespace std; +using namespace storage; + + +void +check(const vector& input, const vector& output) +{ + Mockup::set_mode(Mockup::Mode::PLAYBACK); + Mockup::set_command(DF_BIN " --block-size=1 --output=size,used,avail,fstype /test", input); + + CmdDf cmd_df("/test"); + + ostringstream parsed; + parsed.setf(std::ios::boolalpha); + parsed << cmd_df; + + string lhs = parsed.str(); + string rhs = boost::join(output, "\n") + "\n"; + + BOOST_CHECK_EQUAL(lhs, rhs); +} + + +BOOST_AUTO_TEST_CASE(parse1) +{ + vector input = { + " 1B-blocks Used Avail Type", + "10738466816 7864320 10183770112 btrfs" + }; + + vector output = { + "path:/test size:10738466816 used:7864320 available:10183770112 fs-type:btrfs" + }; + + check(input, output); +} + + +BOOST_AUTO_TEST_CASE(parse2) +{ + vector input = { + " 1B-blocks Used Avail Type", + "983348543488 61565304832 871756464128 nfs4" + }; + + vector output = { + "path:/test size:983348543488 used:61565304832 available:871756464128 fs-type:nfs4" + }; + + check(input, output); +}