diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index eb2ae4e0ee..03518c5989 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -167,6 +167,8 @@ jobs: run: make test-stratisd-min - name: Run stratis-min cli tests run: make test-stratis-min + - name: Run stratis-tools tests + run: make test-stratisd-tools shell-checks: runs-on: ubuntu-22.04 diff --git a/Makefile b/Makefile index fe0271611f..878e404988 100644 --- a/Makefile +++ b/Makefile @@ -386,6 +386,10 @@ test-stratisd-min: test-stratis-min: RUSTFLAGS="${PROFILE_FLAGS}" RUST_BACKTRACE=1 RUST_TEST_THREADS=1 CARGO_TARGET_X86_64_UNKNOWN_LINUX_GNU_RUNNER='sudo -E' cargo test --no-default-features --features "engine,min" test_stratis_min +## Test stratisd-tools CLI +test-stratisd-tools: + RUSTFLAGS="${PROFILE_FLAGS}" RUST_BACKTRACE=1 RUST_TEST_THREADS=1 cargo test --no-default-features --features "engine,extras" test_stratisd_tools + ## Run yamllint on workflow files yamllint: yamllint --strict .github/workflows/*.yml .packit.yaml diff --git a/tests/stratisd_tools.rs b/tests/stratisd_tools.rs new file mode 100644 index 0000000000..5fee5c4259 --- /dev/null +++ b/tests/stratisd_tools.rs @@ -0,0 +1,49 @@ +// This Source Code Form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at http://mozilla.org/MPL/2.0/. + +#![cfg(all(feature = "engine", feature = "extras"))] + +use assert_cmd::Command; +use predicates::prelude::predicate; + +const VERSION: &str = env!("CARGO_PKG_VERSION"); + +// stratisd-tools parser tests + +#[test] +// Test stratisd-tools -V produces version string. +fn test_stratisd_tools_version() -> Result<(), Box> { + let mut cmd = Command::cargo_bin("stratisd-tools")?; + cmd.arg("-V"); + cmd.assert() + .success() + .stdout(predicate::str::contains(VERSION)); + Ok(()) +} + +#[test] +// Test stratisd-tools when no subcommand is given. +fn test_stratisd_tools_no_subcommand() -> Result<(), Box> { + let mut cmd = Command::cargo_bin("stratisd-tools")?; + cmd.assert().failure().code(2); + Ok(()) +} + +#[test] +// Test that stratisd-tools rejects an unknown subcommand. +fn test_stratisd_tools_bad_subcommand() -> Result<(), Box> { + let mut cmd = Command::cargo_bin("stratisd-tools")?; + cmd.arg("notasub"); + cmd.assert().failure().code(2); + Ok(()) +} + +#[test] +fn test_stratisd_tools_good_subcommand() -> Result<(), Box> { + let mut cmd = Command::cargo_bin("stratisd-tools")?; + cmd.arg("stratis-dumpmetadata"); + cmd.arg("--help"); + cmd.assert().success(); + Ok(()) +}