github.com/ssdev-go/moby@v17.12.1-ce-rc2+incompatible/client/volume_remove_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 "golang.org/x/net/context" 12 ) 13 14 func TestVolumeRemoveError(t *testing.T) { 15 client := &Client{ 16 client: newMockClient(errorMock(http.StatusInternalServerError, "Server error")), 17 } 18 19 err := client.VolumeRemove(context.Background(), "volume_id", false) 20 if err == nil || err.Error() != "Error response from daemon: Server error" { 21 t.Fatalf("expected a Server Error, got %v", err) 22 } 23 } 24 25 func TestVolumeRemove(t *testing.T) { 26 expectedURL := "/volumes/volume_id" 27 28 client := &Client{ 29 client: newMockClient(func(req *http.Request) (*http.Response, error) { 30 if !strings.HasPrefix(req.URL.Path, expectedURL) { 31 return nil, fmt.Errorf("Expected URL '%s', got '%s'", expectedURL, req.URL) 32 } 33 if req.Method != "DELETE" { 34 return nil, fmt.Errorf("expected DELETE method, got %s", req.Method) 35 } 36 return &http.Response{ 37 StatusCode: http.StatusOK, 38 Body: ioutil.NopCloser(bytes.NewReader([]byte("body"))), 39 }, nil 40 }), 41 } 42 43 err := client.VolumeRemove(context.Background(), "volume_id", false) 44 if err != nil { 45 t.Fatal(err) 46 } 47 }