github.com/gravitational/moby@v1.13.1/client/checkpoint_delete_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 "github.com/docker/docker/api/types" 12 "golang.org/x/net/context" 13 ) 14 15 func TestCheckpointDeleteError(t *testing.T) { 16 client := &Client{ 17 client: newMockClient(errorMock(http.StatusInternalServerError, "Server error")), 18 } 19 20 err := client.CheckpointDelete(context.Background(), "container_id", types.CheckpointDeleteOptions{ 21 CheckpointID: "checkpoint_id", 22 }) 23 24 if err == nil || err.Error() != "Error response from daemon: Server error" { 25 t.Fatalf("expected a Server Error, got %v", err) 26 } 27 } 28 29 func TestCheckpointDelete(t *testing.T) { 30 expectedURL := "/containers/container_id/checkpoints/checkpoint_id" 31 32 client := &Client{ 33 client: newMockClient(func(req *http.Request) (*http.Response, error) { 34 if !strings.HasPrefix(req.URL.Path, expectedURL) { 35 return nil, fmt.Errorf("Expected URL '%s', got '%s'", expectedURL, req.URL) 36 } 37 if req.Method != "DELETE" { 38 return nil, fmt.Errorf("expected DELETE method, got %s", req.Method) 39 } 40 return &http.Response{ 41 StatusCode: http.StatusOK, 42 Body: ioutil.NopCloser(bytes.NewReader([]byte(""))), 43 }, nil 44 }), 45 } 46 47 err := client.CheckpointDelete(context.Background(), "container_id", types.CheckpointDeleteOptions{ 48 CheckpointID: "checkpoint_id", 49 }) 50 51 if err != nil { 52 t.Fatal(err) 53 } 54 }