github.com/rish1988/moby@v25.0.2+incompatible/client/checkpoint_delete_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/api/types/checkpoint" 13 "github.com/docker/docker/errdefs" 14 "gotest.tools/v3/assert" 15 is "gotest.tools/v3/assert/cmp" 16 ) 17 18 func TestCheckpointDeleteError(t *testing.T) { 19 client := &Client{ 20 client: newMockClient(errorMock(http.StatusInternalServerError, "Server error")), 21 } 22 23 err := client.CheckpointDelete(context.Background(), "container_id", checkpoint.DeleteOptions{ 24 CheckpointID: "checkpoint_id", 25 }) 26 27 assert.Check(t, is.ErrorType(err, errdefs.IsSystem)) 28 } 29 30 func TestCheckpointDelete(t *testing.T) { 31 expectedURL := "/containers/container_id/checkpoints/checkpoint_id" 32 33 client := &Client{ 34 client: newMockClient(func(req *http.Request) (*http.Response, error) { 35 if !strings.HasPrefix(req.URL.Path, expectedURL) { 36 return nil, fmt.Errorf("Expected URL '%s', got '%s'", expectedURL, req.URL) 37 } 38 if req.Method != http.MethodDelete { 39 return nil, fmt.Errorf("expected DELETE method, got %s", req.Method) 40 } 41 return &http.Response{ 42 StatusCode: http.StatusOK, 43 Body: io.NopCloser(bytes.NewReader([]byte(""))), 44 }, nil 45 }), 46 } 47 48 err := client.CheckpointDelete(context.Background(), "container_id", checkpoint.DeleteOptions{ 49 CheckpointID: "checkpoint_id", 50 }) 51 if err != nil { 52 t.Fatal(err) 53 } 54 }