MCPcopy Create free account
hub / github.com/MaterializeInc/materialize / test_double_encoded_json

Function test_double_encoded_json

src/environmentd/tests/server.rs:4721–4825  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

4719#[cfg_attr(miri, ignore)] // too slow
4720#[allow(clippy::disallowed_methods)]
4721async fn test_double_encoded_json() {
4722 let server = test_util::TestHarness::default().start().await;
4723 let client = server.connect().await.expect("success");
4724
4725 client
4726 .execute("CREATE TABLE t1 (a jsonb)", &[])
4727 .await
4728 .unwrap();
4729 client
4730 .execute("GRANT ALL PRIVILEGES ON TABLE t1 TO PUBLIC", &[])
4731 .await
4732 .unwrap();
4733
4734 client
4735 .execute(r#"INSERT INTO t1 VALUES ('{ "type": "foo" }')"#, &[])
4736 .await
4737 .unwrap();
4738 client
4739 .execute(
4740 r#"INSERT INTO t1 VALUES ('" { \"type\": \"foo\" } "')"#,
4741 &[],
4742 )
4743 .await
4744 .unwrap();
4745
4746 let http_client = reqwest::Client::new();
4747 let http_url = Url::parse(&format!("http://{}/api/sql", server.http_local_addr(),)).unwrap();
4748 let query = serde_json::json!({
4749 "query": "SELECT a FROM t1 ORDER BY a"
4750 });
4751
4752 let result: serde_json::Value = http_client
4753 .post(http_url)
4754 .json(&query)
4755 .send()
4756 .await
4757 .expect("failed to send SQL")
4758 .json()
4759 .await
4760 .expect("invalid JSON");
4761 let rows = result
4762 .as_object()
4763 .unwrap()
4764 .get("results")
4765 .unwrap()
4766 .as_array()
4767 .unwrap()
4768 .get(0)
4769 .unwrap()
4770 .as_object()
4771 .unwrap()
4772 .get("rows")
4773 .unwrap();
4774
4775 insta::assert_debug_snapshot!(rows, @r###"
4776 Array [
4777 Array [
4778 String(" { \"type\": \"foo\" } "),

Callers

nothing calls this directly

Calls 15

auth_with_wsFunction · 0.85
TextClass · 0.85
expectMethod · 0.80
unwrapMethod · 0.80
ws_addrMethod · 0.80
parseFunction · 0.50
connectFunction · 0.50
startMethod · 0.45
connectMethod · 0.45
executeMethod · 0.45
jsonMethod · 0.45
sendMethod · 0.45

Tested by

no test coverage detected