summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--service/rpc/config_test.go2
-rw-r--r--util/network.go6
-rw-r--r--util/network_test.go14
3 files changed, 20 insertions, 2 deletions
diff --git a/service/rpc/config_test.go b/service/rpc/config_test.go
index 6cf63eea..af261698 100644
--- a/service/rpc/config_test.go
+++ b/service/rpc/config_test.go
@@ -71,7 +71,7 @@ func Test_Config_Error(t *testing.T) {
ln, err := cfg.Listener()
assert.Nil(t, ln)
assert.Error(t, err)
- assert.Equal(t, "invalid socket DSN (tcp://:6001, unix://file.sock)", err.Error())
+ assert.Equal(t, "Invalid DSN (tcp://:6001, unix://file.sock)", err.Error())
}
func Test_Config_ErrorMethod(t *testing.T) {
diff --git a/util/network.go b/util/network.go
index 1ceb95b0..4c393c37 100644
--- a/util/network.go
+++ b/util/network.go
@@ -10,7 +10,11 @@ import (
func CreateListener(address string) (net.Listener, error) {
dsn := strings.Split(address, "://")
if len(dsn) != 2 {
- return nil, errors.New("invalid socket DSN (tcp://:6001, unix://file.sock)")
+ return nil, errors.New("Invalid DSN (tcp://:6001, unix://file.sock)")
+ }
+
+ if dsn[0] != "unix" && dsn[0] != "tcp" {
+ return nil, errors.New("Invalid Protocol (tcp://:6001, unix://file.sock)")
}
if dsn[0] == "unix" {
diff --git a/util/network_test.go b/util/network_test.go
new file mode 100644
index 00000000..bdc7e0b7
--- /dev/null
+++ b/util/network_test.go
@@ -0,0 +1,14 @@
+package util
+
+import (
+ "github.com/stretchr/testify/assert"
+ "testing"
+)
+
+func TestCreateListener(t *testing.T) {
+ _, err := CreateListener("unexpected dsn");
+ assert.Error(t, err, "Invalid DSN (tcp://:6001, unix://file.sock)")
+
+ _, err = CreateListener("aaa://192.168.0.1");
+ assert.Error(t, err, "Invalid Protocol (tcp://:6001, unix://file.sock)")
+}