github.com/khulnasoft-lab/khulnasoft@v26.0.1-0.20240328202558-330a6f959fe0+incompatible/client/container_kill_test.go (about) 1 package client // import "github.com/docker/docker/client" 2 3 import ( 4 "bytes" 5 "context" 6 "fmt" 7 "io" 8 "net/http" 9 "strings" 10 "testing" 11 12 "github.com/docker/docker/errdefs" 13 "gotest.tools/v3/assert" 14 is "gotest.tools/v3/assert/cmp" 15 ) 16 17 func TestContainerKillError(t *testing.T) { 18 client := &Client{ 19 client: newMockClient(errorMock(http.StatusInternalServerError, "Server error")), 20 } 21 err := client.ContainerKill(context.Background(), "nothing", "SIGKILL") 22 assert.Check(t, is.ErrorType(err, errdefs.IsSystem)) 23 } 24 25 func TestContainerKill(t *testing.T) { 26 expectedURL := "/containers/container_id/kill" 27 client := &Client{ 28 client: newMockClient(func(req *http.Request) (*http.Response, error) { 29 if !strings.HasPrefix(req.URL.Path, expectedURL) { 30 return nil, fmt.Errorf("Expected URL '%s', got '%s'", expectedURL, req.URL) 31 } 32 signal := req.URL.Query().Get("signal") 33 if signal != "SIGKILL" { 34 return nil, fmt.Errorf("signal not set in URL query properly. Expected 'SIGKILL', got %s", signal) 35 } 36 return &http.Response{ 37 StatusCode: http.StatusOK, 38 Body: io.NopCloser(bytes.NewReader([]byte(""))), 39 }, nil 40 }), 41 } 42 43 err := client.ContainerKill(context.Background(), "container_id", "SIGKILL") 44 if err != nil { 45 t.Fatal(err) 46 } 47 }