Skip to content

Commit

Permalink
Cleaning up tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
mikeal committed May 19, 2010
1 parent a3ac375 commit 1139efe
Showing 1 changed file with 11 additions and 14 deletions.
25 changes: 11 additions & 14 deletions tests/couch.js
Original file line number Diff line number Diff line change
@@ -1,33 +1,30 @@
var request = require('../lib/main'),
sys = require('sys');
sys = require('sys'),
assert = require('assert');

function testports (port) {
var uri = port ? 'http://mikeal.couchone.com' + ":" + port : 'http://mikeal.couchone.com';
sys.puts(uri)
request({uri:uri}, function (error, response, body) {
if (error) {throw new Error(error)};
if (!response.statusCode == 200) {
throw new Error("Wrong status code "+response.statusCode);
}
var v = '{"couchdb":"Welcome",'
if (body.slice(0, v.length) !== v) {
throw new Error("Unexpected body\n"+body);
}
assert.equal(response.statusCode, 200);
assert.equal(body.slice(0, '{"couchdb":"Welcome",'.length), '{"couchdb":"Welcome",');
})
}
testports();
testports(80)
testports(5984)

var randomnumber=Math.floor(Math.random()*11).toString();
var randomnumber=Math.floor(Math.random()*100000000).toString();
request({uri:'http://mikeal.couchone.com/testjs', method:'POST', body:'{"_id":"'+randomnumber+'"}'},
function (error, response, body) {
if (error) {throw new Error(error)};
if (!response.statusCode == 201) {
throw new Error("Wrong status code "+response.statusCode);
}
assert.equal(response.statusCode, 201);
});

request({uri:'http://gmail.com'}, function (error, response, body) {
sys.puts(error)
var options = {uri:'http://gmail.com'};
request(options, function (error, response, body) {
assert.equal(response.statusCode, 200);
assert.equal(options.uri.host, 'www.google.com');
assert.equal(response.socket.port, 443);
})

0 comments on commit 1139efe

Please sign in to comment.