From 0f1fc739d5ecd73dc0be240aa71ae66841f62d5c Mon Sep 17 00:00:00 2001 From: Tan Date: Sun, 7 May 2023 17:22:34 +0700 Subject: [PATCH 1/5] add verbose flag to smdk test --- .../smartmodule-development-kit/src/main.rs | 3 ++- .../smartmodule-development-kit/src/test.rs | 8 ++++++- tests/cli/smdk_smoke_tests/smdk-basic.bats | 24 +++++++++---------- 3 files changed, 21 insertions(+), 14 deletions(-) diff --git a/crates/smartmodule-development-kit/src/main.rs b/crates/smartmodule-development-kit/src/main.rs index 9f1eb90ca1..448fdb0e95 100644 --- a/crates/smartmodule-development-kit/src/main.rs +++ b/crates/smartmodule-development-kit/src/main.rs @@ -10,6 +10,7 @@ mod set_public; use std::path::{PathBuf}; use clap::Parser; use anyhow::Result; +use tracing::debug; use cmd::SmdkCommand; @@ -23,6 +24,6 @@ fn main() -> Result<()> { } pub(crate) fn read_bytes_from_path(path: &PathBuf) -> Result> { - println!("loading module at: {}", path.display()); + debug!("loading module at: {}", path.display()); std::fs::read(path).map_err(|err| anyhow::anyhow!("error reading wasm file: {}", err)) } diff --git a/crates/smartmodule-development-kit/src/test.rs b/crates/smartmodule-development-kit/src/test.rs index 598d3363a8..0ed1e4695e 100644 --- a/crates/smartmodule-development-kit/src/test.rs +++ b/crates/smartmodule-development-kit/src/test.rs @@ -66,6 +66,10 @@ pub struct TestCmd { /// E.g. smdk test --text '{}' --transform='{"uses":"infinyon/jolt@0.1.0","with":{"spec":"[{\"operation\":\"default\",\"spec\":{\"source\":\"test\"}}]"}}' #[clap(long, short, group = "TestSmartModule")] transform: Vec, + + /// verbose output + #[clap(short = 'v', long = "verbose")] + verbose: bool, } fn parse_key_val(s: &str) -> Result<(String, String)> { @@ -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}"); diff --git a/tests/cli/smdk_smoke_tests/smdk-basic.bats b/tests/cli/smdk_smoke_tests/smdk-basic.bats index c66c75e9f2..682fe041fd 100644 --- a/tests/cli/smdk_smoke_tests/smdk-basic.bats +++ b/tests/cli/smdk_smoke_tests/smdk-basic.bats @@ -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 } @@ -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 @@ -193,7 +193,7 @@ setup_file() { assert_success # Test - run $SMDK_BIN test --text '["foo", "bar"]' + run $SMDK_BIN test --verbose --text '["foo", "bar"]' assert_output --partial "2 records outputed" assert_output --partial "foo" assert_output --partial "bar" @@ -236,7 +236,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 @@ -277,7 +277,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 @@ -320,7 +320,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 } @@ -502,7 +502,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 } @@ -542,7 +542,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 @@ -583,7 +583,7 @@ setup_file() { assert_success # Test - run $SMDK_BIN test --text '["foo", "bar"]' + run $SMDK_BIN test --verbose --text '["foo", "bar"]' assert_output --partial "2 records outputed" assert_output --partial "foo" assert_output --partial "bar" @@ -625,7 +625,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 @@ -666,7 +666,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 @@ -709,7 +709,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 } From 0da77858052ad21f06ee8a347acbdc4eb1a61820 Mon Sep 17 00:00:00 2001 From: Tan Date: Mon, 8 May 2023 09:43:14 +0700 Subject: [PATCH 2/5] Update smdk-basic.bats Add verbose smoke test --- tests/cli/smdk_smoke_tests/smdk-basic.bats | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/tests/cli/smdk_smoke_tests/smdk-basic.bats b/tests/cli/smdk_smoke_tests/smdk-basic.bats index 682fe041fd..0dada51de3 100644 --- a/tests/cli/smdk_smoke_tests/smdk-basic.bats +++ b/tests/cli/smdk_smoke_tests/smdk-basic.bats @@ -192,12 +192,18 @@ setup_file() { assert_output --partial "Creating SmartModule: $SM_PACKAGE_NAME" assert_success - # Test + # 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"]' + assert_output --partial "foo" + assert_output --partial "bar" + assert_success } @test "Generate and test filter-map - (stable fluvio-smartmodule / no params)" { @@ -582,12 +588,18 @@ setup_file() { assert_output --partial "Creating SmartModule: $SM_PACKAGE_NAME" assert_success - # Test + # 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"]' + assert_output --partial "foo" + assert_output --partial "bar" + assert_success } @test "Generate and test filter-map - (current repo fluvio-smartmodule / no params)" { From bba2142a38b4b7f0fb83837097ac31101d293a07 Mon Sep 17 00:00:00 2001 From: Tan Date: Mon, 8 May 2023 17:31:11 +0700 Subject: [PATCH 3/5] Update smdk-basic.bats refute_output without verbose --- tests/cli/smdk_smoke_tests/smdk-basic.bats | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/tests/cli/smdk_smoke_tests/smdk-basic.bats b/tests/cli/smdk_smoke_tests/smdk-basic.bats index 0dada51de3..0702736116 100644 --- a/tests/cli/smdk_smoke_tests/smdk-basic.bats +++ b/tests/cli/smdk_smoke_tests/smdk-basic.bats @@ -200,7 +200,8 @@ setup_file() { assert_success # Test without verbose - run $SMDK_BIN test --text '["foo", "bar"]' + run $SMDK_BIN test --text '["foo", "bar"]' + refute_output --partial "2 records outputed" assert_output --partial "foo" assert_output --partial "bar" assert_success @@ -244,7 +245,7 @@ setup_file() { # Test run $SMDK_BIN test --verbose --text '2' assert_output --partial "1 records outputed" - assert_output --partial "2" + assert_output --partial "1" assert_success } @@ -596,7 +597,8 @@ setup_file() { assert_success # Test with without verbose - run $SMDK_BIN test --text '["foo", "bar"]' + run $SMDK_BIN test --text '["foo", "bar"]' + refute_output --partial "2 records outputed" assert_output --partial "foo" assert_output --partial "bar" assert_success @@ -639,7 +641,7 @@ setup_file() { # Test run $SMDK_BIN test --verbose --text '2' assert_output --partial "1 records outputed" - assert_output --partial "2" + assert_output --partial "1" assert_success } From be6620c2da115bbd6036fbb282e224db0d22c2aa Mon Sep 17 00:00:00 2001 From: TanNgocDo Date: Mon, 8 May 2023 23:53:05 +0700 Subject: [PATCH 4/5] Update crates/smartmodule-development-kit/src/test.rs Co-authored-by: morenol <22335041+morenol@users.noreply.github.com> --- crates/smartmodule-development-kit/src/test.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/smartmodule-development-kit/src/test.rs b/crates/smartmodule-development-kit/src/test.rs index 0ed1e4695e..9fd058a9e6 100644 --- a/crates/smartmodule-development-kit/src/test.rs +++ b/crates/smartmodule-development-kit/src/test.rs @@ -68,7 +68,7 @@ pub struct TestCmd { transform: Vec, /// verbose output - #[clap(short = 'v', long = "verbose")] + #[arg(short = 'v', long = "verbose")] verbose: bool, } From 682cd51e466a9cfb5eacbc633a4882284f58f038 Mon Sep 17 00:00:00 2001 From: Tan Date: Tue, 9 May 2023 11:26:31 +0700 Subject: [PATCH 5/5] Update main.rs minor change debug format --- crates/smartmodule-development-kit/src/main.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/crates/smartmodule-development-kit/src/main.rs b/crates/smartmodule-development-kit/src/main.rs index 448fdb0e95..2ea241133f 100644 --- a/crates/smartmodule-development-kit/src/main.rs +++ b/crates/smartmodule-development-kit/src/main.rs @@ -8,6 +8,7 @@ mod hub; mod set_public; use std::path::{PathBuf}; + use clap::Parser; use anyhow::Result; use tracing::debug; @@ -24,6 +25,6 @@ fn main() -> Result<()> { } pub(crate) fn read_bytes_from_path(path: &PathBuf) -> Result> { - debug!("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)) }