github.com/Prakhar-Agarwal-byte/moby@v0.0.0-20231027092010-a14e3e8ab87e/client/volume_remove_test.go (about) 1 package client // import "github.com/Prakhar-Agarwal-byte/moby/client" 2 3 import ( 4 "bytes" 5 "context" 6 "fmt" 7 "io" 8 "net/http" 9 "strings" 10 "testing" 11 12 "github.com/Prakhar-Agarwal-byte/moby/errdefs" 13 "gotest.tools/v3/assert" 14 is "gotest.tools/v3/assert/cmp" 15 ) 16 17 func TestVolumeRemoveError(t *testing.T) { 18 client := &Client{ 19 client: newMockClient(errorMock(http.StatusInternalServerError, "Server error")), 20 } 21 22 err := client.VolumeRemove(context.Background(), "volume_id", false) 23 assert.Check(t, is.ErrorType(err, errdefs.IsSystem)) 24 } 25 26 func TestVolumeRemove(t *testing.T) { 27 expectedURL := "/volumes/volume_id" 28 29 client := &Client{ 30 client: newMockClient(func(req *http.Request) (*http.Response, error) { 31 if !strings.HasPrefix(req.URL.Path, expectedURL) { 32 return nil, fmt.Errorf("Expected URL '%s', got '%s'", expectedURL, req.URL) 33 } 34 if req.Method != http.MethodDelete { 35 return nil, fmt.Errorf("expected DELETE method, got %s", req.Method) 36 } 37 return &http.Response{ 38 StatusCode: http.StatusOK, 39 Body: io.NopCloser(bytes.NewReader([]byte("body"))), 40 }, nil 41 }), 42 } 43 44 err := client.VolumeRemove(context.Background(), "volume_id", false) 45 if err != nil { 46 t.Fatal(err) 47 } 48 }