github.com/jwhonce/docker@v0.6.7-0.20190327063223-da823cf3a5a3/integration/plugin/common/plugin_test.go (about) 1 package common // import "github.com/docker/docker/integration/plugin/common" 2 3 import ( 4 "net/http" 5 "testing" 6 7 "github.com/docker/docker/internal/test/request" 8 "gotest.tools/assert" 9 is "gotest.tools/assert/cmp" 10 ) 11 12 func TestPluginInvalidJSON(t *testing.T) { 13 defer setupTest(t)() 14 15 endpoints := []string{"/plugins/foobar/set"} 16 17 for _, ep := range endpoints { 18 t.Run(ep, func(t *testing.T) { 19 t.Parallel() 20 21 res, body, err := request.Post(ep, request.RawString("{invalid json"), request.JSON) 22 assert.NilError(t, err) 23 assert.Equal(t, res.StatusCode, http.StatusBadRequest) 24 25 buf, err := request.ReadBody(body) 26 assert.NilError(t, err) 27 assert.Check(t, is.Contains(string(buf), "invalid character 'i' looking for beginning of object key string")) 28 29 res, body, err = request.Post(ep, request.JSON) 30 assert.NilError(t, err) 31 assert.Equal(t, res.StatusCode, http.StatusBadRequest) 32 33 buf, err = request.ReadBody(body) 34 assert.NilError(t, err) 35 assert.Check(t, is.Contains(string(buf), "got EOF while reading request body")) 36 }) 37 } 38 }