summaryrefslogtreecommitdiff
path: root/service/health/config_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'service/health/config_test.go')
-rw-r--r--service/health/config_test.go43
1 files changed, 43 insertions, 0 deletions
diff --git a/service/health/config_test.go b/service/health/config_test.go
new file mode 100644
index 00000000..9068f2ca
--- /dev/null
+++ b/service/health/config_test.go
@@ -0,0 +1,43 @@
+package health
+
+import (
+ "encoding/json"
+ "testing"
+
+ "github.com/spiral/roadrunner/service"
+ "github.com/stretchr/testify/assert"
+)
+
+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{`{"address": "localhost:8080"}`}
+ c := &Config{}
+
+ assert.NoError(t, c.Hydrate(cfg))
+ assert.Equal(t, "localhost:8080", c.Address)
+}
+
+func Test_Config_Hydrate_Error2(t *testing.T) {
+ cfg := &mockCfg{`{"dir": "/dir/"`}
+ c := &Config{}
+
+ assert.Error(t, c.Hydrate(cfg))
+}
+
+func Test_Config_Hydrate_Valid1(t *testing.T) {
+ cfg := &mockCfg{`{"address": "localhost"}`}
+ c := &Config{}
+
+ assert.Error(t, c.Hydrate(cfg))
+}
+
+func Test_Config_Hydrate_Valid2(t *testing.T) {
+ cfg := &mockCfg{`{"address": ":1111"}`}
+ c := &Config{}
+
+ assert.NoError(t, c.Hydrate(cfg))
+}