summaryrefslogtreecommitdiff
path: root/service/health/config_test.go
diff options
context:
space:
mode:
authorAlex Price <[email protected]>2019-10-12 15:02:57 +1100
committerAlex Price <[email protected]>2019-10-12 15:38:40 +1100
commitc9fdfb6e9484b9aa45e20a90e78a23d5d129308c (patch)
tree61117f89311b7b8ec2cc680128ecdd1d27d6d94e /service/health/config_test.go
parent8a840c40828c1fb31c69fc846a85738ddef0a7c7 (diff)
adds a health service for determining the status of the workers
This commit adds a health service which ensures that at least one worker is active. Uses `isActive()` to determine if the worker is ready. The health service runs on a seperate address. Will return a HTTP 200 if health, HTTP 500 otherwise. Fixes #192 Signed-off-by: Alex Price <[email protected]>
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))
+}