container_kill_test.go 1.2 KB

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