1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

vweb: add an overridable .not_found() method, for making a custom 404 page + tests fixes (#17936)

This commit is contained in:
Casper Kuethe
2023-04-11 23:50:03 +02:00
committed by GitHub
parent f9c186a400
commit 838083e610
7 changed files with 58 additions and 16 deletions

View File

@@ -1,9 +1,6 @@
import os
import time
import json
import net
import net.http
import io
const (
sport = 12382
@@ -91,6 +88,21 @@ fn test_other_path() {
assert x.body == 'Other path'
}
fn test_different_404() {
res_app := http.get('http://${localserver}/zxcnbnm') or { panic(err) }
assert res_app.status() == .not_found
assert res_app.body == '404 From App'
res_admin := http.get('http://${localserver}/admin/JHKAJA') or { panic(err) }
assert res_admin.status() == .not_found
assert res_admin.body == '404 From Admin'
// Other doesn't have a custom 404 so the vweb.Context's not_found is expected
res_other := http.get('http://${localserver}/other/unknown') or { panic(err) }
assert res_other.status() == .not_found
assert res_other.body == '404 Not Found'
}
fn test_shutdown() {
// This test is guaranteed to be called last.
// It sends a request to the server to shutdown.