checkpoint_delete_test.go 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. package client // import "github.com/docker/docker/client"
  2. import (
  3. "bytes"
  4. "context"
  5. "fmt"
  6. "io"
  7. "net/http"
  8. "strings"
  9. "testing"
  10. "github.com/docker/docker/api/types"
  11. "github.com/docker/docker/errdefs"
  12. )
  13. func TestCheckpointDeleteError(t *testing.T) {
  14. client := &Client{
  15. client: newMockClient(errorMock(http.StatusInternalServerError, "Server error")),
  16. }
  17. err := client.CheckpointDelete(context.Background(), "container_id", types.CheckpointDeleteOptions{
  18. CheckpointID: "checkpoint_id",
  19. })
  20. if !errdefs.IsSystem(err) {
  21. t.Fatalf("expected a Server Error, got %[1]T: %[1]v", err)
  22. }
  23. }
  24. func TestCheckpointDelete(t *testing.T) {
  25. expectedURL := "/containers/container_id/checkpoints/checkpoint_id"
  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. if req.Method != http.MethodDelete {
  32. return nil, fmt.Errorf("expected DELETE method, got %s", req.Method)
  33. }
  34. return &http.Response{
  35. StatusCode: http.StatusOK,
  36. Body: io.NopCloser(bytes.NewReader([]byte(""))),
  37. }, nil
  38. }),
  39. }
  40. err := client.CheckpointDelete(context.Background(), "container_id", types.CheckpointDeleteOptions{
  41. CheckpointID: "checkpoint_id",
  42. })
  43. if err != nil {
  44. t.Fatal(err)
  45. }
  46. }