checkpoint_delete_test.go 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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/checkpoint"
  11. "github.com/docker/docker/errdefs"
  12. "gotest.tools/v3/assert"
  13. is "gotest.tools/v3/assert/cmp"
  14. )
  15. func TestCheckpointDeleteError(t *testing.T) {
  16. client := &Client{
  17. client: newMockClient(errorMock(http.StatusInternalServerError, "Server error")),
  18. }
  19. err := client.CheckpointDelete(context.Background(), "container_id", checkpoint.DeleteOptions{
  20. CheckpointID: "checkpoint_id",
  21. })
  22. assert.Check(t, is.ErrorType(err, errdefs.IsSystem))
  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", checkpoint.DeleteOptions{
  41. CheckpointID: "checkpoint_id",
  42. })
  43. if err != nil {
  44. t.Fatal(err)
  45. }
  46. }