diff options
author | Wolfy-J <[email protected]> | 2018-06-07 16:59:38 +0300 |
---|---|---|
committer | Wolfy-J <[email protected]> | 2018-06-07 16:59:38 +0300 |
commit | e2ccf9717ca11bbcf8e9b8ee5332e3211d38cfa9 (patch) | |
tree | e64ca370052172e1e981f9be0c862f870741c782 | |
parent | b1a324e9b230f7db114fe7264019f86ff1875e16 (diff) |
more tests
-rw-r--r-- | .travis.yml | 2 | ||||
-rw-r--r-- | _____/http/config.go (renamed from cmd/_____/http/config.go) | 2 | ||||
-rw-r--r-- | _____/http/request.go (renamed from cmd/_____/http/request.go) | 0 | ||||
-rw-r--r-- | _____/http/rpc.go (renamed from cmd/_____/http/rpc.go) | 2 | ||||
-rw-r--r-- | _____/http/server.go (renamed from cmd/_____/http/server.go) | 0 | ||||
-rw-r--r-- | _____/http/service.go (renamed from cmd/_____/http/service.go) | 0 | ||||
-rw-r--r-- | _____/http/static.go (renamed from cmd/_____/http/static.go) | 0 | ||||
-rw-r--r-- | _____/http/uploads.go (renamed from cmd/_____/http/uploads.go) | 0 | ||||
-rw-r--r-- | _____/utils/size.go (renamed from cmd/_____/utils/size.go) | 0 | ||||
-rw-r--r-- | _____/utils/workers.go (renamed from cmd/_____/utils/workers.go) | 0 | ||||
-rw-r--r-- | _____/verbose.go (renamed from cmd/_____/verbose.go) | 0 | ||||
-rw-r--r-- | composer.json | 5 | ||||
-rw-r--r-- | rpc/config.go | 4 | ||||
-rw-r--r-- | rpc/config_test.go | 109 | ||||
-rw-r--r-- | service/registry.go | 4 |
15 files changed, 121 insertions, 7 deletions
diff --git a/.travis.yml b/.travis.yml index 5ea8b20d..f7108a84 100644 --- a/.travis.yml +++ b/.travis.yml @@ -20,7 +20,7 @@ install: - go get -u "github.com/stretchr/testify/assert" script: - - go test -race -v -coverprofile=coverage.txt -covermode=atomic + - go test ./... -race -v -coverprofile=coverage.txt -covermode=atomic after_success: - bash <(curl -s https://codecov.io/bash) diff --git a/cmd/_____/http/config.go b/_____/http/config.go index 54e39a7d..4ea414c1 100644 --- a/cmd/_____/http/config.go +++ b/_____/http/config.go @@ -3,7 +3,7 @@ package http import ( "fmt" "github.com/spiral/roadrunner/service" - "github.com/spiral/roadrunner/cmd/_____/utils" + "github.com/spiral/roadrunner/_____/utils" "os" "path" "strings" diff --git a/cmd/_____/http/request.go b/_____/http/request.go index fd483744..fd483744 100644 --- a/cmd/_____/http/request.go +++ b/_____/http/request.go diff --git a/cmd/_____/http/rpc.go b/_____/http/rpc.go index 1bc8a06b..e54eae7c 100644 --- a/cmd/_____/http/rpc.go +++ b/_____/http/rpc.go @@ -2,7 +2,7 @@ package http import ( "github.com/sirupsen/logrus" - "github.com/spiral/roadrunner/cmd/_____/utils" + "github.com/spiral/roadrunner/_____/utils" "github.com/pkg/errors" ) diff --git a/cmd/_____/http/server.go b/_____/http/server.go index db1f22ef..db1f22ef 100644 --- a/cmd/_____/http/server.go +++ b/_____/http/server.go diff --git a/cmd/_____/http/service.go b/_____/http/service.go index 008aeab8..008aeab8 100644 --- a/cmd/_____/http/service.go +++ b/_____/http/service.go diff --git a/cmd/_____/http/static.go b/_____/http/static.go index b055099f..b055099f 100644 --- a/cmd/_____/http/static.go +++ b/_____/http/static.go diff --git a/cmd/_____/http/uploads.go b/_____/http/uploads.go index c3b18169..c3b18169 100644 --- a/cmd/_____/http/uploads.go +++ b/_____/http/uploads.go diff --git a/cmd/_____/utils/size.go b/_____/utils/size.go index 176cc9e1..176cc9e1 100644 --- a/cmd/_____/utils/size.go +++ b/_____/utils/size.go diff --git a/cmd/_____/utils/workers.go b/_____/utils/workers.go index 1024b4c6..1024b4c6 100644 --- a/cmd/_____/utils/workers.go +++ b/_____/utils/workers.go diff --git a/cmd/_____/verbose.go b/_____/verbose.go index d0088b69..d0088b69 100644 --- a/cmd/_____/verbose.go +++ b/_____/verbose.go diff --git a/composer.json b/composer.json index ada34e58..403316fd 100644 --- a/composer.json +++ b/composer.json @@ -11,7 +11,8 @@ ], "require": { "php": "^7.0", - "spiral/goridge": "^2.0" + "spiral/goridge": "^2.0", + "psr/http-message": "^1.0" }, "require-dev": { "phpunit/phpunit": "~6.0" @@ -21,4 +22,4 @@ "Spiral\\RoadRunner\\": "php-src/" } } -}
\ No newline at end of file +} diff --git a/rpc/config.go b/rpc/config.go index 67dc1094..8a34752a 100644 --- a/rpc/config.go +++ b/rpc/config.go @@ -18,7 +18,7 @@ type config struct { func (cfg *config) listener() (net.Listener, error) { dsn := strings.Split(cfg.Listen, "://") if len(dsn) != 2 { - return nil, errors.New("invalid socket DSN (tcp://:6001, unix://sock.unix)") + return nil, errors.New("invalid socket DSN (tcp://:6001, unix://rpc.sock)") } return net.Listen(dsn[0], dsn[1]) @@ -28,7 +28,7 @@ func (cfg *config) listener() (net.Listener, error) { func (cfg *config) dialer() (net.Conn, error) { dsn := strings.Split(cfg.Listen, "://") if len(dsn) != 2 { - return nil, errors.New("invalid socket DSN (tcp://:6001, unix://sock.unix)") + return nil, errors.New("invalid socket DSN (tcp://:6001, unix://rpc.sock)") } return net.Dial(dsn[0], dsn[1]) diff --git a/rpc/config_test.go b/rpc/config_test.go new file mode 100644 index 00000000..dbb028d3 --- /dev/null +++ b/rpc/config_test.go @@ -0,0 +1,109 @@ +package rpc + +import ( + "testing" + "github.com/stretchr/testify/assert" + "runtime" +) + +func TestConfig_Listener(t *testing.T) { + cfg := &config{Listen: "tcp://:18001"} + + ln, err := cfg.listener() + assert.NoError(t, err) + assert.NotNil(t, ln) + defer ln.Close() + + assert.Equal(t, "tcp", ln.Addr().Network()) + assert.Equal(t, "[::]:18001", ln.Addr().String()) +} + +func TestConfig_ListenerUnix(t *testing.T) { + if runtime.GOOS == "windows" { + t.Skip("not supported on " + runtime.GOOS) + } + + cfg := &config{Listen: "unix://rpc.sock"} + + ln, err := cfg.listener() + assert.NoError(t, err) + assert.NotNil(t, ln) + defer ln.Close() + + assert.Equal(t, "unix", ln.Addr().Network()) + assert.Equal(t, "rpc.sock", ln.Addr().String()) +} + +func Test_Config_Error(t *testing.T) { + if runtime.GOOS == "windows" { + t.Skip("not supported on " + runtime.GOOS) + } + + cfg := &config{Listen: "uni:unix.sock"} + ln, err := cfg.listener() + assert.Nil(t, ln) + assert.Error(t, err) + assert.Equal(t, "invalid socket DSN (tcp://:6001, unix://rpc.sock)", err.Error()) +} + +func Test_Config_ErrorMethod(t *testing.T) { + cfg := &config{Listen: "xinu://unix.sock"} + + ln, err := cfg.listener() + assert.Nil(t, ln) + assert.Error(t, err) +} + +func TestConfig_Dialer(t *testing.T) { + cfg := &config{Listen: "tcp://:18001"} + + ln, err := cfg.listener() + defer ln.Close() + + conn, err := cfg.dialer() + assert.NoError(t, err) + assert.NotNil(t, conn) + defer conn.Close() + + assert.Equal(t, "tcp", conn.RemoteAddr().Network()) + assert.Equal(t, "127.0.0.1:18001", conn.RemoteAddr().String()) +} + +func TestConfig_DialerUnix(t *testing.T) { + if runtime.GOOS == "windows" { + t.Skip("not supported on " + runtime.GOOS) + } + + cfg := &config{Listen: "unix://rpc.sock"} + + ln, err := cfg.listener() + defer ln.Close() + + conn, err := cfg.dialer() + assert.NoError(t, err) + assert.NotNil(t, conn) + defer conn.Close() + + assert.Equal(t, "unix", conn.RemoteAddr().Network()) + assert.Equal(t, "rpc.sock", conn.RemoteAddr().String()) +} + +func Test_Config_DialerError(t *testing.T) { + if runtime.GOOS == "windows" { + t.Skip("not supported on " + runtime.GOOS) + } + + cfg := &config{Listen: "uni:unix.sock"} + ln, err := cfg.dialer() + assert.Nil(t, ln) + assert.Error(t, err) + assert.Equal(t, "invalid socket DSN (tcp://:6001, unix://rpc.sock)", err.Error()) +} + +func Test_Config_DialerErrorMethod(t *testing.T) { + cfg := &config{Listen: "xinu://unix.sock"} + + ln, err := cfg.dialer() + assert.Nil(t, ln) + assert.Error(t, err) +} diff --git a/service/registry.go b/service/registry.go index e2ab0d81..0182fa93 100644 --- a/service/registry.go +++ b/service/registry.go @@ -153,10 +153,14 @@ func (r *registry) Get(service string) Service { // Serve all configured services. Non blocking. func (r *registry) Serve() error { + // todo: serving + return nil } // Close all active services. func (r *registry) Stop() error { + // todo: stopping + return nil } |