From b80b3117fba2716bc569b302e00ed5b771077a21 Mon Sep 17 00:00:00 2001 From: Daniela Date: Wed, 27 Mar 2024 01:21:21 -0300 Subject: [PATCH] feat: Adds a test section for URL parameters --- .gitignore | 3 +++ README.md | 2 +- crates/http-sink/config-example.yaml | 4 ++++ crates/tiny-http-server/src/main.rs | 3 +++ tests/integration-sends-data-via-post.bats | 19 +++++++++++++++++++ 5 files changed, 30 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 83858b2..c4930ab 100644 --- a/.gitignore +++ b/.gitignore @@ -13,4 +13,7 @@ hub/** # Development log.txt +*-logs.txt +*.log + development-config.yml diff --git a/README.md b/README.md index cf21946..0424c7c 100644 --- a/README.md +++ b/README.md @@ -73,7 +73,7 @@ We could write a url_parameter containing the following information: This would be the ending result: ```md -https://someurl.com?updatecondition=user_id%20%3D%202901 +https://someurl.com?updatecondition=user_id+%3D+2901 ``` diff --git a/crates/http-sink/config-example.yaml b/crates/http-sink/config-example.yaml index 7f94a5c..c5521a1 100644 --- a/crates/http-sink/config-example.yaml +++ b/crates/http-sink/config-example.yaml @@ -7,3 +7,7 @@ http: endpoint: "https://httpbin.org/post" http_request_timeout: 1s http_connect_timeout: 15s + url_parameters: + - record_key: id + url_key: sql_condition + prefix: "user_id = " diff --git a/crates/tiny-http-server/src/main.rs b/crates/tiny-http-server/src/main.rs index 482d2da..50d8a1d 100644 --- a/crates/tiny-http-server/src/main.rs +++ b/crates/tiny-http-server/src/main.rs @@ -12,6 +12,8 @@ pub struct RequestData { payload: String, #[allow(dead_code)] user_agent: String, + #[allow(dead_code)] + url: String, } #[derive(Clone, Debug, Default)] @@ -91,6 +93,7 @@ fn main() { let data = RequestData { payload: content.clone(), user_agent: user_agent.map(|h| h.value.to_string()).unwrap_or_default(), + url: request.url().to_string() }; state.append_payload(data); diff --git a/tests/integration-sends-data-via-post.bats b/tests/integration-sends-data-via-post.bats index 0394206..d7d04db 100644 --- a/tests/integration-sends-data-via-post.bats +++ b/tests/integration-sends-data-via-post.bats @@ -34,6 +34,25 @@ teardown() { kill $MOCK_PID } + +@test "url_parameter" { + echo "Starting consumer on topic $TOPIC" + echo "Using connector $CONNECTOR" + sleep 45 + + echo "Produce \"{\"id\": 2901, \"name\": \"Luiz Barros Rocha\", \"age\": 26}\" on $TOPIC" + echo "{\"id\": 2901, \"name\": \"Luiz Barros Rocha\", \"age\": 26}" | fluvio produce $TOPIC + + echo "Sleep to ensure record is processed" + sleep 25 + + echo "" + + cat ./$LOGGER_FILENAME | grep "url: \"/?condition=user_id+%3D+2901&age=26+years\"" + assert_success +} + + @test "integration-sends-data-via-post" { echo "Starting consumer on topic $TOPIC" echo "Using connector $CONNECTOR"