add test unit

This commit is contained in:
加里 2014-11-14 17:26:49 +08:00
parent 6279982aaf
commit 4e65353a29
3 changed files with 27 additions and 90 deletions

View File

@ -360,7 +360,7 @@ function setRules(newRule){
} }
async.series(functions,function(errors,result){ async.series(functions,function(errors,result){
if(!errors){ if(!errors){
console.log(color.green('Anyproxy rules initialize finished, have a fun!')); console.log(color.green('Anyproxy rules initialize finished, have fun!'));
} }
}); });

View File

@ -19,28 +19,30 @@
"stream-throttle": "^0.1.3", "stream-throttle": "^0.1.3",
"ws": "^0.4.32" "ws": "^0.4.32"
}, },
"devDependencies": {}, "devDependencies": {
"scripts": { "proxy-eval": "^1.1.0"
"test": "nodeunit test.js"
}, },
"optionalDependencies":{ "scripts": {
"underscore":"^1.7.0", "test": "node test.js"
"cookie":"^0.1.2", },
"mysql":"^2.5.2", "optionalDependencies": {
"underscore": "^1.7.0",
"cookie": "^0.1.2",
"mysql": "^2.5.2",
"iconv-lite": "^0.4.4", "iconv-lite": "^0.4.4",
"ip": "^0.3.2", "ip": "^0.3.2",
"jquery": "^2.1.1", "jquery": "^2.1.1",
"jsdom": "^1.0.3", "jsdom": "^1.0.3",
"socks5-http-client": "^0.1.6", "socks5-http-client": "^0.1.6",
"socks5-https-client": "^0.2.2", "socks5-https-client": "^0.2.2",
"http-proxy-agent":"^0.2.6", "http-proxy-agent": "^0.2.6",
"https-proxy-agent":"^0.3.5", "https-proxy-agent": "^0.3.5",
"tcp-ping":"^0.1.1", "tcp-ping": "^0.1.1",
"request":"^2.48.0" "request": "^2.48.0"
}, },
"repository": { "repository": {
"type":"git", "type": "git",
"url" :"https://github.com/alibaba/anyproxy" "url": "https://github.com/alibaba/anyproxy"
}, },
"author": "ottomao@gmail.com", "author": "ottomao@gmail.com",
"license": "ISC" "license": "ISC"

87
test.js
View File

@ -1,78 +1,13 @@
var https = require("https"), var tester = require("proxy-eval"),
http = require("http"), proxy = require("./proxy.js");
proxy = require("./proxy"),
tunnel= require('tunnel'),
tls = require("tls");
process.env['NODE_TLS_REJECT_UNAUTHORIZED'] = '0'; new proxy.proxyServer({
type:"http"
});
module.exports.httpOverHttp = function(test){ setTimeout(function(){
var testDesc = "httpOverHttp", tester.test( {proxy : 'http://127.0.0.1:8001',reqTimeout:3000} ,function(results){
proxyServer = new proxy.proxyServer("http","8004"); tester.printResult(results);
process.exit();
try{ });
var test_option_http_over_http = { },2000);
host: "localhost",
port: 8004,
path: "/",
headers: {
Host: "www.baidu.com"
}
};
http.get(test_option_http_over_http, function(res) {
var data = "";
res.on("data",function(chunk){
data += chunk;
});
res.on("end",function(){
proxyServer.close();
test.ok(data.length > 50, testDesc);
test.done();
});
});
}catch(e){
console.log(e);
test.ok(false,testDesc);
test.done();
}
}
module.exports.testHttpsOverHttp = function(test){
var testDesc = "httpsOverHttp";
var proxyServer = new proxy.proxyServer("http","8004");
try{
var tunnelingAgent = tunnel.httpsOverHttp({
proxy: {
host: 'localhost',
port: 8004
}
});
var req = https.request({
host: 'www.gotofail.com',
port: 443,
agent: tunnelingAgent
},function(res){
var data = "";
res.on("data",function(chunk){
data += chunk;
});
res.on("end",function(){
proxyServer.close();
test.ok(data.length > 50, testDesc);
test.done();
});
});
req.end();
}catch(e){
console.log(e);
test.ok(false,testDesc);
test.done();
}
}