github.com/rish1988/moby@v25.0.2+incompatible/client/volume_update_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/swarm" 13 volumetypes "github.com/docker/docker/api/types/volume" 14 "github.com/docker/docker/errdefs" 15 "gotest.tools/v3/assert" 16 is "gotest.tools/v3/assert/cmp" 17 ) 18 19 func TestVolumeUpdateError(t *testing.T) { 20 client := &Client{ 21 client: newMockClient(errorMock(http.StatusInternalServerError, "Server error")), 22 } 23 24 err := client.VolumeUpdate(context.Background(), "", swarm.Version{}, volumetypes.UpdateOptions{}) 25 assert.Check(t, is.ErrorType(err, errdefs.IsSystem)) 26 } 27 28 func TestVolumeUpdate(t *testing.T) { 29 expectedURL := "/volumes/test1" 30 expectedVersion := "version=10" 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 != http.MethodPut { 38 return nil, fmt.Errorf("expected PUT method, got %s", req.Method) 39 } 40 if !strings.Contains(req.URL.RawQuery, expectedVersion) { 41 return nil, fmt.Errorf("expected query to contain '%s', got '%s'", expectedVersion, req.URL.RawQuery) 42 } 43 return &http.Response{ 44 StatusCode: http.StatusOK, 45 Body: io.NopCloser(bytes.NewReader([]byte("body"))), 46 }, nil 47 }), 48 } 49 50 err := client.VolumeUpdate(context.Background(), "test1", swarm.Version{Index: uint64(10)}, volumetypes.UpdateOptions{}) 51 if err != nil { 52 t.Fatal(err) 53 } 54 }