tangled
alpha
login
or
join now
keii.dev
/
wisp
3
fork
atom
🧚 A practical web framework for Gleam
3
fork
atom
overview
issues
pulls
pipelines
Test getters and setters
Louis Pilfold
2 years ago
ab5151ec
f4f582da
+89
-6
2 changed files
expand all
collapse all
unified
split
src
wisp.gleam
test
wisp_test.gleam
+16
-6
src/wisp.gleam
···
123
123
pub type Response =
124
124
HttpResponse(ResponseBody)
125
125
126
126
-
// TODO: test
127
126
// TODO: document
128
127
pub fn html_response(html: StringBuilder, status: Int) -> Response {
129
129
-
HttpResponse(status, [#("Content-Type", "text/html")], Text(html))
128
128
+
HttpResponse(status, [#("content-type", "text/html")], Text(html))
130
129
}
131
130
132
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
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
200
-
// TODO: test
197
197
+
// TODO: document
198
198
+
pub fn get_max_body_size(request: Request) -> Int {
199
199
+
request.body.max_body_size
200
200
+
}
201
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
207
-
// TODO: test
208
208
+
// TODO: document
209
209
+
pub fn get_max_files_size(request: Request) -> Int {
210
210
+
request.body.max_files_size
211
211
+
}
212
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
217
+
}
218
218
+
219
219
+
// TODO: document
220
220
+
pub fn get_read_chunk_size(request: Request) -> Int {
221
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
6
+
import gleam/http/request
7
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
37
+
38
38
+
pub fn html_response_test() {
39
39
+
let body = string_builder.from_string("Hello, world!")
40
40
+
let response = wisp.html_response(body, 200)
41
41
+
response.status
42
42
+
|> should.equal(200)
43
43
+
response.headers
44
44
+
|> should.equal([#("content-type", "text/html")])
45
45
+
response.body
46
46
+
|> wisp.body_to_string_builder
47
47
+
|> should.equal(body)
48
48
+
}
49
49
+
50
50
+
pub fn html_body_test() {
51
51
+
let body = string_builder.from_string("Hello, world!")
52
52
+
let response =
53
53
+
wisp.method_not_allowed([http.Get])
54
54
+
|> wisp.html_body(body)
55
55
+
response.status
56
56
+
|> should.equal(405)
57
57
+
response.headers
58
58
+
|> should.equal([#("allow", "GET"), #("content-type", "text/html")])
59
59
+
response.body
60
60
+
|> wisp.body_to_string_builder
61
61
+
|> should.equal(body)
62
62
+
}
63
63
+
64
64
+
pub fn set_get_max_body_size_test() {
65
65
+
let request =
66
66
+
request.new()
67
67
+
|> request.set_body(wisp.test_connection(<<>>))
68
68
+
69
69
+
request
70
70
+
|> wisp.get_max_body_size
71
71
+
|> should.equal(8_000_000)
72
72
+
73
73
+
request
74
74
+
|> wisp.set_max_body_size(10)
75
75
+
|> wisp.get_max_body_size
76
76
+
|> should.equal(10)
77
77
+
}
78
78
+
79
79
+
pub fn set_get_max_files_size_test() {
80
80
+
let request =
81
81
+
request.new()
82
82
+
|> request.set_body(wisp.test_connection(<<>>))
83
83
+
84
84
+
request
85
85
+
|> wisp.get_max_files_size
86
86
+
|> should.equal(32_000_000)
87
87
+
88
88
+
request
89
89
+
|> wisp.set_max_files_size(10)
90
90
+
|> wisp.get_max_files_size
91
91
+
|> should.equal(10)
92
92
+
}
93
93
+
94
94
+
pub fn set_get_read_chunk_size_test() {
95
95
+
let request =
96
96
+
request.new()
97
97
+
|> request.set_body(wisp.test_connection(<<>>))
98
98
+
99
99
+
request
100
100
+
|> wisp.get_read_chunk_size
101
101
+
|> should.equal(1_000_000)
102
102
+
103
103
+
request
104
104
+
|> wisp.set_read_chunk_size(10)
105
105
+
|> wisp.get_read_chunk_size
106
106
+
|> should.equal(10)
107
107
+
}