Skip to content

Commit

Permalink
Move x records outputed from smdk test to --verbose #3169 (#3234)
Browse files Browse the repository at this point in the history
This is to add verbose flag into smdk test : #3169
  • Loading branch information
TanNgocDo committed May 9, 2023
1 parent f229565 commit 8e95c79
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 18 deletions.
4 changes: 3 additions & 1 deletion crates/smartmodule-development-kit/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@ mod hub;
mod set_public;

use std::path::{PathBuf};

use clap::Parser;
use anyhow::Result;
use tracing::debug;

use cmd::SmdkCommand;

Expand All @@ -23,6 +25,6 @@ fn main() -> Result<()> {
}

pub(crate) fn read_bytes_from_path(path: &PathBuf) -> Result<Vec<u8>> {
println!("loading module at: {}", path.display());
debug!(path = ?path.display(), "Loading module");
std::fs::read(path).map_err(|err| anyhow::anyhow!("error reading wasm file: {}", err))
}
8 changes: 7 additions & 1 deletion crates/smartmodule-development-kit/src/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@ pub struct TestCmd {
/// E.g. smdk test --text '{}' --transform='{"uses":"infinyon/[email protected]","with":{"spec":"[{\"operation\":\"default\",\"spec\":{\"source\":\"test\"}}]"}}'
#[arg(long, short, group = "TestSmartModule")]
transform: Vec<String>,

/// verbose output
#[arg(short = 'v', long = "verbose")]
verbose: bool,
}

fn parse_key_val(s: &str) -> Result<(String, String)> {
Expand Down Expand Up @@ -125,7 +129,9 @@ impl TestCmd {

let output = chain.process(SmartModuleInput::try_from(test_records)?, &metrics)?;

println!("{:?} records outputed", output.successes.len());
if self.verbose {
println!("{:?} records outputed", output.successes.len());
}
for output_record in output.successes {
let output_value = output_record.value.as_str()?;
println!("{output_value}");
Expand Down
46 changes: 30 additions & 16 deletions tests/cli/smdk_smoke_tests/smdk-basic.bats
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ setup_file() {
assert_success

# Test
run $SMDK_BIN test --text 'a'
run $SMDK_BIN test --verbose --text 'a'
assert_output --partial "1 records outputed"
assert_success
}
Expand Down Expand Up @@ -152,7 +152,7 @@ setup_file() {
assert_success

# Test
run $SMDK_BIN test --text '2'
run $SMDK_BIN test --verbose --text '2'
assert_output --partial "1 records outputed"
assert_output --partial "4"
assert_success
Expand Down Expand Up @@ -192,12 +192,19 @@ setup_file() {
assert_output --partial "Creating SmartModule: $SM_PACKAGE_NAME"
assert_success

# Test
run $SMDK_BIN test --text '["foo", "bar"]'
# Test with verbose
run $SMDK_BIN test --verbose --text '["foo", "bar"]'
assert_output --partial "2 records outputed"
assert_output --partial "foo"
assert_output --partial "bar"
assert_success

# Test without verbose
run $SMDK_BIN test --text '["foo", "bar"]'
refute_output --partial "2 records outputed"
assert_output --partial "foo"
assert_output --partial "bar"
assert_success
}

@test "Generate and test filter-map - (stable fluvio-smartmodule / no params)" {
Expand Down Expand Up @@ -236,9 +243,9 @@ setup_file() {
assert_success

# Test
run $SMDK_BIN test --text '2'
run $SMDK_BIN test --verbose --text '2'
assert_output --partial "1 records outputed"
assert_output --partial "2"
assert_output --partial "1"
assert_success
}

Expand Down Expand Up @@ -277,7 +284,7 @@ setup_file() {
assert_success

# Test
run $SMDK_BIN test --text '2'
run $SMDK_BIN test --verbose --text '2'
assert_output --partial "1 records outputed"
assert_output --partial "2"
assert_success
Expand Down Expand Up @@ -320,7 +327,7 @@ setup_file() {
assert_success

# Test
run $SMDK_BIN test --text 'a' -e key=value
run $SMDK_BIN test --verbose --text 'a' -e key=value
assert_output --partial "1 records outputed"
assert_success
}
Expand Down Expand Up @@ -502,7 +509,7 @@ setup_file() {
assert_success

# Test
run $SMDK_BIN test --text 'a'
run $SMDK_BIN test --verbose --text 'a'
assert_output --partial "1 records outputed"
assert_success
}
Expand Down Expand Up @@ -542,7 +549,7 @@ setup_file() {
assert_success

# Test
run $SMDK_BIN test --text '2'
run $SMDK_BIN test --verbose --text '2'
assert_output --partial "1 records outputed"
assert_output --partial "4"
assert_success
Expand Down Expand Up @@ -582,12 +589,19 @@ setup_file() {
assert_output --partial "Creating SmartModule: $SM_PACKAGE_NAME"
assert_success

# Test
run $SMDK_BIN test --text '["foo", "bar"]'
# Test with verbose
run $SMDK_BIN test --verbose --text '["foo", "bar"]'
assert_output --partial "2 records outputed"
assert_output --partial "foo"
assert_output --partial "bar"
assert_success

# Test with without verbose
run $SMDK_BIN test --text '["foo", "bar"]'
refute_output --partial "2 records outputed"
assert_output --partial "foo"
assert_output --partial "bar"
assert_success
}

@test "Generate and test filter-map - (current repo fluvio-smartmodule / no params)" {
Expand Down Expand Up @@ -625,9 +639,9 @@ setup_file() {
assert_success

# Test
run $SMDK_BIN test --text '2'
run $SMDK_BIN test --verbose --text '2'
assert_output --partial "1 records outputed"
assert_output --partial "2"
assert_output --partial "1"
assert_success
}

Expand Down Expand Up @@ -666,7 +680,7 @@ setup_file() {
assert_success

# Test
run $SMDK_BIN test --text '2'
run $SMDK_BIN test --verbose --text '2'
assert_output --partial "1 records outputed"
assert_output --partial "2"
assert_success
Expand Down Expand Up @@ -709,7 +723,7 @@ setup_file() {
assert_success

# Test
run $SMDK_BIN test --text 'a' -e key=value
run $SMDK_BIN test --verbose --text 'a' -e key=value
assert_output --partial "1 records outputed"
assert_success
}
Expand Down

0 comments on commit 8e95c79

Please sign in to comment.