From 4e65353a29212ac77c2aa857d602b77f4615fa2e Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E5=8A=A0=E9=87=8C?= <xiaofeng.mxf@taobao.com>
Date: Fri, 14 Nov 2014 17:26:49 +0800
Subject: [PATCH] add test unit

---
 lib/requestHandler.js |  2 +-
 package.json          | 28 +++++++-------
 test.js               | 87 ++++++-------------------------------------
 3 files changed, 27 insertions(+), 90 deletions(-)

diff --git a/lib/requestHandler.js b/lib/requestHandler.js
index 6f26f2e..b3f284c 100644
--- a/lib/requestHandler.js
+++ b/lib/requestHandler.js
@@ -360,7 +360,7 @@ function setRules(newRule){
         }
         async.series(functions,function(errors,result){
             if(!errors){
-                console.log(color.green('Anyproxy rules initialize finished, have a fun!'));
+                console.log(color.green('Anyproxy rules initialize finished, have fun!'));
             }
         });
 
diff --git a/package.json b/package.json
index c93c36d..f9162eb 100644
--- a/package.json
+++ b/package.json
@@ -19,28 +19,30 @@
     "stream-throttle": "^0.1.3",
     "ws": "^0.4.32"
   },
-  "devDependencies": {},
-  "scripts": {
-    "test": "nodeunit test.js"
+  "devDependencies": {
+    "proxy-eval": "^1.1.0"
   },
-  "optionalDependencies":{
-    "underscore":"^1.7.0",
-    "cookie":"^0.1.2",
-    "mysql":"^2.5.2",
+  "scripts": {
+    "test": "node test.js"
+  },
+  "optionalDependencies": {
+    "underscore": "^1.7.0",
+    "cookie": "^0.1.2",
+    "mysql": "^2.5.2",
     "iconv-lite": "^0.4.4",
     "ip": "^0.3.2",
     "jquery": "^2.1.1",
     "jsdom": "^1.0.3",
     "socks5-http-client": "^0.1.6",
     "socks5-https-client": "^0.2.2",
-    "http-proxy-agent":"^0.2.6",
-    "https-proxy-agent":"^0.3.5",
-    "tcp-ping":"^0.1.1",
-    "request":"^2.48.0"
+    "http-proxy-agent": "^0.2.6",
+    "https-proxy-agent": "^0.3.5",
+    "tcp-ping": "^0.1.1",
+    "request": "^2.48.0"
   },
   "repository": {
-    "type":"git",
-    "url" :"https://github.com/alibaba/anyproxy"  
+    "type": "git",
+    "url": "https://github.com/alibaba/anyproxy"
   },
   "author": "ottomao@gmail.com",
   "license": "ISC"
diff --git a/test.js b/test.js
index f7e2d6a..ad08da7 100644
--- a/test.js
+++ b/test.js
@@ -1,78 +1,13 @@
-var https = require("https"),
-	http  = require("http"),
-	proxy = require("./proxy"),
-	tunnel= require('tunnel'),
-	tls   = require("tls");
+var tester = require("proxy-eval"),
+    proxy  = require("./proxy.js");
 
-process.env['NODE_TLS_REJECT_UNAUTHORIZED'] = '0';
+new proxy.proxyServer({
+	type:"http"
+});
 
-module.exports.httpOverHttp = function(test){
-	var testDesc    = "httpOverHttp",
-        proxyServer = new proxy.proxyServer("http","8004");
-
-	try{
-		var test_option_http_over_http = {
-		    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();
-    }
-}
\ No newline at end of file
+setTimeout(function(){
+	tester.test( {proxy : 'http://127.0.0.1:8001',reqTimeout:3000} ,function(results){
+		tester.printResult(results);
+	    process.exit();
+	});
+},2000);
\ No newline at end of file