🧚 A practical web framework for Gleam

Test getters and setters

+89 -6
+16 -6
src/wisp.gleam
··· 123 123 pub type Response = 124 124 HttpResponse(ResponseBody) 125 125 126 - // TODO: test 127 126 // TODO: document 128 127 pub fn html_response(html: StringBuilder, status: Int) -> Response { 129 - HttpResponse(status, [#("Content-Type", "text/html")], Text(html)) 128 + HttpResponse(status, [#("content-type", "text/html")], Text(html)) 130 129 } 131 130 132 - // TODO: test 133 131 // TODO: document 134 132 pub fn html_body(response: Response, html: StringBuilder) -> Response { 135 133 response ··· 190 188 ReadingFinished 191 189 } 192 190 193 - // TODO: test 194 191 // TODO: document 195 192 pub fn set_max_body_size(request: Request, size: Int) -> Request { 196 193 Connection(..request.body, max_body_size: size) 197 194 |> request.set_body(request, _) 198 195 } 199 196 200 - // TODO: test 197 + // TODO: document 198 + pub fn get_max_body_size(request: Request) -> Int { 199 + request.body.max_body_size 200 + } 201 + 201 202 // TODO: document 202 203 pub fn set_max_files_size(request: Request, size: Int) -> Request { 203 204 Connection(..request.body, max_files_size: size) 204 205 |> request.set_body(request, _) 205 206 } 206 207 207 - // TODO: test 208 + // TODO: document 209 + pub fn get_max_files_size(request: Request) -> Int { 210 + request.body.max_files_size 211 + } 212 + 208 213 // TODO: document 209 214 pub fn set_read_chunk_size(request: Request, size: Int) -> Request { 210 215 Connection(..request.body, read_chunk_size: size) 211 216 |> request.set_body(request, _) 217 + } 218 + 219 + // TODO: document 220 + pub fn get_read_chunk_size(request: Request) -> Int { 221 + request.body.read_chunk_size 212 222 } 213 223 214 224 pub type Request =
+73
test/wisp_test.gleam
··· 3 3 import wisp 4 4 import gleam/http 5 5 import gleam/http/response.{Response} 6 + import gleam/http/request 7 + import gleam/string_builder 6 8 7 9 pub fn main() { 8 10 gleeunit.main() ··· 32 34 wisp.method_not_allowed([http.Get, http.Patch, http.Delete]) 33 35 |> should.equal(Response(405, [#("allow", "DELETE, GET, PATCH")], wisp.Empty)) 34 36 } 37 + 38 + pub fn html_response_test() { 39 + let body = string_builder.from_string("Hello, world!") 40 + let response = wisp.html_response(body, 200) 41 + response.status 42 + |> should.equal(200) 43 + response.headers 44 + |> should.equal([#("content-type", "text/html")]) 45 + response.body 46 + |> wisp.body_to_string_builder 47 + |> should.equal(body) 48 + } 49 + 50 + pub fn html_body_test() { 51 + let body = string_builder.from_string("Hello, world!") 52 + let response = 53 + wisp.method_not_allowed([http.Get]) 54 + |> wisp.html_body(body) 55 + response.status 56 + |> should.equal(405) 57 + response.headers 58 + |> should.equal([#("allow", "GET"), #("content-type", "text/html")]) 59 + response.body 60 + |> wisp.body_to_string_builder 61 + |> should.equal(body) 62 + } 63 + 64 + pub fn set_get_max_body_size_test() { 65 + let request = 66 + request.new() 67 + |> request.set_body(wisp.test_connection(<<>>)) 68 + 69 + request 70 + |> wisp.get_max_body_size 71 + |> should.equal(8_000_000) 72 + 73 + request 74 + |> wisp.set_max_body_size(10) 75 + |> wisp.get_max_body_size 76 + |> should.equal(10) 77 + } 78 + 79 + pub fn set_get_max_files_size_test() { 80 + let request = 81 + request.new() 82 + |> request.set_body(wisp.test_connection(<<>>)) 83 + 84 + request 85 + |> wisp.get_max_files_size 86 + |> should.equal(32_000_000) 87 + 88 + request 89 + |> wisp.set_max_files_size(10) 90 + |> wisp.get_max_files_size 91 + |> should.equal(10) 92 + } 93 + 94 + pub fn set_get_read_chunk_size_test() { 95 + let request = 96 + request.new() 97 + |> request.set_body(wisp.test_connection(<<>>)) 98 + 99 + request 100 + |> wisp.get_read_chunk_size 101 + |> should.equal(1_000_000) 102 + 103 + request 104 + |> wisp.set_read_chunk_size(10) 105 + |> wisp.get_read_chunk_size 106 + |> should.equal(10) 107 + }