summaryrefslogtreecommitdiff
path: root/service/limit/config_test.go
blob: c79836b8673615ffbbfb655d09e6403b27602bf3 (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
package limit

import (
	json "github.com/json-iterator/go"
	"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 {
	j := json.ConfigCompatibleWithStandardLibrary
	return j.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{}
	err := c.InitDefaults()
	if err != nil {
		t.Errorf("failed to InitDefaults: error %v", err)
	}

	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)
}