|
@@ -10,6 +10,9 @@ import (
|
|
"testing"
|
|
"testing"
|
|
|
|
|
|
"github.com/docker/docker/api/types"
|
|
"github.com/docker/docker/api/types"
|
|
|
|
+ "github.com/docker/docker/internal/testutil"
|
|
|
|
+ "github.com/stretchr/testify/assert"
|
|
|
|
+ "github.com/stretchr/testify/require"
|
|
"golang.org/x/net/context"
|
|
"golang.org/x/net/context"
|
|
)
|
|
)
|
|
|
|
|
|
@@ -19,9 +22,7 @@ func TestVolumeInspectError(t *testing.T) {
|
|
}
|
|
}
|
|
|
|
|
|
_, err := client.VolumeInspect(context.Background(), "nothing")
|
|
_, err := client.VolumeInspect(context.Background(), "nothing")
|
|
- if err == nil || err.Error() != "Error response from daemon: Server error" {
|
|
|
|
- t.Fatalf("expected a Server Error, got %v", err)
|
|
|
|
- }
|
|
|
|
|
|
+ testutil.ErrorContains(t, err, "Error response from daemon: Server error")
|
|
}
|
|
}
|
|
|
|
|
|
func TestVolumeInspectNotFound(t *testing.T) {
|
|
func TestVolumeInspectNotFound(t *testing.T) {
|
|
@@ -30,13 +31,34 @@ func TestVolumeInspectNotFound(t *testing.T) {
|
|
}
|
|
}
|
|
|
|
|
|
_, err := client.VolumeInspect(context.Background(), "unknown")
|
|
_, err := client.VolumeInspect(context.Background(), "unknown")
|
|
- if err == nil || !IsErrVolumeNotFound(err) {
|
|
|
|
- t.Fatalf("expected a volumeNotFound error, got %v", err)
|
|
|
|
|
|
+ assert.True(t, IsErrNotFound(err))
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+func TestVolumeInspectWithEmptyID(t *testing.T) {
|
|
|
|
+ expectedURL := "/volumes/"
|
|
|
|
+
|
|
|
|
+ client := &Client{
|
|
|
|
+ client: newMockClient(func(req *http.Request) (*http.Response, error) {
|
|
|
|
+ assert.Equal(t, req.URL.Path, expectedURL)
|
|
|
|
+ return &http.Response{
|
|
|
|
+ StatusCode: http.StatusNotFound,
|
|
|
|
+ Body: ioutil.NopCloser(bytes.NewReader(nil)),
|
|
|
|
+ }, nil
|
|
|
|
+ }),
|
|
}
|
|
}
|
|
|
|
+ _, err := client.VolumeInspect(context.Background(), "")
|
|
|
|
+ testutil.ErrorContains(t, err, "No such volume: ")
|
|
|
|
+
|
|
}
|
|
}
|
|
|
|
|
|
func TestVolumeInspect(t *testing.T) {
|
|
func TestVolumeInspect(t *testing.T) {
|
|
expectedURL := "/volumes/volume_id"
|
|
expectedURL := "/volumes/volume_id"
|
|
|
|
+ expected := types.Volume{
|
|
|
|
+ Name: "name",
|
|
|
|
+ Driver: "driver",
|
|
|
|
+ Mountpoint: "mountpoint",
|
|
|
|
+ }
|
|
|
|
+
|
|
client := &Client{
|
|
client := &Client{
|
|
client: newMockClient(func(req *http.Request) (*http.Response, error) {
|
|
client: newMockClient(func(req *http.Request) (*http.Response, error) {
|
|
if !strings.HasPrefix(req.URL.Path, expectedURL) {
|
|
if !strings.HasPrefix(req.URL.Path, expectedURL) {
|
|
@@ -45,11 +67,7 @@ func TestVolumeInspect(t *testing.T) {
|
|
if req.Method != "GET" {
|
|
if req.Method != "GET" {
|
|
return nil, fmt.Errorf("expected GET method, got %s", req.Method)
|
|
return nil, fmt.Errorf("expected GET method, got %s", req.Method)
|
|
}
|
|
}
|
|
- content, err := json.Marshal(types.Volume{
|
|
|
|
- Name: "name",
|
|
|
|
- Driver: "driver",
|
|
|
|
- Mountpoint: "mountpoint",
|
|
|
|
- })
|
|
|
|
|
|
+ content, err := json.Marshal(expected)
|
|
if err != nil {
|
|
if err != nil {
|
|
return nil, err
|
|
return nil, err
|
|
}
|
|
}
|
|
@@ -60,17 +78,7 @@ func TestVolumeInspect(t *testing.T) {
|
|
}),
|
|
}),
|
|
}
|
|
}
|
|
|
|
|
|
- v, err := client.VolumeInspect(context.Background(), "volume_id")
|
|
|
|
- if err != nil {
|
|
|
|
- t.Fatal(err)
|
|
|
|
- }
|
|
|
|
- if v.Name != "name" {
|
|
|
|
- t.Fatalf("expected `name`, got %s", v.Name)
|
|
|
|
- }
|
|
|
|
- if v.Driver != "driver" {
|
|
|
|
- t.Fatalf("expected `driver`, got %s", v.Driver)
|
|
|
|
- }
|
|
|
|
- if v.Mountpoint != "mountpoint" {
|
|
|
|
- t.Fatalf("expected `mountpoint`, got %s", v.Mountpoint)
|
|
|
|
- }
|
|
|
|
|
|
+ volume, err := client.VolumeInspect(context.Background(), "volume_id")
|
|
|
|
+ require.NoError(t, err)
|
|
|
|
+ assert.Equal(t, expected, volume)
|
|
}
|
|
}
|