Skip to content

Commit e152d97

Browse files
committed
fix #167 - suppress expected failure logging during tests
1 parent 0e5443e commit e152d97

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

source/dlangbot/utils.d

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,25 @@ module dlangbot.utils;
33
import dlangbot.app : runAsync;
44

55
import vibe.http.client : HTTPClientRequest, HTTPClientResponse;
6+
import vibe.http.common : HTTPStatus;
67

78
import std.datetime : Duration;
89

10+
version (unittest) int _expectedStatusCode;
11+
12+
bool expectedStatusCode(int statusCode) nothrow @safe @nogc
13+
{
14+
version (unittest)
15+
{
16+
if (_expectedStatusCode == statusCode)
17+
{
18+
_expectedStatusCode = 0;
19+
return true;
20+
}
21+
}
22+
return false;
23+
}
24+
925
HTTPClientResponse request(
1026
string url,
1127
scope void delegate(scope HTTPClientRequest) requester = cast(void delegate(scope HTTPClientRequest req))null
@@ -23,7 +39,7 @@ HTTPClientResponse request(
2339
requester(req);
2440
method = req.method;
2541
});
26-
if (res.statusCode / 100 != 2)
42+
if (res.statusCode / 100 != 2 && !expectedStatusCode(res.statusCode))
2743
logError("%s %s failed; %s %s.", method, url, res.statusPhrase, res.statusCode);
2844
return res;
2945
}
@@ -46,7 +62,7 @@ void request(
4662
method = req.method;
4763
},
4864
(scope res) {
49-
if (res.statusCode / 100 != 2)
65+
if (res.statusCode / 100 != 2 && !expectedStatusCode(res.statusCode))
5066
logError("%s %s failed; %s %s.", method, url, res.statusPhrase, res.statusCode);
5167
responder(res);
5268
}

test/utils.d

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,10 @@ auto payloadServer(scope HTTPServerRequest req, scope HTTPServerResponse res)
105105
}
106106

107107
res.statusCode = expectation.respStatusCode;
108+
// set failure status code exception to suppress false errors
109+
import dlangbot.utils : _expectedStatusCode;
110+
if (expectation.respStatusCode / 100 != 2)
111+
_expectedStatusCode = expectation.respStatusCode;
108112

109113
string filePath = buildPath(payloadDir, req.requestURL[1 .. $].replace("/", "_"));
110114

0 commit comments

Comments
 (0)