github.com/lacework-dev/go-moby@v20.10.12+incompatible/integration/container/container_test.go (about)

     1  package container // import "github.com/docker/docker/integration/container"
     2  
     3  import (
     4  	"net/http"
     5  	"testing"
     6  
     7  	"github.com/docker/docker/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  }