Skip to content

Commit

Permalink
Add some tests for stratisd-tools parser
Browse files Browse the repository at this point in the history
Signed-off-by: mulhern <amulhern@redhat.com>
  • Loading branch information
the Mulhern authored and mulkieran committed Feb 7, 2025
1 parent d8b33e6 commit 6a8d629
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 0 deletions.
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,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_TARGET_X86_64_UNKNOWN_LINUX_GNU_RUNNER='sudo -E' cargo test --no-default-features --features "engine,extras" test_stratisd_tools

## Run yamllint on workflow files
yamllint:
yamllint --strict .github/workflows/*.yml .packit.yaml
Expand Down
40 changes: 40 additions & 0 deletions tests/stratisd_tools.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// 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<dyn std::error::Error>> {
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<dyn std::error::Error>> {
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<dyn std::error::Error>> {
let mut cmd = Command::cargo_bin("stratisd-tools")?;
cmd.arg("notasub");
cmd.assert().failure().code(2);
Ok(())
}

0 comments on commit 6a8d629

Please sign in to comment.