blob: 710f9c4252a7324846ab3e10e1b53bc9bfbf5c6d (
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
|
package static
import (
json "github.com/json-iterator/go"
"github.com/spiral/roadrunner/service"
"github.com/stretchr/testify/assert"
"testing"
)
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(t *testing.T) {
cfg := &mockCfg{`{"dir": "./"}`}
c := &Config{}
assert.NoError(t, c.Hydrate(cfg))
}
func Test_Config_Hydrate_Error(t *testing.T) {
cfg := &mockCfg{`{"enable": true,"dir": "/dir/"}`}
c := &Config{}
assert.Error(t, c.Hydrate(cfg))
}
func TestConfig_Forbids(t *testing.T) {
cfg := Config{Forbid: []string{".php"}}
assert.True(t, cfg.AlwaysForbid("index.php"))
assert.True(t, cfg.AlwaysForbid("index.PHP"))
assert.True(t, cfg.AlwaysForbid("phpadmin/index.bak.php"))
assert.False(t, cfg.AlwaysForbid("index.html"))
}
func TestConfig_Valid(t *testing.T) {
assert.NoError(t, (&Config{Dir: "./"}).Valid())
assert.Error(t, (&Config{Dir: "./config.go"}).Valid())
assert.Error(t, (&Config{Dir: "./dir/"}).Valid())
}
|