From 04b251097e06e8052631a973baeaddc9f427c3b2 Mon Sep 17 00:00:00 2001 From: Joel Natividad <1980690+jqnatividad@users.noreply.github.com> Date: Mon, 4 Nov 2024 00:22:58 -0500 Subject: [PATCH] tests: correct `fetchpost --payload-tpl` tests --- tests/test_fetch.rs | 79 +++++++++------------------------------------ 1 file changed, 15 insertions(+), 64 deletions(-) diff --git a/tests/test_fetch.rs b/tests/test_fetch.rs index 256572994..fcecea88f 100644 --- a/tests/test_fetch.rs +++ b/tests/test_fetch.rs @@ -1544,6 +1544,8 @@ fn fetchpost_payload_template() { .arg("payload.tpl") .arg("--new-column") .arg("response") + .arg("--jaq") + .arg(r#"."data""#) .arg("data.csv"); let got: Vec> = wrk.read_stdout(&mut cmd); @@ -1555,34 +1557,25 @@ fn fetchpost_payload_template() { "Smith", "35", "New York", - r#"{"args":{},"data":"firstName=John&lastName=Smith&age=35&city=New+York","files":{},"form":{},"headers"# + r#""{"firstName":"John","lastName":"Smith","age":35,"city":"New York"}""# ], svec![ "Jane", "Doe", "28", "Los Angeles", - r#"{"args":{},"data":"firstName=Jane&lastName=Doe&age=28&city=Los+Angeles","files":{},"form":{},"header"# + r#""{"firstName":"Jane","lastName":"Doe","age":28,"city":"Los Angeles"}""# ], svec![ "Bob", "Jones", "42", "Chicago", - r#"{"args":{},"data":"firstName=Bob&lastName=Jones&age=42&city=Chicago","files":{},"form":{},"headers":"# + r#""{"firstName":"Bob","lastName":"Jones","age":42,"city":"Chicago"}""# ], ]; - for (got_row, expected_row) in got.iter().skip(1).zip(expected.iter().skip(1)) { - // Assert first 4 columns match - assert_eq!(&got_row[..4], &expected_row[..4]); - // Assert the first 100 characters of response column match - assert_eq!( - &got_row[4][..100], - &expected_row[4][..100], - "Response column first 100 chars mismatch" - ); - } + assert_eq!(got, expected); } #[test] @@ -1615,6 +1608,8 @@ fn fetchpost_payload_template_with_report() { .arg("payload.tpl") .arg("--new-column") .arg("response") + .arg("--jaq") + .arg(r#"."data""#) .arg("--report") .arg("short") .arg("data.csv"); @@ -1628,72 +1623,28 @@ fn fetchpost_payload_template_with_report() { "Smith", "35", "New York", - r#"{"args":{},"data":"firstName=John&lastName=Smith&age=35&city=New+York","files":{},"form":{},"headers"# + r#""{"firstName":"John","lastName":"Smith","age":35,"city":"New York"}""# ], svec![ - "Janet", + "Jane", "Doe", "28", "Los Angeles", - r#"{"args":{},"data":"","files":{},"form":{"age":"28","city":"Los Angeles","firstName":"Jane","lastName":"Doe"},"headers":{"Accept":"*/*","Accept-Encoding":"zstd;q=1.0, br;q=0.8, gzip;q=0.6, deflate;q=0.4, *;q=0.2","Content-Length":"51","Content-Type":"application/x-www-form-urlencoded","Host":"httpbin.org","User-Agent":"qsv/0.137.0 (aarch64-apple-darwin; fetchpost; compiled; https://github.com/jqnatividad/qsv)","X-Amzn-Trace-Id":"Root=1-6727a9d5-47c9d7ed1247562762fdd379"},"json":null,"origin":"149.88.100.35","url":"https://httpbin.org/post"}"# + r#""{"firstName":"Jane","lastName":"Doe","age":28,"city":"Los Angeles"}""# ], svec![ "Bob", "Jones", "42", "Chicago", - r#"{"args":{},"data":"","files":{},"form":{"age":"42","city":"Chicago","firstName":"Bob","lastName":"Jones"},"headers":{"Accept":"*/*","Accept-Encoding":"zstd;q=1.0, br;q=0.8, gzip;q=0.6, deflate;q=0.4, *;q=0.2","Content-Length":"48","Content-Type":"application/x-www-form-urlencoded","Host":"httpbin.org","User-Agent":"qsv/0.137.0 (aarch64-apple-darwin; fetchpost; compiled; https://github.com/jqnatividad/qsv)","X-Amzn-Trace-Id":"Root=1-6727a9d5-784c0cdf4d78bf1257f9a4d4"},"json":null,"origin":"149.88.100.35","url":"https://httpbin.org/post"}"# + r#""{"firstName":"Bob","lastName":"Jones","age":42,"city":"Chicago"}""# ], ]; - for (got_row, expected_row) in got.iter().skip(1).zip(expected.iter().skip(1)) { - // Assert first 4 columns match - assert_eq!(&got_row[..4], &expected_row[..4]); - // Assert the first 100 characters of response column match - assert_eq!( - &got_row[4][..100], - &expected_row[4][..100], - "Response column first 100 chars mismatch" - ); - } - - let mut cmd = wrk.command("select"); - cmd.arg("url,form,status,cache_hit,retries,response") - .arg(wrk.load_test_file("data.csv.fetchpost-report.tsv")); - - let got: Vec> = wrk.read_stdout(&mut cmd); - - let expected = vec![ - svec!["url", "form", "status", "cache_hit", "retries", "response"], - svec![ - "https://httpbin.org/post", - "{\"bool_col\": String(\"true\"), \"col1\": String(\"a\"), \"number_col\": \ - String(\"42\")}", - "200", - "0", - "0", - r#"{"bool_col": String("true"), "col1": String("a"), "number_col": String("42")}"# - ], - svec![ - "https://httpbin.org/post", - "{\"bool_col\": String(\"false\"), \"col1\": String(\"b\"), \"number_col\": \ - String(\"3.14\")}", - "200", - "0", - "0", - r#"{"bool_col": String("false"), "col1": String("b"), "number_col": String("3.14")}"# - ], - svec![ - "https://httpbin.org/post", - "{\"bool_col\": String(\"true\"), \"col1\": String(\"c\"), \"number_col\": \ - String(\"666\")}", - "200", - "0", - "0", - r#"{"bool_col": String("true"), "col1": String("c"), "number_col": String("666")}"# - ], - ]; assert_eq!(got, expected); + + let report = wrk.read_to_string("data.csv.fetchpost-report.tsv"); + assert!(!report.is_empty()); } #[test]