diff options
author | Dmitry Patsura <[email protected]> | 2019-06-13 20:34:34 +0300 |
---|---|---|
committer | Dmitry Patsura <[email protected]> | 2019-06-13 20:34:34 +0300 |
commit | be46c93e500a775306e4fc71661657d49fa52c54 (patch) | |
tree | 2572b5dd043fe90ab1c23a6527ed4fd4b57b28db /service/http/fcgi_test.go | |
parent | e8ea2418e55869be8fb908f612e4a8dd122bc5e9 (diff) |
Feature(tests): Implement Test_FCGI_Service_Echo
Diffstat (limited to 'service/http/fcgi_test.go')
-rw-r--r-- | service/http/fcgi_test.go | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/service/http/fcgi_test.go b/service/http/fcgi_test.go new file mode 100644 index 00000000..d053ce03 --- /dev/null +++ b/service/http/fcgi_test.go @@ -0,0 +1,60 @@ +package http + +import ( + "github.com/sirupsen/logrus" + "github.com/sirupsen/logrus/hooks/test" + "github.com/spiral/roadrunner/service" + "github.com/stretchr/testify/assert" + "io/ioutil" + "net/http/httptest" + "testing" + "time" + "github.com/yookoala/gofast" +) + +func Test_FCGI_Service_Echo(t *testing.T) { + logger, _ := test.NewNullLogger() + logger.SetLevel(logrus.DebugLevel) + + c := service.NewContainer(logger) + c.Register(ID, &Service{}) + + assert.NoError(t, c.Init(&testCfg{httpCfg: `{ + "address": ":6029", + "fcgi": { + "address": "tcp://0.0.0.0:6082" + }, + "workers":{ + "command": "php ../../tests/http/client.php echo pipes", + "pool": {"numWorkers": 1} + } + }`})) + + s, st := c.Get(ID) + assert.NotNil(t, s) + assert.Equal(t, service.StatusOK, st) + + // should do nothing + s.(*Service).Stop() + + go func() { assert.NoError(t, c.Serve()) }() + time.Sleep(time.Millisecond * 100) + defer c.Stop() + + fcgiConnFactory := gofast.SimpleConnFactory("tcp", "0.0.0.0:6082") + + fcgiHandler := gofast.NewHandler( + gofast.BasicParamsMap(gofast.BasicSession), + gofast.SimpleClientFactory(fcgiConnFactory, 0), + ) + + w := httptest.NewRecorder() + req := httptest.NewRequest("GET", "http://site.local/?hello=world", nil) + fcgiHandler.ServeHTTP(w, req) + + body, err := ioutil.ReadAll(w.Result().Body); + + assert.NoError(t, err) + assert.Equal(t, 201, w.Result().StatusCode) + assert.Equal(t, "WORLD", string(body)) +} |