migrate TestContainerAPIPostContainerStop to integration

Migrates:

- TestContainerAPIPostContainerStop

Signed-off-by: Yudai Nakakubo <nyggl4dev@gmail.com>
This commit is contained in:
Yudai Nakakubo
2026-01-17 11:59:52 +09:00
parent 397c7d65cc
commit ef5287fb08
2 changed files with 60 additions and 13 deletions

View File

@@ -953,19 +953,6 @@ func (s *DockerAPISuite) TestContainerAPIChunkedEncoding(c *testing.T) {
assert.Equal(c, resp.StatusCode, http.StatusCreated)
}
func (s *DockerAPISuite) TestContainerAPIPostContainerStop(c *testing.T) {
containerID := runSleepingContainer(c)
cli.WaitRun(c, containerID)
apiClient, err := client.New(client.FromEnv)
assert.NilError(c, err)
defer apiClient.Close()
_, err = apiClient.ContainerStop(testutil.GetContext(c), containerID, client.ContainerStopOptions{})
assert.NilError(c, err)
assert.NilError(c, waitInspect(containerID, "{{ .State.Running }}", "false", 60*time.Second))
}
// Ensure an error occurs when you have a container read-only rootfs but you
// extract an archive to a symlink in a writable volume which points to a
// directory outside of the volume.

View File

@@ -1,12 +1,15 @@
package container
import (
"net/http"
"testing"
"time"
"github.com/moby/moby/api/types/common"
containertypes "github.com/moby/moby/api/types/container"
"github.com/moby/moby/client"
"github.com/moby/moby/v2/integration/internal/container"
"github.com/moby/moby/v2/internal/testutil/request"
"gotest.tools/v3/assert"
is "gotest.tools/v3/assert/cmp"
"gotest.tools/v3/poll"
@@ -111,3 +114,60 @@ func TestStopContainerWithTimeout(t *testing.T) {
})
}
}
func TestContainerAPIPostContainerStop(t *testing.T) {
apiClient := testEnv.APIClient()
ctx := setupTest(t)
tests := []struct {
testName string
id string
expStatusCode int
expError string
checkContainerState bool
expStateRunning bool
}{
{
testName: "no error",
id: container.Run(ctx, t, apiClient),
expStatusCode: http.StatusNoContent,
checkContainerState: true,
expStateRunning: false,
},
{
testName: "container already stopped",
id: container.Create(ctx, t, apiClient),
expStatusCode: http.StatusNotModified,
checkContainerState: true,
expStateRunning: false,
},
{
testName: "no such container",
id: "test1234",
expStatusCode: http.StatusNotFound,
expError: `No such container: test1234`,
checkContainerState: false,
},
}
for _, tc := range tests {
t.Run(tc.testName, func(t *testing.T) {
res, _, err := request.Post(ctx, "/containers/"+tc.id+"/stop")
assert.Equal(t, res.StatusCode, tc.expStatusCode)
assert.NilError(t, err)
if tc.expError != "" {
var respErr common.ErrorResponse
assert.NilError(t, request.ReadJSONResponse(res, &respErr))
assert.ErrorContains(t, respErr, tc.expError)
}
if tc.checkContainerState {
inspectRes := container.Inspect(ctx, t, apiClient, tc.id)
assert.Equal(t, inspectRes.State.Running, tc.expStateRunning)
}
})
}
}