mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
vfmt: shorten main.const_name
to just const_name
This commit is contained in:
@ -18,18 +18,18 @@ const (
|
||||
|
||||
// setup of vweb webserver
|
||||
fn testsuite_begin() {
|
||||
os.chdir(main.vroot)
|
||||
if os.exists(main.serverexe) {
|
||||
os.rm(main.serverexe)
|
||||
os.chdir(vroot)
|
||||
if os.exists(serverexe) {
|
||||
os.rm(serverexe)
|
||||
}
|
||||
}
|
||||
|
||||
fn test_a_simple_vweb_app_can_be_compiled() {
|
||||
// did_server_compile := os.system('$vexe -g -o $serverexe vlib/vweb/tests/vweb_test_server.v')
|
||||
// TODO: find out why it does not compile with -usecache and -g
|
||||
did_server_compile := os.system('$main.vexe -o $main.serverexe vlib/vweb/tests/vweb_test_server.v')
|
||||
did_server_compile := os.system('$vexe -o $serverexe vlib/vweb/tests/vweb_test_server.v')
|
||||
assert did_server_compile == 0
|
||||
assert os.exists(main.serverexe)
|
||||
assert os.exists(serverexe)
|
||||
}
|
||||
|
||||
fn test_a_simple_vweb_app_runs_in_the_background() {
|
||||
@ -37,10 +37,10 @@ fn test_a_simple_vweb_app_runs_in_the_background() {
|
||||
$if !windows {
|
||||
suffix = ' > /dev/null &'
|
||||
}
|
||||
if main.vweb_logfile != '' {
|
||||
suffix = ' 2>> $main.vweb_logfile >> $main.vweb_logfile &'
|
||||
if vweb_logfile != '' {
|
||||
suffix = ' 2>> $vweb_logfile >> $vweb_logfile &'
|
||||
}
|
||||
server_exec_cmd := '$main.serverexe $main.sport $main.exit_after_time $suffix'
|
||||
server_exec_cmd := '$serverexe $sport $exit_after_time $suffix'
|
||||
$if debug_net_socket_client ? {
|
||||
eprintln('running:\n$server_exec_cmd')
|
||||
}
|
||||
@ -102,14 +102,14 @@ fn assert_common_http_headers(x http.Response) {
|
||||
}
|
||||
|
||||
fn test_http_client_index() {
|
||||
x := http.get('http://127.0.0.1:$main.sport/') or { panic(err) }
|
||||
x := http.get('http://127.0.0.1:$sport/') or { panic(err) }
|
||||
assert_common_http_headers(x)
|
||||
assert x.headers['Content-Type'] == 'text/plain'
|
||||
assert x.text == 'Welcome to VWeb'
|
||||
}
|
||||
|
||||
fn test_http_client_chunk_transfer() {
|
||||
x := http.get('http://127.0.0.1:$main.sport/chunk') or { panic(err) }
|
||||
x := http.get('http://127.0.0.1:$sport/chunk') or { panic(err) }
|
||||
assert_common_http_headers(x)
|
||||
assert x.headers['Transfer-Encoding'] == 'chunked'
|
||||
assert x.text == 'Lorem ipsum dolor sit amet, consetetur sadipscing'
|
||||
@ -117,9 +117,9 @@ fn test_http_client_chunk_transfer() {
|
||||
|
||||
fn test_http_client_404() {
|
||||
url_404_list := [
|
||||
'http://127.0.0.1:$main.sport/zxcnbnm',
|
||||
'http://127.0.0.1:$main.sport/JHKAJA',
|
||||
'http://127.0.0.1:$main.sport/unknown',
|
||||
'http://127.0.0.1:$sport/zxcnbnm',
|
||||
'http://127.0.0.1:$sport/JHKAJA',
|
||||
'http://127.0.0.1:$sport/unknown',
|
||||
]
|
||||
for url in url_404_list {
|
||||
res := http.get(url) or { panic(err) }
|
||||
@ -128,39 +128,39 @@ fn test_http_client_404() {
|
||||
}
|
||||
|
||||
fn test_http_client_simple() {
|
||||
x := http.get('http://127.0.0.1:$main.sport/simple') or { panic(err) }
|
||||
x := http.get('http://127.0.0.1:$sport/simple') or { panic(err) }
|
||||
assert_common_http_headers(x)
|
||||
assert x.headers['Content-Type'] == 'text/plain'
|
||||
assert x.text == 'A simple result'
|
||||
}
|
||||
|
||||
fn test_http_client_html_page() {
|
||||
x := http.get('http://127.0.0.1:$main.sport/html_page') or { panic(err) }
|
||||
x := http.get('http://127.0.0.1:$sport/html_page') or { panic(err) }
|
||||
assert_common_http_headers(x)
|
||||
assert x.headers['Content-Type'] == 'text/html'
|
||||
assert x.text == '<h1>ok</h1>'
|
||||
}
|
||||
|
||||
fn test_http_client_settings_page() {
|
||||
x := http.get('http://127.0.0.1:$main.sport/bilbo/settings') or { panic(err) }
|
||||
x := http.get('http://127.0.0.1:$sport/bilbo/settings') or { panic(err) }
|
||||
assert_common_http_headers(x)
|
||||
assert x.text == 'username: bilbo'
|
||||
//
|
||||
y := http.get('http://127.0.0.1:$main.sport/kent/settings') or { panic(err) }
|
||||
y := http.get('http://127.0.0.1:$sport/kent/settings') or { panic(err) }
|
||||
assert_common_http_headers(y)
|
||||
assert y.text == 'username: kent'
|
||||
}
|
||||
|
||||
fn test_http_client_user_repo_settings_page() {
|
||||
x := http.get('http://127.0.0.1:$main.sport/bilbo/gostamp/settings') or { panic(err) }
|
||||
x := http.get('http://127.0.0.1:$sport/bilbo/gostamp/settings') or { panic(err) }
|
||||
assert_common_http_headers(x)
|
||||
assert x.text == 'username: bilbo | repository: gostamp'
|
||||
//
|
||||
y := http.get('http://127.0.0.1:$main.sport/kent/golang/settings') or { panic(err) }
|
||||
y := http.get('http://127.0.0.1:$sport/kent/golang/settings') or { panic(err) }
|
||||
assert_common_http_headers(y)
|
||||
assert y.text == 'username: kent | repository: golang'
|
||||
//
|
||||
z := http.get('http://127.0.0.1:$main.sport/missing/golang/settings') or { panic(err) }
|
||||
z := http.get('http://127.0.0.1:$sport/missing/golang/settings') or { panic(err) }
|
||||
assert z.status_code == 404
|
||||
}
|
||||
|
||||
@ -175,9 +175,7 @@ fn test_http_client_json_post() {
|
||||
age: 123
|
||||
}
|
||||
json_for_ouser := json.encode(ouser)
|
||||
mut x := http.post_json('http://127.0.0.1:$main.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 ? {
|
||||
eprintln('/json_echo endpoint response: $x')
|
||||
}
|
||||
@ -186,7 +184,7 @@ fn test_http_client_json_post() {
|
||||
nuser := json.decode(User, x.text) or { User{} }
|
||||
assert '$ouser' == '$nuser'
|
||||
//
|
||||
x = http.post_json('http://127.0.0.1:$main.sport/json', json_for_ouser) or { panic(err) }
|
||||
x = http.post_json('http://127.0.0.1:$sport/json', json_for_ouser) or { panic(err) }
|
||||
$if debug_net_socket_client ? {
|
||||
eprintln('/json endpoint response: $x')
|
||||
}
|
||||
@ -197,7 +195,7 @@ fn test_http_client_json_post() {
|
||||
}
|
||||
|
||||
fn test_http_client_shutdown_does_not_work_without_a_cookie() {
|
||||
x := http.get('http://127.0.0.1:$main.sport/shutdown') or {
|
||||
x := http.get('http://127.0.0.1:$sport/shutdown') or {
|
||||
assert err == ''
|
||||
return
|
||||
}
|
||||
@ -208,7 +206,7 @@ fn test_http_client_shutdown_does_not_work_without_a_cookie() {
|
||||
fn testsuite_end() {
|
||||
// This test is guaranteed to be called last.
|
||||
// It sends a request to the server to shutdown.
|
||||
x := http.fetch('http://127.0.0.1:$main.sport/shutdown',
|
||||
x := http.fetch('http://127.0.0.1:$sport/shutdown',
|
||||
method: .get
|
||||
cookies: {
|
||||
'skey': 'superman'
|
||||
@ -236,7 +234,7 @@ fn simple_tcp_client(config SimpleTcpClientConfig) ?string {
|
||||
mut tries := 0
|
||||
for tries < config.retries {
|
||||
tries++
|
||||
client = net.dial_tcp('127.0.0.1:$main.sport') or {
|
||||
client = net.dial_tcp('127.0.0.1:$sport') or {
|
||||
if tries > config.retries {
|
||||
return error(err)
|
||||
}
|
||||
@ -245,8 +243,8 @@ fn simple_tcp_client(config SimpleTcpClientConfig) ?string {
|
||||
}
|
||||
break
|
||||
}
|
||||
client.set_read_timeout(main.tcp_r_timeout)
|
||||
client.set_write_timeout(main.tcp_w_timeout)
|
||||
client.set_read_timeout(tcp_r_timeout)
|
||||
client.set_write_timeout(tcp_w_timeout)
|
||||
defer {
|
||||
client.close()
|
||||
}
|
||||
|
Reference in New Issue
Block a user