summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--service/http/config_test.go21
-rw-r--r--service/rpc/config_test.go21
-rw-r--r--service/static/config_test.go21
3 files changed, 63 insertions, 0 deletions
diff --git a/service/http/config_test.go b/service/http/config_test.go
index cb804f4a..86622cdf 100644
--- a/service/http/config_test.go
+++ b/service/http/config_test.go
@@ -6,8 +6,29 @@ import (
"os"
"testing"
"time"
+ "github.com/spiral/roadrunner/service"
+ "encoding/json"
)
+type mockCfg struct{ cfg string }
+
+func (cfg *mockCfg) Get(name string) service.Config { return nil }
+func (cfg *mockCfg) Unmarshal(out interface{}) error { return json.Unmarshal([]byte(cfg.cfg), out) }
+
+func Test_Config_Hydrate_Error1(t *testing.T) {
+ cfg := &mockCfg{`{"enable": true}`}
+ c := &Config{}
+
+ assert.Error(t, c.Hydrate(cfg))
+}
+
+func Test_Config_Hydrate_Error2(t *testing.T) {
+ cfg := &mockCfg{`{"dir": "/dir/"`}
+ c := &Config{}
+
+ assert.Error(t, c.Hydrate(cfg))
+}
+
func Test_Config_Valid(t *testing.T) {
cfg := &Config{
Enable: true,
diff --git a/service/rpc/config_test.go b/service/rpc/config_test.go
index 8642e9ab..95eb41b4 100644
--- a/service/rpc/config_test.go
+++ b/service/rpc/config_test.go
@@ -4,8 +4,29 @@ import (
"github.com/stretchr/testify/assert"
"runtime"
"testing"
+ "encoding/json"
+ "github.com/spiral/roadrunner/service"
)
+type testCfg struct{ cfg string }
+
+func (cfg *testCfg) Get(name string) service.Config { return nil }
+func (cfg *testCfg) Unmarshal(out interface{}) error { return json.Unmarshal([]byte(cfg.cfg), out) }
+
+func Test_Config_Hydrate(t *testing.T) {
+ cfg := &testCfg{`{"enable": true, "listen": "tcp://:18001"}`}
+ c := &Config{}
+
+ assert.NoError(t, c.Hydrate(cfg))
+}
+
+func Test_Config_Hydrate_Error(t *testing.T) {
+ cfg := &testCfg{`{"enable": true, "listen": "invalid"}`}
+ c := &Config{}
+
+ assert.Error(t, c.Hydrate(cfg))
+}
+
func TestConfig_Listener(t *testing.T) {
cfg := &Config{Listen: "tcp://:18001"}
diff --git a/service/static/config_test.go b/service/static/config_test.go
index d2099cdf..baa9776f 100644
--- a/service/static/config_test.go
+++ b/service/static/config_test.go
@@ -3,8 +3,29 @@ package static
import (
"github.com/stretchr/testify/assert"
"testing"
+ "github.com/spiral/roadrunner/service"
+ "encoding/json"
)
+type mockCfg struct{ cfg string }
+
+func (cfg *mockCfg) Get(name string) service.Config { return nil }
+func (cfg *mockCfg) Unmarshal(out interface{}) error { return json.Unmarshal([]byte(cfg.cfg), out) }
+
+func Test_Config_Hydrate(t *testing.T) {
+ cfg := &mockCfg{`{"dir": "./"}`}
+ c := &Config{}
+
+ assert.NoError(t, c.Hydrate(cfg))
+}
+
+func Test_Config_Hydrate_Error(t *testing.T) {
+ cfg := &mockCfg{`{"dir": "/dir/"}`}
+ c := &Config{}
+
+ assert.Error(t, c.Hydrate(cfg))
+}
+
func TestConfig_Forbids(t *testing.T) {
cfg := Config{Forbid: []string{".php"}}