b3b7eb27 |
package main
import (
"encoding/json"
"net/http" |
2af5034c |
"path/filepath" |
b3b7eb27 |
|
710817a7 |
"github.com/docker/docker/pkg/integration/checker" |
907407d0 |
"github.com/docker/engine-api/types" |
b3b7eb27 |
"github.com/go-check/check"
)
func (s *DockerSuite) TestVolumesApiList(c *check.C) { |
382c96ee |
prefix, _ := getPrefixAndSlashFromDaemonPlatform() |
e4468913 |
dockerCmd(c, "run", "-v", prefix+"/foo", "busybox") |
b3b7eb27 |
status, b, err := sockRequest("GET", "/volumes", nil) |
710817a7 |
c.Assert(err, checker.IsNil)
c.Assert(status, checker.Equals, http.StatusOK) |
b3b7eb27 |
var volumes types.VolumesListResponse |
710817a7 |
c.Assert(json.Unmarshal(b, &volumes), checker.IsNil) |
b3b7eb27 |
|
710817a7 |
c.Assert(len(volumes.Volumes), checker.Equals, 1, check.Commentf("\n%v", volumes.Volumes)) |
b3b7eb27 |
}
func (s *DockerSuite) TestVolumesApiCreate(c *check.C) {
config := types.VolumeCreateRequest{
Name: "test",
} |
0c95eeb5 |
status, b, err := sockRequest("POST", "/volumes/create", config) |
b3b7eb27 |
c.Assert(err, check.IsNil)
c.Assert(status, check.Equals, http.StatusCreated, check.Commentf(string(b)))
var vol types.Volume
err = json.Unmarshal(b, &vol) |
710817a7 |
c.Assert(err, checker.IsNil) |
b3b7eb27 |
|
2af5034c |
c.Assert(filepath.Base(filepath.Dir(vol.Mountpoint)), checker.Equals, config.Name) |
b3b7eb27 |
}
func (s *DockerSuite) TestVolumesApiRemove(c *check.C) { |
382c96ee |
prefix, _ := getPrefixAndSlashFromDaemonPlatform() |
faf4604d |
dockerCmd(c, "run", "-v", prefix+"/foo", "--name=test", "busybox") |
b3b7eb27 |
status, b, err := sockRequest("GET", "/volumes", nil) |
710817a7 |
c.Assert(err, checker.IsNil)
c.Assert(status, checker.Equals, http.StatusOK) |
b3b7eb27 |
var volumes types.VolumesListResponse |
710817a7 |
c.Assert(json.Unmarshal(b, &volumes), checker.IsNil)
c.Assert(len(volumes.Volumes), checker.Equals, 1, check.Commentf("\n%v", volumes.Volumes)) |
b3b7eb27 |
v := volumes.Volumes[0]
status, _, err = sockRequest("DELETE", "/volumes/"+v.Name, nil) |
710817a7 |
c.Assert(err, checker.IsNil)
c.Assert(status, checker.Equals, http.StatusConflict, check.Commentf("Should not be able to remove a volume that is in use")) |
b3b7eb27 |
dockerCmd(c, "rm", "-f", "test")
status, data, err := sockRequest("DELETE", "/volumes/"+v.Name, nil) |
710817a7 |
c.Assert(err, checker.IsNil)
c.Assert(status, checker.Equals, http.StatusNoContent, check.Commentf(string(data))) |
b3b7eb27 |
}
func (s *DockerSuite) TestVolumesApiInspect(c *check.C) {
config := types.VolumeCreateRequest{
Name: "test",
} |
0c95eeb5 |
status, b, err := sockRequest("POST", "/volumes/create", config) |
b3b7eb27 |
c.Assert(err, check.IsNil)
c.Assert(status, check.Equals, http.StatusCreated, check.Commentf(string(b)))
status, b, err = sockRequest("GET", "/volumes", nil) |
710817a7 |
c.Assert(err, checker.IsNil)
c.Assert(status, checker.Equals, http.StatusOK, check.Commentf(string(b))) |
b3b7eb27 |
var volumes types.VolumesListResponse |
710817a7 |
c.Assert(json.Unmarshal(b, &volumes), checker.IsNil)
c.Assert(len(volumes.Volumes), checker.Equals, 1, check.Commentf("\n%v", volumes.Volumes)) |
b3b7eb27 |
var vol types.Volume
status, b, err = sockRequest("GET", "/volumes/"+config.Name, nil) |
710817a7 |
c.Assert(err, checker.IsNil)
c.Assert(status, checker.Equals, http.StatusOK, check.Commentf(string(b)))
c.Assert(json.Unmarshal(b, &vol), checker.IsNil)
c.Assert(vol.Name, checker.Equals, config.Name) |
b3b7eb27 |
} |