aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDimitri Sokolyuk <demon@dim13.org>2016-04-01 18:36:24 +0200
committerDimitri Sokolyuk <demon@dim13.org>2016-04-01 18:36:24 +0200
commitb7bd7e507cdbc95539ab2912a316a406111bafa0 (patch)
tree3d647b8ed28deada4f8e353fa20b5fafc3df9d9b
parente9069513b1287b6e3654e4d2c43b8a6a8fa1a539 (diff)
Change testing port range
-rw-r--r--rpc.go8
-rw-r--r--server_test.go41
2 files changed, 27 insertions, 22 deletions
diff --git a/rpc.go b/rpc.go
index a658801..bf34484 100644
--- a/rpc.go
+++ b/rpc.go
@@ -9,8 +9,9 @@ import (
)
var (
- ErrNoHost = errors.New("Both Host and Upstream are required")
- ErrNoCert = errors.New("Certificate and Key are required")
+ ErrNoHost = errors.New("Both Host and Upstream are required")
+ ErrNoCert = errors.New("Certificate and Key are required")
+ ErrEmptyHost = errors.New("Empty Host value")
)
const RPCPort = ":8000"
@@ -80,6 +81,9 @@ func (s *GoXY) Del(host string, _ *struct{}) error {
if err != nil {
return err
}
+ if h.Host == "" {
+ return ErrEmptyHost
+ }
delete(s.server.Route, h.Host)
s.server.Save(s.server.DataFile)
return s.server.Update()
diff --git a/server_test.go b/server_test.go
index 244cb43..82e35e1 100644
--- a/server_test.go
+++ b/server_test.go
@@ -21,9 +21,9 @@ type Cannary string
const (
cannary = Cannary("hello from backend")
dataFile = "test.json"
- wwwServer = "localhost:8080"
- tlsServer = "localhost:8443"
- rpcServer = "localhost:8000"
+ wwwServer = "localhost:18080"
+ tlsServer = "localhost:18443"
+ rpcServer = "localhost:18000"
cert = `-----BEGIN CERTIFICATE-----
MIIBXjCCAQygAwIBAgIRAM03h8i2NyJ7sItcK4jU1eEwCgYIKoZIzj0EAwIwEjEQ
MA4GA1UEChMHQWNtZSBDbzAeFw0xNjAzMzExMzU5NTlaFw0yNjAzMjkxMzU5NTla
@@ -107,7 +107,7 @@ func (c Cannary) Equal(s string) bool {
func TestReverseProxy(t *testing.T) {
backServer := httptest.NewServer(cannary)
- t.Log("start", backServer.URL)
+ t.Log("run", backServer.URL)
e := Entry{
Host: "http://" + wwwServer,
@@ -116,9 +116,9 @@ func TestReverseProxy(t *testing.T) {
if err := add(e); err != nil {
t.Error(err)
}
- t.Log("add", e)
+ t.Log("add", e.Host)
- resp, err := get("http://" + wwwServer)
+ resp, err := get(e.Host)
if err != nil {
t.Error(err)
}
@@ -127,17 +127,17 @@ func TestReverseProxy(t *testing.T) {
}
backServer.Close()
- resp, err = get("http://" + wwwServer)
+ resp, err = get(e.Host)
if err == nil || err.Error() != "500 Internal Server Error" {
t.Errorf("closed: got %q expected %v", err, http.StatusInternalServerError)
}
- if err := del(wwwServer); err != nil {
+ t.Log("del", e.Host)
+ if err := del(e.Host); err != nil {
t.Error(err)
}
- t.Log("del", wwwServer)
- resp, err = get("http://" + wwwServer)
+ resp, err = get(e.Host)
if err == nil || err.Error() != "404 Not Found" {
t.Errorf("removed: got %q expected %v", err, http.StatusNotFound)
}
@@ -146,7 +146,7 @@ func TestReverseProxy(t *testing.T) {
func TestReverseProxyTLS(t *testing.T) {
backServer := httptest.NewServer(cannary)
defer backServer.Close()
- t.Log("start", backServer.URL)
+ t.Log("run", backServer.URL)
e := Entry{
Host: "https://" + tlsServer,
@@ -157,9 +157,9 @@ func TestReverseProxyTLS(t *testing.T) {
if err := add(e); err != nil {
t.Error(err)
}
- t.Log("add", e)
+ t.Log("add", e.Host)
- resp, err := get("https://" + tlsServer)
+ resp, err := get(e.Host)
if err != nil {
t.Error(err)
}
@@ -167,10 +167,10 @@ func TestReverseProxyTLS(t *testing.T) {
t.Errorf("got %q expected %q", resp, cannary)
}
- if err := del(tlsServer); err != nil {
+ t.Log("del", e.Host)
+ if err := del(e.Host); err != nil {
t.Error(err)
}
- t.Log("del", tlsServer)
}
func TestWebsocketProxy(t *testing.T) {
@@ -178,7 +178,7 @@ func TestWebsocketProxy(t *testing.T) {
io.Copy(ws, ws)
}))
defer wsServer.Close()
- t.Log("start ws", wsServer.URL)
+ t.Log("run", wsServer.URL)
// Test WebSocket proxy
e := Entry{
@@ -188,9 +188,9 @@ func TestWebsocketProxy(t *testing.T) {
if err := add(e); err != nil {
t.Error(err)
}
- t.Log("add", e)
+ t.Log("add", e.Host)
- ws, err := websocket.Dial("ws://"+wwwServer, "", "http://localhost")
+ ws, err := websocket.Dial(e.Host, "", "http://localhost")
if err != nil {
t.Error(err)
}
@@ -206,8 +206,9 @@ func TestWebsocketProxy(t *testing.T) {
if !bytes.Equal(msg, []byte(cannary)) {
t.Errorf("got %q expected %q", string(msg), cannary)
}
- if err := del(tlsServer); err != nil {
+
+ t.Log("del", e.Host)
+ if err := del(e.Host); err != nil {
t.Error(err)
}
- t.Log("del", tlsServer)
}