Skip to content
This repository has been archived by the owner on Apr 22, 2023. It is now read-only.

Commit

Permalink
Added test case for the simple multipart API
Browse files Browse the repository at this point in the history
So far this didn't have any test coverage.
  • Loading branch information
felixge committed Jan 5, 2010
1 parent d9a8137 commit aa73ed9
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion test/mjsunit/test-multipart.js
Expand Up @@ -12,7 +12,7 @@ var badRequests = 0;
var parts = {};
var respond = function(res, text) {
requests++;
if (requests == 2) {
if (requests == 3) {
server.close();
}

Expand All @@ -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) {
Expand Down Expand Up @@ -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();
Expand Down

0 comments on commit aa73ed9

Please sign in to comment.