mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
vweb: change optional to result in vweb_test (#16412)
This commit is contained in:
parent
b54f9c2949
commit
e8e75251b4
@ -109,17 +109,17 @@ fn test_a_simple_tcp_client_html_page() {
|
||||
}
|
||||
|
||||
// net.http client based tests follow:
|
||||
fn assert_common_http_headers(x http.Response) ? {
|
||||
fn assert_common_http_headers(x http.Response) ! {
|
||||
assert x.status() == .ok
|
||||
assert x.header.get(.server)? == 'VWeb'
|
||||
assert x.header.get(.content_length)?.int() > 0
|
||||
assert x.header.get(.connection)? == 'close'
|
||||
assert x.header.get(.server)! == 'VWeb'
|
||||
assert x.header.get(.content_length)!.int() > 0
|
||||
assert x.header.get(.connection)! == 'close'
|
||||
}
|
||||
|
||||
fn test_http_client_index() {
|
||||
x := http.get('http://$localserver/') or { panic(err) }
|
||||
assert_common_http_headers(x)?
|
||||
assert x.header.get(.content_type)? == 'text/plain'
|
||||
assert_common_http_headers(x)!
|
||||
assert x.header.get(.content_type)! == 'text/plain'
|
||||
assert x.body == 'Welcome to VWeb'
|
||||
}
|
||||
|
||||
@ -137,35 +137,35 @@ fn test_http_client_404() {
|
||||
|
||||
fn test_http_client_simple() {
|
||||
x := http.get('http://$localserver/simple') or { panic(err) }
|
||||
assert_common_http_headers(x)?
|
||||
assert x.header.get(.content_type)? == 'text/plain'
|
||||
assert_common_http_headers(x)!
|
||||
assert x.header.get(.content_type)! == 'text/plain'
|
||||
assert x.body == 'A simple result'
|
||||
}
|
||||
|
||||
fn test_http_client_html_page() {
|
||||
x := http.get('http://$localserver/html_page') or { panic(err) }
|
||||
assert_common_http_headers(x)?
|
||||
assert x.header.get(.content_type)? == 'text/html'
|
||||
assert_common_http_headers(x)!
|
||||
assert x.header.get(.content_type)! == 'text/html'
|
||||
assert x.body == '<h1>ok</h1>'
|
||||
}
|
||||
|
||||
fn test_http_client_settings_page() {
|
||||
x := http.get('http://$localserver/bilbo/settings') or { panic(err) }
|
||||
assert_common_http_headers(x)?
|
||||
assert_common_http_headers(x)!
|
||||
assert x.body == 'username: bilbo'
|
||||
//
|
||||
y := http.get('http://$localserver/kent/settings') or { panic(err) }
|
||||
assert_common_http_headers(y)?
|
||||
assert_common_http_headers(y)!
|
||||
assert y.body == 'username: kent'
|
||||
}
|
||||
|
||||
fn test_http_client_user_repo_settings_page() {
|
||||
x := http.get('http://$localserver/bilbo/gostamp/settings') or { panic(err) }
|
||||
assert_common_http_headers(x)?
|
||||
assert_common_http_headers(x)!
|
||||
assert x.body == 'username: bilbo | repository: gostamp'
|
||||
//
|
||||
y := http.get('http://$localserver/kent/golang/settings') or { panic(err) }
|
||||
assert_common_http_headers(y)?
|
||||
assert_common_http_headers(y)!
|
||||
assert y.body == 'username: kent | repository: golang'
|
||||
//
|
||||
z := http.get('http://$localserver/missing/golang/settings') or { panic(err) }
|
||||
@ -187,7 +187,7 @@ fn test_http_client_json_post() {
|
||||
$if debug_net_socket_client ? {
|
||||
eprintln('/json_echo endpoint response: $x')
|
||||
}
|
||||
assert x.header.get(.content_type)? == 'application/json'
|
||||
assert x.header.get(.content_type)! == 'application/json'
|
||||
assert x.body == json_for_ouser
|
||||
nuser := json.decode(User, x.body) or { User{} }
|
||||
assert '$ouser' == '$nuser'
|
||||
@ -196,7 +196,7 @@ fn test_http_client_json_post() {
|
||||
$if debug_net_socket_client ? {
|
||||
eprintln('/json endpoint response: $x')
|
||||
}
|
||||
assert x.header.get(.content_type)? == 'application/json'
|
||||
assert x.header.get(.content_type)! == 'application/json'
|
||||
assert x.body == json_for_ouser
|
||||
nuser2 := json.decode(User, x.body) or { User{} }
|
||||
assert '$ouser' == '$nuser2'
|
||||
@ -221,7 +221,7 @@ $contents\r
|
||||
value: ct
|
||||
)
|
||||
data: data
|
||||
)?
|
||||
)!
|
||||
$if debug_net_socket_client ? {
|
||||
eprintln('/form_echo endpoint response: $x')
|
||||
}
|
||||
@ -264,7 +264,7 @@ struct SimpleTcpClientConfig {
|
||||
content string
|
||||
}
|
||||
|
||||
fn simple_tcp_client(config SimpleTcpClientConfig) ?string {
|
||||
fn simple_tcp_client(config SimpleTcpClientConfig) !string {
|
||||
mut client := &net.TcpConn(0)
|
||||
mut tries := 0
|
||||
for tries < config.retries {
|
||||
@ -297,8 +297,8 @@ $config.content'
|
||||
$if debug_net_socket_client ? {
|
||||
eprintln('sending:\n$message')
|
||||
}
|
||||
client.write(message.bytes())?
|
||||
read := io.read_all(reader: client)?
|
||||
client.write(message.bytes())!
|
||||
read := io.read_all(reader: client)!
|
||||
$if debug_net_socket_client ? {
|
||||
eprintln('received:\n$read')
|
||||
}
|
||||
|
@ -44,7 +44,7 @@ fn main() {
|
||||
global_config: config
|
||||
}
|
||||
eprintln('>> webserver: pid: $os.getpid(), started on http://localhost:$app.port/ , with maximum runtime of $app.timeout milliseconds.')
|
||||
vweb.run_at(app, host: 'localhost', port: http_port, family: .ip)?
|
||||
vweb.run_at(app, host: 'localhost', port: http_port, family: .ip)!
|
||||
}
|
||||
|
||||
// pub fn (mut app App) init_server() {
|
||||
|
Loading…
Reference in New Issue
Block a user