mirror of
https://github.com/moby/moby.git
synced 2026-01-11 18:51:37 +00:00
client/volume: refactor volume options and responses
Signed-off-by: Austin Vazquez <austin.vazquez@docker.com>
This commit is contained in:
@@ -238,7 +238,7 @@ func setupTestVolume(t *testing.T, apiClient client.APIClient) string {
|
||||
|
||||
volumeName := t.Name() + "-volume"
|
||||
|
||||
err := apiClient.VolumeRemove(ctx, volumeName, true)
|
||||
err := apiClient.VolumeRemove(ctx, volumeName, client.VolumeRemoveOptions{Force: true})
|
||||
assert.NilError(t, err, "failed to clean volume")
|
||||
|
||||
_, err = apiClient.VolumeCreate(ctx, volume.CreateOptions{
|
||||
|
||||
@@ -47,8 +47,9 @@ func TestVolumesCreateAndList(t *testing.T) {
|
||||
}
|
||||
assert.Check(t, is.DeepEqual(vol, expected, cmpopts.EquateEmpty()))
|
||||
|
||||
volList, err := apiClient.VolumeList(ctx, client.VolumeListOptions{})
|
||||
res, err := apiClient.VolumeList(ctx, client.VolumeListOptions{})
|
||||
assert.NilError(t, err)
|
||||
volList := res.List
|
||||
assert.Assert(t, len(volList.Volumes) > 0)
|
||||
|
||||
volumes := volList.Volumes[:0]
|
||||
@@ -76,7 +77,7 @@ func TestVolumesRemove(t *testing.T) {
|
||||
vname := c.Mounts[0].Name
|
||||
|
||||
t.Run("volume in use", func(t *testing.T) {
|
||||
err = apiClient.VolumeRemove(ctx, vname, false)
|
||||
err = apiClient.VolumeRemove(ctx, vname, client.VolumeRemoveOptions{})
|
||||
assert.Check(t, is.ErrorType(err, cerrdefs.IsConflict))
|
||||
assert.Check(t, is.ErrorContains(err, "volume is in use"))
|
||||
})
|
||||
@@ -87,17 +88,17 @@ func TestVolumesRemove(t *testing.T) {
|
||||
})
|
||||
assert.NilError(t, err)
|
||||
|
||||
err = apiClient.VolumeRemove(ctx, vname, false)
|
||||
err = apiClient.VolumeRemove(ctx, vname, client.VolumeRemoveOptions{})
|
||||
assert.NilError(t, err)
|
||||
})
|
||||
|
||||
t.Run("non-existing volume", func(t *testing.T) {
|
||||
err = apiClient.VolumeRemove(ctx, "no_such_volume", false)
|
||||
err = apiClient.VolumeRemove(ctx, "no_such_volume", client.VolumeRemoveOptions{})
|
||||
assert.Check(t, is.ErrorType(err, cerrdefs.IsNotFound))
|
||||
})
|
||||
|
||||
t.Run("non-existing volume force", func(t *testing.T) {
|
||||
err = apiClient.VolumeRemove(ctx, "no_such_volume", true)
|
||||
err = apiClient.VolumeRemove(ctx, "no_such_volume", client.VolumeRemoveOptions{Force: true})
|
||||
assert.NilError(t, err)
|
||||
})
|
||||
}
|
||||
@@ -128,7 +129,7 @@ func TestVolumesRemoveSwarmEnabled(t *testing.T) {
|
||||
vname := c.Mounts[0].Name
|
||||
|
||||
t.Run("volume in use", func(t *testing.T) {
|
||||
err = apiClient.VolumeRemove(ctx, vname, false)
|
||||
err = apiClient.VolumeRemove(ctx, vname, client.VolumeRemoveOptions{})
|
||||
assert.Check(t, is.ErrorType(err, cerrdefs.IsConflict))
|
||||
assert.Check(t, is.ErrorContains(err, "volume is in use"))
|
||||
})
|
||||
@@ -139,17 +140,17 @@ func TestVolumesRemoveSwarmEnabled(t *testing.T) {
|
||||
})
|
||||
assert.NilError(t, err)
|
||||
|
||||
err = apiClient.VolumeRemove(ctx, vname, false)
|
||||
err = apiClient.VolumeRemove(ctx, vname, client.VolumeRemoveOptions{})
|
||||
assert.NilError(t, err)
|
||||
})
|
||||
|
||||
t.Run("non-existing volume", func(t *testing.T) {
|
||||
err = apiClient.VolumeRemove(ctx, "no_such_volume", false)
|
||||
err = apiClient.VolumeRemove(ctx, "no_such_volume", client.VolumeRemoveOptions{})
|
||||
assert.Check(t, is.ErrorType(err, cerrdefs.IsNotFound))
|
||||
})
|
||||
|
||||
t.Run("non-existing volume force", func(t *testing.T) {
|
||||
err = apiClient.VolumeRemove(ctx, "no_such_volume", true)
|
||||
err = apiClient.VolumeRemove(ctx, "no_such_volume", client.VolumeRemoveOptions{Force: true})
|
||||
assert.NilError(t, err)
|
||||
})
|
||||
}
|
||||
@@ -165,22 +166,22 @@ func TestVolumesInspect(t *testing.T) {
|
||||
inspected, err := apiClient.VolumeInspect(ctx, vol.Name)
|
||||
assert.NilError(t, err)
|
||||
|
||||
assert.Check(t, is.DeepEqual(inspected, vol, cmpopts.EquateEmpty()))
|
||||
assert.Check(t, is.DeepEqual(inspected.Volume, vol, cmpopts.EquateEmpty()))
|
||||
|
||||
// comparing CreatedAt field time for the new volume to now. Truncate to 1 minute precision to avoid false positive
|
||||
createdAt, err := time.Parse(time.RFC3339, strings.TrimSpace(inspected.CreatedAt))
|
||||
createdAt, err := time.Parse(time.RFC3339, strings.TrimSpace(inspected.Volume.CreatedAt))
|
||||
assert.NilError(t, err)
|
||||
assert.Check(t, createdAt.Unix()-now.Unix() < 60, "CreatedAt (%s) exceeds creation time (%s) 60s", createdAt, now)
|
||||
|
||||
// update atime and mtime for the "_data" directory (which would happen during volume initialization)
|
||||
modifiedAt := time.Now().Local().Add(5 * time.Hour)
|
||||
err = os.Chtimes(inspected.Mountpoint, modifiedAt, modifiedAt)
|
||||
err = os.Chtimes(inspected.Volume.Mountpoint, modifiedAt, modifiedAt)
|
||||
assert.NilError(t, err)
|
||||
|
||||
inspected, err = apiClient.VolumeInspect(ctx, vol.Name)
|
||||
assert.NilError(t, err)
|
||||
|
||||
createdAt2, err := time.Parse(time.RFC3339, strings.TrimSpace(inspected.CreatedAt))
|
||||
createdAt2, err := time.Parse(time.RFC3339, strings.TrimSpace(inspected.Volume.CreatedAt))
|
||||
assert.NilError(t, err)
|
||||
|
||||
// Check that CreatedAt didn't change after updating atime and mtime of the "_data" directory
|
||||
|
||||
Reference in New Issue
Block a user