aboutsummaryrefslogtreecommitdiff
path: root/v_windows/v/vlib/net/http/response_test.v
diff options
context:
space:
mode:
authorIndrajith K L2022-12-03 17:00:20 +0530
committerIndrajith K L2022-12-03 17:00:20 +0530
commitf5c4671bfbad96bf346bd7e9a21fc4317b4959df (patch)
tree2764fc62da58f2ba8da7ed341643fc359873142f /v_windows/v/vlib/net/http/response_test.v
downloadcli-tools-windows-master.tar.gz
cli-tools-windows-master.tar.bz2
cli-tools-windows-master.zip
Adds most of the toolsHEADmaster
Diffstat (limited to 'v_windows/v/vlib/net/http/response_test.v')
-rw-r--r--v_windows/v/vlib/net/http/response_test.v36
1 files changed, 36 insertions, 0 deletions
diff --git a/v_windows/v/vlib/net/http/response_test.v b/v_windows/v/vlib/net/http/response_test.v
new file mode 100644
index 0000000..bf2fba3
--- /dev/null
+++ b/v_windows/v/vlib/net/http/response_test.v
@@ -0,0 +1,36 @@
+module http
+
+fn test_response_bytestr() ? {
+ {
+ resp := new_response(
+ status: .ok
+ text: 'Foo'
+ )
+ assert resp.bytestr() == 'HTTP/1.1 200 OK\r\n' + 'Content-Length: 3\r\n' + '\r\n' + 'Foo'
+ }
+ {
+ resp := new_response(
+ status: .found
+ text: 'Foo'
+ header: new_header(key: .location, value: '/')
+ )
+ lines := resp.bytestr().split_into_lines()
+ assert lines[0] == 'HTTP/1.1 302 Found'
+ // header order is not guaranteed
+ check_headers(['Location: /', 'Content-Length: 3'], lines[1..3]) ?
+ assert lines[3] == ''
+ assert lines[4] == 'Foo'
+ }
+}
+
+// check_headers is a helper function for asserting all expected headers
+// are found because rendered header order is not guaranteed. The check
+// is O(n^2) which is fine for small lists.
+fn check_headers(expected []string, found []string) ? {
+ assert expected.len == found.len
+ for header in expected {
+ if !found.contains(header) {
+ return error('expected header "$header" not in $found')
+ }
+ }
+}