Skip to content

Commit 352f796

Browse files
committed
test: Add tests for the form encoding
It only tests a single value right now using httpbin but I have seen multiple work just as fine
1 parent 621104e commit 352f796

File tree

1 file changed

+65
-0
lines changed

1 file changed

+65
-0
lines changed

test/sql/httpclient.test

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,3 +134,68 @@ FROM
134134
;
135135
----
136136
S2A_56LPN_20210930_0_L2A
137+
138+
# Confirm the POST function with form request works
139+
query III
140+
WITH __input AS (
141+
SELECT
142+
http_post_form(
143+
'https://httpbin.org/delay/0',
144+
headers => MAP {
145+
'accept': 'application/json',
146+
},
147+
params => MAP {
148+
'limit': 10
149+
}
150+
) AS res
151+
),
152+
__response AS (
153+
SELECT
154+
(res->>'status')::INT AS status,
155+
(res->>'reason') AS reason,
156+
unnest( from_json(((res->>'body')::JSON)->'headers', '{"Host": "VARCHAR"}') ) AS features
157+
FROM
158+
__input
159+
)
160+
SELECT
161+
__response.status,
162+
__response.reason,
163+
__response.Host AS host
164+
FROM
165+
__response
166+
;
167+
----
168+
200 OK httpbin.org
169+
170+
# Confirm the POST function with form encoding transmits a single value
171+
query III
172+
WITH __input AS (
173+
SELECT
174+
http_post_form(
175+
'https://httpbin.org/delay/0',
176+
headers => MAP {
177+
'accept': 'application/json',
178+
},
179+
params => MAP {
180+
'limit': 10
181+
}
182+
) AS res
183+
),
184+
__response AS (
185+
SELECT
186+
(res->>'status')::INT AS status,
187+
(res->>'reason') AS reason,
188+
unnest( from_json(((res->>'body')::JSON)->'form', '{"limit": "VARCHAR"}') ) AS features
189+
FROM
190+
__input
191+
)
192+
SELECT
193+
__response.status,
194+
__response.reason,
195+
__response.limit AS limit
196+
FROM
197+
__response
198+
;
199+
----
200+
200 OK 10
201+

0 commit comments

Comments
 (0)