From a5b117fcdf5559e80c033fd3364f7b8566c9a289 Mon Sep 17 00:00:00 2001
From: Tw <tw19881113@gmail.com>
Date: Tue, 17 Nov 2015 15:08:36 +0800
Subject: [PATCH] proxy: make tests workable when offline

Instead of accessing the google website, we setup a local server
for test, then tests will work fine even we are offline.

Fix issue #346

Signed-off-by: Tw <tw19881113@gmail.com>
---
 middleware/proxy/policy_test.go | 17 ++++++++++++++++-
 1 file changed, 16 insertions(+), 1 deletion(-)

diff --git a/middleware/proxy/policy_test.go b/middleware/proxy/policy_test.go
index b7d633277..8f4f1f792 100644
--- a/middleware/proxy/policy_test.go
+++ b/middleware/proxy/policy_test.go
@@ -1,9 +1,24 @@
 package proxy
 
 import (
+	"net/http"
+	"net/http/httptest"
+	"os"
 	"testing"
 )
 
+var workableServer *httptest.Server
+
+func TestMain(m *testing.M) {
+	workableServer = httptest.NewServer(http.HandlerFunc(
+		func(w http.ResponseWriter, r *http.Request) {
+			// do nothing
+		}))
+	r := m.Run()
+	workableServer.Close()
+	os.Exit(r)
+}
+
 type customPolicy struct{}
 
 func (r *customPolicy) Select(pool HostPool) *UpstreamHost {
@@ -13,7 +28,7 @@ func (r *customPolicy) Select(pool HostPool) *UpstreamHost {
 func testPool() HostPool {
 	pool := []*UpstreamHost{
 		{
-			Name: "http://google.com", // this should resolve (healthcheck test)
+			Name: workableServer.URL, // this should resolve (healthcheck test)
 		},
 		{
 			Name: "http://shouldnot.resolve", // this shouldn't