github.com/kinvolk/docker@v1.13.1/client/container_kill_test.go (about) 1 package client 2 3 import ( 4 "bytes" 5 "fmt" 6 "io/ioutil" 7 "net/http" 8 "strings" 9 "testing" 10 11 "golang.org/x/net/context" 12 ) 13 14 func TestContainerKillError(t *testing.T) { 15 client := &Client{ 16 client: newMockClient(errorMock(http.StatusInternalServerError, "Server error")), 17 } 18 err := client.ContainerKill(context.Background(), "nothing", "SIGKILL") 19 if err == nil || err.Error() != "Error response from daemon: Server error" { 20 t.Fatalf("expected a Server Error, got %v", err) 21 } 22 } 23 24 func TestContainerKill(t *testing.T) { 25 expectedURL := "/containers/container_id/kill" 26 client := &Client{ 27 client: newMockClient(func(req *http.Request) (*http.Response, error) { 28 if !strings.HasPrefix(req.URL.Path, expectedURL) { 29 return nil, fmt.Errorf("Expected URL '%s', got '%s'", expectedURL, req.URL) 30 } 31 signal := req.URL.Query().Get("signal") 32 if signal != "SIGKILL" { 33 return nil, fmt.Errorf("signal not set in URL query properly. Expected 'SIGKILL', got %s", signal) 34 } 35 return &http.Response{ 36 StatusCode: http.StatusOK, 37 Body: ioutil.NopCloser(bytes.NewReader([]byte(""))), 38 }, nil 39 }), 40 } 41 42 err := client.ContainerKill(context.Background(), "container_id", "SIGKILL") 43 if err != nil { 44 t.Fatal(err) 45 } 46 }