summaryrefslogtreecommitdiff
path: root/plugins/broadcast/root/config_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/broadcast/root/config_test.go')
-rw-r--r--plugins/broadcast/root/config_test.go60
1 files changed, 60 insertions, 0 deletions
diff --git a/plugins/broadcast/root/config_test.go b/plugins/broadcast/root/config_test.go
new file mode 100644
index 00000000..28191c6b
--- /dev/null
+++ b/plugins/broadcast/root/config_test.go
@@ -0,0 +1,60 @@
+package broadcast
+
+import (
+ "encoding/json"
+ "testing"
+
+ "github.com/spiral/roadrunner/service"
+ "github.com/spiral/roadrunner/service/rpc"
+ "github.com/stretchr/testify/assert"
+)
+
+type testCfg struct {
+ rpc string
+ broadcast string
+ target string
+}
+
+func (cfg *testCfg) Get(name string) service.Config {
+ if name == ID {
+ return &testCfg{target: cfg.broadcast}
+ }
+
+ if name == rpc.ID {
+ return &testCfg{target: cfg.rpc}
+ }
+
+ return nil
+}
+
+func (cfg *testCfg) Unmarshal(out interface{}) error {
+ return json.Unmarshal([]byte(cfg.target), out)
+}
+
+func Test_Config_Hydrate_Error(t *testing.T) {
+ cfg := &testCfg{target: `{"dead`}
+ c := &Config{}
+
+ assert.Error(t, c.Hydrate(cfg))
+}
+
+func Test_Config_Hydrate_OK(t *testing.T) {
+ cfg := &testCfg{target: `{"path":"/path"}`}
+ c := &Config{}
+
+ assert.NoError(t, c.Hydrate(cfg))
+}
+
+func Test_Config_Redis_Error(t *testing.T) {
+ cfg := &testCfg{target: `{"path":"/path","redis":{}}`}
+ c := &Config{}
+
+ assert.Error(t, c.Hydrate(cfg))
+}
+
+func Test_Config_Redis_OK(t *testing.T) {
+ cfg := &testCfg{target: `{"path":"/path","redis":{"addr":"localhost:6379"}}`}
+ c := &Config{}
+
+ assert.NoError(t, c.Hydrate(cfg))
+}