Added test case for the simple multipart API

So far this didn't have any test coverage.
This commit is contained in:
Felix Geisendörfer
2010-01-05 22:28:03 +01:00
parent d9a81374b2
commit aa73ed973c

View File

@@ -12,7 +12,7 @@ var badRequests = 0;
var parts = {};
var respond = function(res, text) {
requests++;
if (requests == 2) {
if (requests == 3) {
server.close();
}
@@ -22,6 +22,18 @@ var respond = function(res, text) {
};
var server = http.createServer(function(req, res) {
if (req.headers['x-use-simple-api']) {
multipart.parse(req)
.addCallback(function() {
respond(res, 'thanks');
})
.addErrback(function() {
badRequests++;
});
return;
}
try {
var stream = new multipart.Stream(req);
} catch (e) {
@@ -67,6 +79,11 @@ var request = client.request('POST', '/', {'Content-Type': 'multipart/form-data;
request.sendBody(fixture.reply, 'binary');
request.finish();
var client = http.createClient(port);
var simpleRequest = client.request('POST', '/', {'X-Use-Simple-Api': 'yes', 'Content-Type': 'multipart/form-data; boundary=AaB03x', 'Content-Length': fixture.reply.length});
simpleRequest.sendBody(fixture.reply, 'binary');
simpleRequest.finish();
var badRequest = client.request('POST', '/', {'Content-Type': 'something', 'Content-Length': fixture.reply.length});
badRequest.sendBody(fixture.reply, 'binary');
badRequest.finish();