From e8e75251b4d1b769edf34fcc5f988bcf66aa5e6c Mon Sep 17 00:00:00 2001 From: yuyi Date: Sun, 13 Nov 2022 16:57:35 +0800 Subject: [PATCH] vweb: change optional to result in vweb_test (#16412) --- vlib/vweb/tests/vweb_test.v | 40 +++++++++++++++--------------- vlib/vweb/tests/vweb_test_server.v | 2 +- 2 files changed, 21 insertions(+), 21 deletions(-) diff --git a/vlib/vweb/tests/vweb_test.v b/vlib/vweb/tests/vweb_test.v index dbf3e5d42f..077c6b300d 100644 --- a/vlib/vweb/tests/vweb_test.v +++ b/vlib/vweb/tests/vweb_test.v @@ -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 == '

ok

' } 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') } diff --git a/vlib/vweb/tests/vweb_test_server.v b/vlib/vweb/tests/vweb_test_server.v index d33b14a2dc..e84d65ef7e 100644 --- a/vlib/vweb/tests/vweb_test_server.v +++ b/vlib/vweb/tests/vweb_test_server.v @@ -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() {