github.com/demonoid81/moby@v0.0.0-20200517203328-62dd8e17c460/integration/container/container_test.go (about) 1 package container // import "github.com/demonoid81/moby/integration/container" 2 3 import ( 4 "net/http" 5 "testing" 6 7 "github.com/demonoid81/moby/testutil/request" 8 "gotest.tools/v3/assert" 9 is "gotest.tools/v3/assert/cmp" 10 ) 11 12 func TestContainerInvalidJSON(t *testing.T) { 13 defer setupTest(t)() 14 15 endpoints := []string{ 16 "/containers/foobar/copy", 17 "/containers/foobar/exec", 18 "/exec/foobar/start", 19 } 20 21 for _, ep := range endpoints { 22 t.Run(ep, func(t *testing.T) { 23 t.Parallel() 24 25 res, body, err := request.Post(ep, request.RawString("{invalid json"), request.JSON) 26 assert.NilError(t, err) 27 assert.Equal(t, res.StatusCode, http.StatusBadRequest) 28 29 buf, err := request.ReadBody(body) 30 assert.NilError(t, err) 31 assert.Check(t, is.Contains(string(buf), "invalid character 'i' looking for beginning of object key string")) 32 33 res, body, err = request.Post(ep, request.JSON) 34 assert.NilError(t, err) 35 assert.Equal(t, res.StatusCode, http.StatusBadRequest) 36 37 buf, err = request.ReadBody(body) 38 assert.NilError(t, err) 39 assert.Check(t, is.Contains(string(buf), "got EOF while reading request body")) 40 }) 41 } 42 }