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 empty response functions
Louis Pilfold
2 years ago
f4f582da
37f00d50
+28
-9
2 changed files
expand all
collapse all
unified
split
src
wisp.gleam
test
wisp_test.gleam
+2
-5
src/wisp.gleam
···
137
137
|> response.set_header("content-type", "text/html")
138
138
}
139
139
140
140
-
// TODO: test
141
140
// TODO: document
142
141
pub fn method_not_allowed(permitted: List(Method)) -> Response {
143
142
let allowed =
144
143
permitted
145
144
|> list.map(http.method_to_string)
145
145
+
|> list.sort(string.compare)
146
146
|> string.join(", ")
147
147
+
|> string.uppercase
147
148
HttpResponse(405, [#("allow", allowed)], Empty)
148
149
}
149
150
150
150
-
// TODO: test
151
151
// TODO: document
152
152
pub fn not_found() -> Response {
153
153
HttpResponse(404, [], Empty)
154
154
}
155
155
156
156
-
// TODO: test
157
156
// TODO: document
158
157
pub fn bad_request() -> Response {
159
158
HttpResponse(400, [], Empty)
160
159
}
161
160
162
162
-
// TODO: test
163
161
// TODO: document
164
162
pub fn entity_too_large() -> Response {
165
163
HttpResponse(413, [], Empty)
166
164
}
167
165
168
168
-
// TODO: test
169
166
// TODO: document
170
167
pub fn internal_server_error() -> Response {
171
168
HttpResponse(500, [], Empty)
+26
-4
test/wisp_test.gleam
···
1
1
import gleeunit
2
2
import gleeunit/should
3
3
+
import wisp
4
4
+
import gleam/http
5
5
+
import gleam/http/response.{Response}
3
6
4
7
pub fn main() {
5
8
gleeunit.main()
6
9
}
7
10
8
8
-
// gleeunit test functions end in `_test`
9
9
-
pub fn hello_world_test() {
10
10
-
1
11
11
-
|> should.equal(1)
11
11
+
pub fn internal_server_error_test() {
12
12
+
wisp.internal_server_error()
13
13
+
|> should.equal(Response(500, [], wisp.Empty))
14
14
+
}
15
15
+
16
16
+
pub fn entity_too_large_test() {
17
17
+
wisp.entity_too_large()
18
18
+
|> should.equal(Response(413, [], wisp.Empty))
19
19
+
}
20
20
+
21
21
+
pub fn bad_request_test() {
22
22
+
wisp.bad_request()
23
23
+
|> should.equal(Response(400, [], wisp.Empty))
24
24
+
}
25
25
+
26
26
+
pub fn not_found_test() {
27
27
+
wisp.not_found()
28
28
+
|> should.equal(Response(404, [], wisp.Empty))
29
29
+
}
30
30
+
31
31
+
pub fn method_not_allowed_test() {
32
32
+
wisp.method_not_allowed([http.Get, http.Patch, http.Delete])
33
33
+
|> should.equal(Response(405, [#("allow", "DELETE, GET, PATCH")], wisp.Empty))
12
34
}