1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00
moby--moby/integration-cli/docker_api_volumes_test.go
Akihiro Suda 7fb7a477d7 [nit] integration-cli: obey Go's naming convention
No substantial code change.

 - Api         --> API
 - Cli         --> CLI
 - Http, Https --> HTTP, HTTPS
 - Id          --> ID
 - Uid,Gid,Pid --> UID,PID,PID
 - Ipam        --> IPAM
 - Tls         --> TLS (TestDaemonNoTlsCliTlsVerifyWithEnv --> TestDaemonTLSVerifyIssue13964)

Didn't touch in this commit:
 - Git: because it is officially "Git": https://git-scm.com/
 - Tar: because it is officially "Tar": https://www.gnu.org/software/tar/
 - Cpu, Nat, Mac, Ipc, Shm: for keeping a consistency with existing production code (not changable, for compatibility)

Signed-off-by: Akihiro Suda <suda.akihiro@lab.ntt.co.jp>
2016-09-30 01:21:05 +00:00

88 lines
3 KiB
Go

package main
import (
"encoding/json"
"net/http"
"path/filepath"
"github.com/docker/docker/api/types"
"github.com/docker/docker/pkg/integration/checker"
"github.com/go-check/check"
)
func (s *DockerSuite) TestVolumesAPIList(c *check.C) {
prefix, _ := getPrefixAndSlashFromDaemonPlatform()
dockerCmd(c, "run", "-v", prefix+"/foo", "busybox")
status, b, err := sockRequest("GET", "/volumes", nil)
c.Assert(err, checker.IsNil)
c.Assert(status, checker.Equals, http.StatusOK)
var volumes types.VolumesListResponse
c.Assert(json.Unmarshal(b, &volumes), checker.IsNil)
c.Assert(len(volumes.Volumes), checker.Equals, 1, check.Commentf("\n%v", volumes.Volumes))
}
func (s *DockerSuite) TestVolumesAPICreate(c *check.C) {
config := types.VolumeCreateRequest{
Name: "test",
}
status, b, err := sockRequest("POST", "/volumes/create", config)
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)
c.Assert(err, checker.IsNil)
c.Assert(filepath.Base(filepath.Dir(vol.Mountpoint)), checker.Equals, config.Name)
}
func (s *DockerSuite) TestVolumesAPIRemove(c *check.C) {
prefix, _ := getPrefixAndSlashFromDaemonPlatform()
dockerCmd(c, "run", "-v", prefix+"/foo", "--name=test", "busybox")
status, b, err := sockRequest("GET", "/volumes", nil)
c.Assert(err, checker.IsNil)
c.Assert(status, checker.Equals, http.StatusOK)
var volumes types.VolumesListResponse
c.Assert(json.Unmarshal(b, &volumes), checker.IsNil)
c.Assert(len(volumes.Volumes), checker.Equals, 1, check.Commentf("\n%v", volumes.Volumes))
v := volumes.Volumes[0]
status, _, err = sockRequest("DELETE", "/volumes/"+v.Name, nil)
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"))
dockerCmd(c, "rm", "-f", "test")
status, data, err := sockRequest("DELETE", "/volumes/"+v.Name, nil)
c.Assert(err, checker.IsNil)
c.Assert(status, checker.Equals, http.StatusNoContent, check.Commentf(string(data)))
}
func (s *DockerSuite) TestVolumesAPIInspect(c *check.C) {
config := types.VolumeCreateRequest{
Name: "test",
}
status, b, err := sockRequest("POST", "/volumes/create", config)
c.Assert(err, check.IsNil)
c.Assert(status, check.Equals, http.StatusCreated, check.Commentf(string(b)))
status, b, err = sockRequest("GET", "/volumes", nil)
c.Assert(err, checker.IsNil)
c.Assert(status, checker.Equals, http.StatusOK, check.Commentf(string(b)))
var volumes types.VolumesListResponse
c.Assert(json.Unmarshal(b, &volumes), checker.IsNil)
c.Assert(len(volumes.Volumes), checker.Equals, 1, check.Commentf("\n%v", volumes.Volumes))
var vol types.Volume
status, b, err = sockRequest("GET", "/volumes/"+config.Name, nil)
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)
}