From ee109928585b44194160db4861f0f189bb39f82a Mon Sep 17 00:00:00 2001 From: Wolfy-J Date: Wed, 13 Jun 2018 23:31:00 +0300 Subject: more static service tests --- service/static/service_test.go | 98 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 98 insertions(+) (limited to 'service') 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) -- cgit v1.2.3