@@ -65,7 +65,6 @@ void startFakeAPIServer()
6565 fakeSettings.port = getFreePort;
6666 fakeSettings.bindAddresses = [" 0.0.0.0" ];
6767 auto router = new URLRouter;
68- router.any(" *" , &payloadServer);
6968
7069 listenHTTP(fakeSettings, router);
7170
@@ -77,77 +76,6 @@ void startFakeAPIServer()
7776 bugzillaURL = fakeAPIServerURL ~ " /bugzilla" ;
7877}
7978
80- // serves saved GitHub API payloads
81- auto payloadServer (scope HTTPServerRequest req, scope HTTPServerResponse res)
82- {
83- import std.path , std.file ;
84- APIExpectation expectation = void ;
85-
86- // simple observer that checks whether a request is expected
87- auto idx = apiExpectations.map! (x => x.url).countUntil(req.requestURL);
88- if (idx >= 0 )
89- {
90- expectation = apiExpectations[idx];
91- if (apiExpectations.length > 1 )
92- apiExpectations = apiExpectations[0 .. idx] ~ apiExpectations[idx + 1 .. $];
93- else
94- apiExpectations.length = 0 ;
95- }
96- else
97- {
98- scope (failure) {
99- writeln(" Remaining expected URLs:" , apiExpectations.map! (x => x.url));
100- }
101- assert (0 , " Request for unexpected URL received: " ~ req.requestURL);
102- }
103-
104- res.statusCode = expectation.respStatusCode;
105- // set failure status code exception to suppress false errors
106- import dlangbot.utils : _expectedStatusCode;
107- if (expectation.respStatusCode / 100 != 2 )
108- _expectedStatusCode = expectation.respStatusCode;
109-
110- string filePath = buildPath(payloadDir, req.requestURL[1 .. $].replace(" /" , " _" ));
111-
112- if (expectation.reqHandler ! is null )
113- {
114- scope (failure) {
115- writefln(" Method: %s" , req.method);
116- writefln(" Json: %s" , req.json);
117- }
118- expectation.reqHandler(req, res);
119- if (res.headerWritten)
120- return ;
121- if (! filePath.exists)
122- return res.writeVoidBody;
123- }
124-
125- if (! filePath.exists)
126- {
127- assert (0 , " Please create payload: " ~ filePath);
128- }
129- else
130- {
131- logInfo(" reading payload: %s" , filePath);
132- auto payload = filePath.readText;
133- if (req.requestURL.startsWith(" /github" , " /trello" ))
134- {
135- auto payloadJson = payload.parseJsonString;
136- replaceAPIReferences(" https://api.github.com" , githubAPIURL, payloadJson);
137- replaceAPIReferences(" https://api.trello.com" , trelloAPIURL, payloadJson);
138-
139- if (expectation.jsonHandler ! is null )
140- expectation.jsonHandler(payloadJson);
141-
142- return res.writeJsonBody(payloadJson);
143- }
144- else
145- {
146- return res.writeBody(payload);
147- }
148- }
149- }
150-
15179void replaceAPIReferences (string official, string local, ref Json json)
15280{
15381 void recursiveReplace (ref Json j)
0 commit comments