-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathcheck-http.w
48 lines (39 loc) · 1.19 KB
/
check-http.w
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
bring "./check.w" as c;
bring "./results.w" as r;
bring http;
bring expect;
pub struct CheckHttpProps extends c.CheckProps {
method: http.HttpMethod?; // http method (default "GET")
path: str?; // url path
status: num?; // expected status
body: str?; // expected body contents
}
pub class CheckHttp impl c.ICheck {
inner: c.Check;
new(url: str, options: CheckHttpProps?) {
this.inner = new c.Check(inflight () => {
let var full_url: str = url;
if let path = options?.path {
let var sep = "/";
if path.startsWith("/") {
sep = "";
}
full_url = full_url + sep + path;
}
let method = options?.method ?? http.HttpMethod.GET;
log("http {method} {full_url}");
let response = http.fetch(full_url, method: method);
log("status {response.status}");
expect.equal(response.status, options?.status ?? 200);
if let body = options?.body {
expect.equal(response.body?.contains(body), true);
}
}, options) as "check";
}
pub inflight run(): r.CheckResult {
return this.inner.run();
}
pub inflight latest(): r.CheckResult? {
return this.inner.latest();
}
}