blob: b8a6c0aa04abc9cf7ab48b7a291b4fd93e330a3c (
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
|
package limit
import (
"encoding/json"
"github.com/spiral/roadrunner/service"
"github.com/stretchr/testify/assert"
"testing"
"time"
)
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{`{"enable: true}`}
c := &Config{}
assert.Error(t, c.Hydrate(cfg))
}
func Test_Controller_Default(t *testing.T) {
cfg := &mockCfg{`
{
"services":{
"http": {
"TTL": 1
}
}
}
`}
c := &Config{}
c.InitDefaults()
assert.NoError(t, c.Hydrate(cfg))
assert.Equal(t, time.Second, c.Interval)
list := c.Controllers(func(event int, ctx interface{}) {
})
sc := list["http"]
assert.Equal(t, time.Second, sc.(*controller).tick)
}
|