blob: 28191c6b6cc31d2cbeb531ced171e4a0d4de6b93 (
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
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))
}
|