blob: 9068f2ca9377ac6ec7cbe29212169cb2de6da367 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
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))
}
|