mirror of
https://github.com/moby/moby.git
synced 2026-08-12 22:16:46 +00:00
Add option- and output structs for; - Client.ContainerKill - Client.ContainerPause - Client.ContainerRemove - Client.ContainerResize - Client.ContainerRestart - Client.ContainerStart - Client.ContainerStop - Client.ContainerUnpause Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
55 lines
1.6 KiB
Go
55 lines
1.6 KiB
Go
package client
|
|
|
|
import (
|
|
"fmt"
|
|
"net/http"
|
|
"testing"
|
|
|
|
cerrdefs "github.com/containerd/errdefs"
|
|
"gotest.tools/v3/assert"
|
|
is "gotest.tools/v3/assert/cmp"
|
|
)
|
|
|
|
func TestContainerKillError(t *testing.T) {
|
|
client, err := NewClientWithOpts(
|
|
WithMockClient(errorMock(http.StatusInternalServerError, "Server error")),
|
|
)
|
|
assert.NilError(t, err)
|
|
|
|
_, err = client.ContainerKill(t.Context(), "nothing", ContainerKillOptions{
|
|
Signal: "SIGKILL",
|
|
})
|
|
assert.Check(t, is.ErrorType(err, cerrdefs.IsInternal))
|
|
|
|
_, err = client.ContainerKill(t.Context(), "", ContainerKillOptions{})
|
|
assert.Check(t, is.ErrorType(err, cerrdefs.IsInvalidArgument))
|
|
assert.Check(t, is.ErrorContains(err, "value is empty"))
|
|
|
|
_, err = client.ContainerKill(t.Context(), " ", ContainerKillOptions{})
|
|
assert.Check(t, is.ErrorType(err, cerrdefs.IsInvalidArgument))
|
|
assert.Check(t, is.ErrorContains(err, "value is empty"))
|
|
}
|
|
|
|
func TestContainerKill(t *testing.T) {
|
|
const expectedURL = "/containers/container_id/kill"
|
|
const expectedSignal = "SIG_SOMETHING"
|
|
client, err := NewClientWithOpts(
|
|
WithMockClient(func(req *http.Request) (*http.Response, error) {
|
|
if err := assertRequest(req, http.MethodPost, expectedURL); err != nil {
|
|
return nil, err
|
|
}
|
|
signal := req.URL.Query().Get("signal")
|
|
if signal != expectedSignal {
|
|
return nil, fmt.Errorf("signal not set in URL query properly. Expected '%s', got %s", expectedSignal, signal)
|
|
}
|
|
return mockResponse(http.StatusOK, nil, "")(req)
|
|
}),
|
|
)
|
|
assert.NilError(t, err)
|
|
|
|
_, err = client.ContainerKill(t.Context(), "container_id", ContainerKillOptions{
|
|
Signal: expectedSignal,
|
|
})
|
|
assert.NilError(t, err)
|
|
}
|