Skip to content

Commit

Permalink
more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
wolfy-j committed Jul 9, 2018
1 parent c691f2b commit 528eb2c
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 0 deletions.
21 changes: 21 additions & 0 deletions service/http/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,29 @@ import (
"os"
"testing"
"time"
"github.com/spiral/roadrunner/service"
"encoding/json"
)

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_Config_Hydrate_Error2(t *testing.T) {
cfg := &mockCfg{`{"dir": "/dir/"`}
c := &Config{}

assert.Error(t, c.Hydrate(cfg))
}

func Test_Config_Valid(t *testing.T) {
cfg := &Config{
Enable: true,
Expand Down
21 changes: 21 additions & 0 deletions service/rpc/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,29 @@ import (
"github.com/stretchr/testify/assert"
"runtime"
"testing"
"encoding/json"
"github.com/spiral/roadrunner/service"
)

type testCfg struct{ cfg string }

func (cfg *testCfg) Get(name string) service.Config { return nil }
func (cfg *testCfg) Unmarshal(out interface{}) error { return json.Unmarshal([]byte(cfg.cfg), out) }

func Test_Config_Hydrate(t *testing.T) {
cfg := &testCfg{`{"enable": true, "listen": "tcp://:18001"}`}
c := &Config{}

assert.NoError(t, c.Hydrate(cfg))
}

func Test_Config_Hydrate_Error(t *testing.T) {
cfg := &testCfg{`{"enable": true, "listen": "invalid"}`}
c := &Config{}

assert.Error(t, c.Hydrate(cfg))
}

func TestConfig_Listener(t *testing.T) {
cfg := &Config{Listen: "tcp://:18001"}

Expand Down
21 changes: 21 additions & 0 deletions service/static/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,29 @@ package static
import (
"github.com/stretchr/testify/assert"
"testing"
"github.com/spiral/roadrunner/service"
"encoding/json"
)

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{`{"dir": "/dir/"}`}
c := &Config{}

assert.Error(t, c.Hydrate(cfg))
}

func TestConfig_Forbids(t *testing.T) {
cfg := Config{Forbid: []string{".php"}}

Expand Down

0 comments on commit 528eb2c

Please sign in to comment.