Skip to content

Commit

Permalink
tests: correct fetchpost --payload-tpl tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jqnatividad committed Nov 4, 2024
1 parent 5aca917 commit 04b2510
Showing 1 changed file with 15 additions and 64 deletions.
79 changes: 15 additions & 64 deletions tests/test_fetch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Vec<String>> = wrk.read_stdout(&mut cmd);
Expand All @@ -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]
Expand Down Expand Up @@ -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");
Expand All @@ -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<Vec<String>> = 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]
Expand Down

0 comments on commit 04b2510

Please sign in to comment.