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 | |
parent | e8ea2418e55869be8fb908f612e4a8dd122bc5e9 (diff) |
Feature(tests): Implement Test_FCGI_Service_Echo
-rw-r--r-- | go.mod | 9 | ||||
-rw-r--r-- | service/http/fcgi_test.go | 60 |
2 files changed, 67 insertions, 2 deletions
@@ -1,22 +1,27 @@ module github.com/spiral/roadrunner require ( + github.com/BurntSushi/toml v0.3.1 // indirect github.com/StackExchange/wmi v0.0.0-20181212234831-e0a55b97c705 // indirect github.com/buger/goterm v0.0.0-20181115115552-c206103e1f37 github.com/dustin/go-humanize v1.0.0 github.com/go-ole/go-ole v1.2.4 // indirect + github.com/inconshreveable/mousetrap v1.0.0 // indirect + github.com/kr/pretty v0.1.0 // indirect github.com/mattn/go-colorable v0.1.1 // indirect github.com/mattn/go-runewidth v0.0.4 // indirect github.com/mgutz/ansi v0.0.0-20170206155736-9520e82c474b github.com/olekukonko/tablewriter v0.0.1 github.com/pkg/errors v0.8.1 github.com/shirou/gopsutil v2.17.12+incompatible + github.com/shirou/w32 v0.0.0-20160930032740-bb4de0191aa4 // indirect github.com/sirupsen/logrus v1.3.0 github.com/spf13/cobra v0.0.3 github.com/spf13/viper v1.3.1 github.com/spiral/goridge v2.1.3+incompatible - github.com/spiral/jobs v1.1.1 // indirect - github.com/spiral/php-grpc v1.0.6 // indirect github.com/stretchr/testify v1.2.2 + github.com/yookoala/gofast v0.3.0 golang.org/x/net v0.0.0-20181017193950-04a2e542c03f + golang.org/x/tools v0.0.0-20180828015842-6cd1fcedba52 // indirect + gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 // indirect ) 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)) +} |