github.com/rish1988/moby@v25.0.2+incompatible/client/checkpoint_list_test.go (about) 1 package client // import "github.com/docker/docker/client" 2 3 import ( 4 "bytes" 5 "context" 6 "encoding/json" 7 "fmt" 8 "io" 9 "net/http" 10 "strings" 11 "testing" 12 13 "github.com/docker/docker/api/types/checkpoint" 14 "github.com/docker/docker/errdefs" 15 "gotest.tools/v3/assert" 16 is "gotest.tools/v3/assert/cmp" 17 ) 18 19 func TestCheckpointListError(t *testing.T) { 20 client := &Client{ 21 client: newMockClient(errorMock(http.StatusInternalServerError, "Server error")), 22 } 23 24 _, err := client.CheckpointList(context.Background(), "container_id", checkpoint.ListOptions{}) 25 assert.Check(t, is.ErrorType(err, errdefs.IsSystem)) 26 } 27 28 func TestCheckpointList(t *testing.T) { 29 expectedURL := "/containers/container_id/checkpoints" 30 31 client := &Client{ 32 client: newMockClient(func(req *http.Request) (*http.Response, error) { 33 if !strings.HasPrefix(req.URL.Path, expectedURL) { 34 return nil, fmt.Errorf("Expected URL '%s', got '%s'", expectedURL, req.URL) 35 } 36 content, err := json.Marshal([]checkpoint.Summary{ 37 { 38 Name: "checkpoint", 39 }, 40 }) 41 if err != nil { 42 return nil, err 43 } 44 return &http.Response{ 45 StatusCode: http.StatusOK, 46 Body: io.NopCloser(bytes.NewReader(content)), 47 }, nil 48 }), 49 } 50 51 checkpoints, err := client.CheckpointList(context.Background(), "container_id", checkpoint.ListOptions{}) 52 if err != nil { 53 t.Fatal(err) 54 } 55 if len(checkpoints) != 1 { 56 t.Fatalf("expected 1 checkpoint, got %v", checkpoints) 57 } 58 } 59 60 func TestCheckpointListContainerNotFound(t *testing.T) { 61 client := &Client{ 62 client: newMockClient(errorMock(http.StatusNotFound, "Server error")), 63 } 64 65 _, err := client.CheckpointList(context.Background(), "unknown", checkpoint.ListOptions{}) 66 assert.Check(t, is.ErrorType(err, errdefs.IsNotFound)) 67 }