Skip to content

Commit

Permalink
- added unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
aschnell committed Jan 30, 2025
1 parent da60f5c commit 0147072
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 2 deletions.
4 changes: 2 additions & 2 deletions testsuite/SystemInfo/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand Down
63 changes: 63 additions & 0 deletions testsuite/SystemInfo/df.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@

#define BOOST_TEST_DYN_LINK
#define BOOST_TEST_MODULE libstorage

#include <boost/test/unit_test.hpp>
#include <boost/algorithm/string.hpp>

#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<string>& input, const vector<string>& 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<string> input = {
" 1B-blocks Used Avail Type",
"10738466816 7864320 10183770112 btrfs"
};

vector<string> output = {
"path:/test size:10738466816 used:7864320 available:10183770112 fs-type:btrfs"
};

check(input, output);
}


BOOST_AUTO_TEST_CASE(parse2)
{
vector<string> input = {
" 1B-blocks Used Avail Type",
"983348543488 61565304832 871756464128 nfs4"
};

vector<string> output = {
"path:/test size:983348543488 used:61565304832 available:871756464128 fs-type:nfs4"
};

check(input, output);
}

0 comments on commit 0147072

Please sign in to comment.