diff options
author | Wolfy-J <[email protected]> | 2018-06-13 23:31:00 +0300 |
---|---|---|
committer | Wolfy-J <[email protected]> | 2018-06-13 23:31:00 +0300 |
commit | ee109928585b44194160db4861f0f189bb39f82a (patch) | |
tree | c169d9da90faf1184bdc2afba70c34f04a5290a6 /service/static | |
parent | 5c6bb6336f0ad653091065bff72b44119170ab2b (diff) |
more static service tests
Diffstat (limited to 'service/static')
-rw-r--r-- | service/static/service_test.go | 98 |
1 files changed, 98 insertions, 0 deletions
diff --git a/service/static/service_test.go b/service/static/service_test.go index c17b4388..f0cb1bea 100644 --- a/service/static/service_test.go +++ b/service/static/service_test.go @@ -84,6 +84,104 @@ func Test_Files(t *testing.T) { assert.Equal(t, "sample", b) } + +func Test_Files_Disable(t *testing.T) { + logger, _ := test.NewNullLogger() + logger.SetLevel(logrus.DebugLevel) + + c := service.NewContainer(logger) + c.Register(rrhttp.ID, &rrhttp.Service{}) + c.Register(ID, &Service{}) + + assert.NoError(t, c.Init(&testCfg{ + static: `{"enable":false, "dir":"../../php-src/tests", "forbid":[".php"]}`, + httpCfg: `{ + "enable": true, + "address": ":6029", + "maxRequest": 1024, + "uploads": { + "dir": ` + tmpDir() + `, + "forbid": [] + }, + "workers":{ + "command": "php ../../php-src/tests/http/client.php echo pipes", + "relay": "pipes", + "pool": { + "numWorkers": 1, + "allocateTimeout": 10000000, + "destroyTimeout": 10000000 + } + } + }`})) + + go func() { c.Serve() }() + time.Sleep(time.Millisecond * 100) + defer c.Stop() + + b, _, _ := get("http://localhost:6029/client.php?hello=world") + assert.Equal(t, "WORLD", b) +} + +func Test_Files_Error(t *testing.T) { + logger, _ := test.NewNullLogger() + logger.SetLevel(logrus.DebugLevel) + + c := service.NewContainer(logger) + c.Register(rrhttp.ID, &rrhttp.Service{}) + c.Register(ID, &Service{}) + + assert.Error(t, c.Init(&testCfg{ + static: `{"enable":true, "dir":"dir/invalid", "forbid":[".php"]}`, + httpCfg: `{ + "enable": true, + "address": ":6029", + "maxRequest": 1024, + "uploads": { + "dir": ` + tmpDir() + `, + "forbid": [] + }, + "workers":{ + "command": "php ../../php-src/tests/http/client.php echo pipes", + "relay": "pipes", + "pool": { + "numWorkers": 1, + "allocateTimeout": 10000000, + "destroyTimeout": 10000000 + } + } + }`})) +} + +func Test_Files_Error2(t *testing.T) { + logger, _ := test.NewNullLogger() + logger.SetLevel(logrus.DebugLevel) + + c := service.NewContainer(logger) + c.Register(rrhttp.ID, &rrhttp.Service{}) + c.Register(ID, &Service{}) + + assert.Error(t, c.Init(&testCfg{ + static: `{"enable":true, "dir":"dir/invalid", "forbid":[".php"]`, + httpCfg: `{ + "enable": true, + "address": ":6029", + "maxRequest": 1024, + "uploads": { + "dir": ` + tmpDir() + `, + "forbid": [] + }, + "workers":{ + "command": "php ../../php-src/tests/http/client.php echo pipes", + "relay": "pipes", + "pool": { + "numWorkers": 1, + "allocateTimeout": 10000000, + "destroyTimeout": 10000000 + } + } + }`})) +} + func Test_Files_Forbid(t *testing.T) { logger, _ := test.NewNullLogger() logger.SetLevel(logrus.DebugLevel) |