mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
vweb: add [post] test
This commit is contained in:
parent
0a069dee79
commit
7496c74f7e
@ -159,7 +159,7 @@ fn test_http_client_json_post() {
|
|||||||
age: 123
|
age: 123
|
||||||
}
|
}
|
||||||
json_for_ouser := json.encode(ouser)
|
json_for_ouser := json.encode(ouser)
|
||||||
x := http.post_json('http://127.0.0.1:$sport/json_echo', json_for_ouser) or { panic(err) }
|
mut x := http.post_json('http://127.0.0.1:$sport/json_echo', json_for_ouser) or { panic(err) }
|
||||||
$if debug_net_socket_client ? {
|
$if debug_net_socket_client ? {
|
||||||
eprintln('json response: $x')
|
eprintln('json response: $x')
|
||||||
}
|
}
|
||||||
@ -167,6 +167,15 @@ fn test_http_client_json_post() {
|
|||||||
assert x.text == json_for_ouser
|
assert x.text == json_for_ouser
|
||||||
nuser := json.decode(User, x.text) or { User{} }
|
nuser := json.decode(User, x.text) or { User{} }
|
||||||
assert '$ouser' == '$nuser'
|
assert '$ouser' == '$nuser'
|
||||||
|
//
|
||||||
|
x = http.post_json('http://127.0.0.1:$sport/json', json_for_ouser) or { panic(err) }
|
||||||
|
$if debug_net_socket_client ? {
|
||||||
|
eprintln('json response: $x')
|
||||||
|
}
|
||||||
|
assert x.headers['Content-Type'] == 'application/json'
|
||||||
|
assert x.text == json_for_ouser
|
||||||
|
nuser2 := json.decode(User, x.text) or { User{} }
|
||||||
|
assert '$ouser' == '$nuser2'
|
||||||
}
|
}
|
||||||
|
|
||||||
fn test_http_client_shutdown_does_not_work_without_a_cookie() {
|
fn test_http_client_shutdown_does_not_work_without_a_cookie() {
|
||||||
|
@ -79,6 +79,13 @@ pub fn (mut app App) user_repo_settings(username string, repository string) vweb
|
|||||||
|
|
||||||
[post]
|
[post]
|
||||||
['/json_echo']
|
['/json_echo']
|
||||||
|
pub fn (mut app App) json_echo() vweb.Result {
|
||||||
|
app.set_content_type(app.req.headers['Content-Type'])
|
||||||
|
return app.ok(app.req.data)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Make sure [post] works without the path
|
||||||
|
[post]
|
||||||
pub fn (mut app App) json() vweb.Result {
|
pub fn (mut app App) json() vweb.Result {
|
||||||
app.set_content_type(app.req.headers['Content-Type'])
|
app.set_content_type(app.req.headers['Content-Type'])
|
||||||
return app.ok(app.req.data)
|
return app.ok(app.req.data)
|
||||||
|
Loading…
Reference in New Issue
Block a user