2015-06-12 13:25:32 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/json"
|
|
|
|
"net/http"
|
2015-09-23 23:04:51 +00:00
|
|
|
"path/filepath"
|
2015-06-12 13:25:32 +00:00
|
|
|
|
2016-09-06 18:18:12 +00:00
|
|
|
"github.com/docker/docker/api/types"
|
2016-10-14 20:20:13 +00:00
|
|
|
volumetypes "github.com/docker/docker/api/types/volume"
|
2015-10-13 12:01:58 +00:00
|
|
|
"github.com/docker/docker/pkg/integration/checker"
|
2015-06-12 13:25:32 +00:00
|
|
|
"github.com/go-check/check"
|
|
|
|
)
|
|
|
|
|
[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-28 01:50:12 +00:00
|
|
|
func (s *DockerSuite) TestVolumesAPIList(c *check.C) {
|
2016-02-03 14:16:00 +00:00
|
|
|
prefix, _ := getPrefixAndSlashFromDaemonPlatform()
|
2016-02-28 10:47:37 +00:00
|
|
|
dockerCmd(c, "run", "-v", prefix+"/foo", "busybox")
|
2015-06-12 13:25:32 +00:00
|
|
|
|
|
|
|
status, b, err := sockRequest("GET", "/volumes", nil)
|
2015-10-13 12:01:58 +00:00
|
|
|
c.Assert(err, checker.IsNil)
|
|
|
|
c.Assert(status, checker.Equals, http.StatusOK)
|
2015-06-12 13:25:32 +00:00
|
|
|
|
2016-10-04 15:40:17 +00:00
|
|
|
var volumes volumetypes.VolumesListOKBody
|
2015-10-13 12:01:58 +00:00
|
|
|
c.Assert(json.Unmarshal(b, &volumes), checker.IsNil)
|
2015-06-12 13:25:32 +00:00
|
|
|
|
2015-10-13 12:01:58 +00:00
|
|
|
c.Assert(len(volumes.Volumes), checker.Equals, 1, check.Commentf("\n%v", volumes.Volumes))
|
2015-06-12 13:25:32 +00:00
|
|
|
}
|
|
|
|
|
[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-28 01:50:12 +00:00
|
|
|
func (s *DockerSuite) TestVolumesAPICreate(c *check.C) {
|
2016-10-06 16:57:17 +00:00
|
|
|
config := volumetypes.VolumesCreateBody{
|
2015-06-12 13:25:32 +00:00
|
|
|
Name: "test",
|
|
|
|
}
|
2015-10-17 11:49:14 +00:00
|
|
|
status, b, err := sockRequest("POST", "/volumes/create", config)
|
2015-06-12 13:25:32 +00:00
|
|
|
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)
|
2015-10-13 12:01:58 +00:00
|
|
|
c.Assert(err, checker.IsNil)
|
2015-06-12 13:25:32 +00:00
|
|
|
|
2015-09-23 23:04:51 +00:00
|
|
|
c.Assert(filepath.Base(filepath.Dir(vol.Mountpoint)), checker.Equals, config.Name)
|
2015-06-12 13:25:32 +00:00
|
|
|
}
|
|
|
|
|
[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-28 01:50:12 +00:00
|
|
|
func (s *DockerSuite) TestVolumesAPIRemove(c *check.C) {
|
2016-02-03 14:16:00 +00:00
|
|
|
prefix, _ := getPrefixAndSlashFromDaemonPlatform()
|
2016-02-27 17:07:39 +00:00
|
|
|
dockerCmd(c, "run", "-v", prefix+"/foo", "--name=test", "busybox")
|
2015-06-12 13:25:32 +00:00
|
|
|
|
|
|
|
status, b, err := sockRequest("GET", "/volumes", nil)
|
2015-10-13 12:01:58 +00:00
|
|
|
c.Assert(err, checker.IsNil)
|
|
|
|
c.Assert(status, checker.Equals, http.StatusOK)
|
2015-06-12 13:25:32 +00:00
|
|
|
|
2016-10-04 15:40:17 +00:00
|
|
|
var volumes volumetypes.VolumesListOKBody
|
2015-10-13 12:01:58 +00:00
|
|
|
c.Assert(json.Unmarshal(b, &volumes), checker.IsNil)
|
|
|
|
c.Assert(len(volumes.Volumes), checker.Equals, 1, check.Commentf("\n%v", volumes.Volumes))
|
2015-06-12 13:25:32 +00:00
|
|
|
|
|
|
|
v := volumes.Volumes[0]
|
|
|
|
status, _, err = sockRequest("DELETE", "/volumes/"+v.Name, nil)
|
2015-10-13 12:01:58 +00:00
|
|
|
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"))
|
2015-06-12 13:25:32 +00:00
|
|
|
|
|
|
|
dockerCmd(c, "rm", "-f", "test")
|
|
|
|
status, data, err := sockRequest("DELETE", "/volumes/"+v.Name, nil)
|
2015-10-13 12:01:58 +00:00
|
|
|
c.Assert(err, checker.IsNil)
|
|
|
|
c.Assert(status, checker.Equals, http.StatusNoContent, check.Commentf(string(data)))
|
2015-06-12 13:25:32 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
[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-28 01:50:12 +00:00
|
|
|
func (s *DockerSuite) TestVolumesAPIInspect(c *check.C) {
|
2016-10-06 16:57:17 +00:00
|
|
|
config := volumetypes.VolumesCreateBody{
|
2015-06-12 13:25:32 +00:00
|
|
|
Name: "test",
|
|
|
|
}
|
2015-10-17 11:49:14 +00:00
|
|
|
status, b, err := sockRequest("POST", "/volumes/create", config)
|
2015-06-12 13:25:32 +00:00
|
|
|
c.Assert(err, check.IsNil)
|
|
|
|
c.Assert(status, check.Equals, http.StatusCreated, check.Commentf(string(b)))
|
|
|
|
|
|
|
|
status, b, err = sockRequest("GET", "/volumes", nil)
|
2015-10-13 12:01:58 +00:00
|
|
|
c.Assert(err, checker.IsNil)
|
|
|
|
c.Assert(status, checker.Equals, http.StatusOK, check.Commentf(string(b)))
|
2015-06-12 13:25:32 +00:00
|
|
|
|
2016-10-04 15:40:17 +00:00
|
|
|
var volumes volumetypes.VolumesListOKBody
|
2015-10-13 12:01:58 +00:00
|
|
|
c.Assert(json.Unmarshal(b, &volumes), checker.IsNil)
|
|
|
|
c.Assert(len(volumes.Volumes), checker.Equals, 1, check.Commentf("\n%v", volumes.Volumes))
|
2015-06-12 13:25:32 +00:00
|
|
|
|
|
|
|
var vol types.Volume
|
|
|
|
status, b, err = sockRequest("GET", "/volumes/"+config.Name, nil)
|
2015-10-13 12:01:58 +00:00
|
|
|
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)
|
2015-06-12 13:25:32 +00:00
|
|
|
}
|