aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDimitri Sokolyuk <demon@dim13.org>2016-04-01 16:29:18 +0200
committerDimitri Sokolyuk <demon@dim13.org>2016-04-01 16:29:18 +0200
commit7396bdc3b4745108760282890d0ae1c985865d69 (patch)
treebdebade830aa51ed7156c2e4a253ea798679fad5
parent0ddcedc64fac9eb941802a29bcbf8787d2541fdc (diff)
Fix NewServer
-rw-r--r--cmd/goxyctl/main.go2
-rw-r--r--rpc.go2
-rw-r--r--server.go3
-rw-r--r--server_test.go21
4 files changed, 17 insertions, 11 deletions
diff --git a/cmd/goxyctl/main.go b/cmd/goxyctl/main.go
index dd7c86d..73b2958 100644
--- a/cmd/goxyctl/main.go
+++ b/cmd/goxyctl/main.go
@@ -9,7 +9,7 @@ import (
)
var (
- rpcserver = flag.String("server", ":http-alt", "RPC Server")
+ rpcserver = flag.String("server", goxy.RPCPort, "RPC Server")
host = flag.String("host", "", "Host URL")
upstream = flag.String("up", "", "Upstream URL")
keyfile = flag.String("key", "", "TLS Key file")
diff --git a/rpc.go b/rpc.go
index a94bc48..0916e88 100644
--- a/rpc.go
+++ b/rpc.go
@@ -12,6 +12,8 @@ var (
ErrNoCert = errors.New("Certificate and Key are required")
)
+const PRCPort = ":8000"
+
type GoXY struct {
server *Server
}
diff --git a/server.go b/server.go
index 44defa8..9fe2571 100644
--- a/server.go
+++ b/server.go
@@ -15,6 +15,9 @@ type Server struct {
}
func NewServer(dataFile, listenWWW, listenTLS, listenRPC string) (*Server, error) {
+ if listenRPC == "" {
+ listenRPC = RPCPort
+ }
r := make(Route)
server := &Server{
DataFile: dataFile,
diff --git a/server_test.go b/server_test.go
index 4577a67..8853193 100644
--- a/server_test.go
+++ b/server_test.go
@@ -10,6 +10,7 @@ import (
"log"
"net/http"
"net/http/httptest"
+ "os"
"testing"
"golang.org/x/net/websocket"
@@ -40,14 +41,18 @@ E2xc6bxzAlZGXQ==
-----END EC PRIVATE KEY-----`
)
-var server Server
-
func init() {
+ os.Remove(dataFile)
server, err := NewServer(dataFile, wwwServer, tlsServer, rpcServer)
if err != nil {
log.Fatal(err)
}
- go server.Start()
+ go func() {
+ if err := server.Start(); err != nil {
+ log.Fatal(err)
+ }
+ }()
+ log.Println("start test server")
}
func get(uri string) (string, error) {
@@ -114,23 +119,20 @@ func TestReverseProxy(t *testing.T) {
}
t.Log("add", e)
- // normal connection
resp, err := get("http://" + wwwServer)
if err != nil {
t.Error(err)
}
if !cannary.Equal(resp) {
- t.Errorf("got %q expected %q", resp, cannary)
+ t.Errorf("normal: got %q expected %q", resp, cannary)
}
- // closed connection
backServer.Close()
resp, err = get("http://" + wwwServer)
if err == nil || err.Error() != "500 Internal Server Error" {
- t.Errorf("got %q expected %v", err, http.StatusInternalServerError)
+ t.Errorf("closed: got %q expected %v", err, http.StatusInternalServerError)
}
- // removed route
if err := del(wwwServer); err != nil {
t.Error(err)
}
@@ -138,7 +140,7 @@ func TestReverseProxy(t *testing.T) {
resp, err = get("http://" + wwwServer)
if err == nil || err.Error() != "404 Not Found" {
- t.Errorf("got %q expected %v", err, http.StatusNotFound)
+ t.Errorf("removed: got %q expected %v", err, http.StatusNotFound)
}
}
@@ -162,7 +164,6 @@ func TestReverseProxyTLS(t *testing.T) {
if err != nil {
t.Error(err)
}
-
if !cannary.Equal(resp) {
t.Errorf("got %q expected %q", resp, cannary)
}