summaryrefslogtreecommitdiff
path: root/service
diff options
context:
space:
mode:
authorWolfy-J <[email protected]>2018-07-26 17:34:01 +0300
committerWolfy-J <[email protected]>2018-07-26 17:34:01 +0300
commita2c1861165c9f61f8ece133f2edecb9aadfabe26 (patch)
treefcd055b054d57efcb7a8289724e334460169a25f /service
parent2f73d679b884616c49f4eba3342b350c001d949f (diff)
more tests
Diffstat (limited to 'service')
-rw-r--r--service/env/config.go2
-rw-r--r--service/env/config_test.go6
-rw-r--r--service/env/service_test.go2
-rw-r--r--service/http/service_test.go60
4 files changed, 65 insertions, 5 deletions
diff --git a/service/env/config.go b/service/env/config.go
index ad7eddf5..d0ba686b 100644
--- a/service/env/config.go
+++ b/service/env/config.go
@@ -13,4 +13,4 @@ type Config struct {
// Hydrate must populate Config values using given Config source. Must return error if Config is not valid.
func (c *Config) Hydrate(cfg service.Config) error {
return cfg.Unmarshal(&c.Values)
-} \ No newline at end of file
+}
diff --git a/service/env/config_test.go b/service/env/config_test.go
index 3c943963..3ae2afbc 100644
--- a/service/env/config_test.go
+++ b/service/env/config_test.go
@@ -1,10 +1,10 @@
package env
import (
- "github.com/spiral/roadrunner/service"
"encoding/json"
- "testing"
+ "github.com/spiral/roadrunner/service"
"github.com/stretchr/testify/assert"
+ "testing"
)
type mockCfg struct{ cfg string }
@@ -26,4 +26,4 @@ func Test_Config_Hydrate_Empty(t *testing.T) {
assert.NoError(t, c.Hydrate(cfg))
assert.Len(t, c.Values, 0)
-} \ No newline at end of file
+}
diff --git a/service/env/service_test.go b/service/env/service_test.go
index 4d823468..f25e56c7 100644
--- a/service/env/service_test.go
+++ b/service/env/service_test.go
@@ -1,8 +1,8 @@
package env
import (
- "testing"
"github.com/stretchr/testify/assert"
+ "testing"
)
func Test_NewService(t *testing.T) {
diff --git a/service/http/service_test.go b/service/http/service_test.go
index b442ae51..29c263b9 100644
--- a/service/http/service_test.go
+++ b/service/http/service_test.go
@@ -13,11 +13,13 @@ import (
"os"
"testing"
"time"
+ "github.com/spiral/roadrunner/service/env"
)
type testCfg struct {
httpCfg string
rpcCfg string
+ envCfg string
target string
}
@@ -29,6 +31,11 @@ func (cfg *testCfg) Get(name string) service.Config {
if name == rpc.ID {
return &testCfg{target: cfg.rpcCfg}
}
+
+ if name == env.ID {
+ return &testCfg{target: cfg.envCfg}
+ }
+
return nil
}
func (cfg *testCfg) Unmarshal(out interface{}) error {
@@ -163,6 +170,59 @@ func Test_Service_Echo(t *testing.T) {
assert.Equal(t, "WORLD", string(b))
}
+func Test_Service_Env(t *testing.T) {
+ logger, _ := test.NewNullLogger()
+ logger.SetLevel(logrus.DebugLevel)
+
+ c := service.NewContainer(logger)
+ c.Register(env.ID, env.NewService("test"))
+ c.Register(ID, &Service{})
+
+ assert.NoError(t, c.Init(&testCfg{httpCfg: `{
+ "enable": true,
+ "address": ":6029",
+ "maxRequest": 1024,
+ "uploads": {
+ "dir": ` + tmpDir() + `,
+ "forbid": []
+ },
+ "workers":{
+ "command": "php ../../php-src/tests/http/client.php env pipes",
+ "relay": "pipes",
+ "pool": {
+ "numWorkers": 1,
+ "allocateTimeout": 10000000,
+ "destroyTimeout": 10000000
+ }
+ }
+ }`, envCfg: `{"env_key":"ENV_VALUE"}`}))
+
+ s, st := c.Get(ID)
+ assert.NotNil(t, s)
+ assert.Equal(t, service.StatusOK, st)
+
+ // should do nothing
+ s.(*Service).Stop()
+
+ go func() { c.Serve() }()
+ time.Sleep(time.Millisecond * 100)
+ defer c.Stop()
+
+ req, err := http.NewRequest("GET", "http://localhost:6029", nil)
+ assert.NoError(t, err)
+
+ r, err := http.DefaultClient.Do(req)
+ assert.NoError(t, err)
+ defer r.Body.Close()
+
+ b, err := ioutil.ReadAll(r.Body)
+ assert.NoError(t, err)
+
+ assert.NoError(t, err)
+ assert.Equal(t, 200, r.StatusCode)
+ assert.Equal(t, "ENV_VALUE", string(b))
+}
+
func Test_Service_ErrorEcho(t *testing.T) {
logger, _ := test.NewNullLogger()
logger.SetLevel(logrus.DebugLevel)