2015-06-12 09:25:32 -04:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2017-05-17 17:19:13 -04:00
|
|
|
"fmt"
|
2015-09-23 19:04:51 -04:00
|
|
|
"path/filepath"
|
2017-05-17 17:19:13 -04:00
|
|
|
"strings"
|
|
|
|
"time"
|
2015-06-12 09:25:32 -04:00
|
|
|
|
2017-05-23 23:56:26 -04:00
|
|
|
"github.com/docker/docker/api/types/filters"
|
2016-10-14 16:20:13 -04:00
|
|
|
volumetypes "github.com/docker/docker/api/types/volume"
|
2017-05-23 23:56:26 -04:00
|
|
|
"github.com/docker/docker/client"
|
2016-12-30 12:23:00 -05:00
|
|
|
"github.com/docker/docker/integration-cli/checker"
|
2015-06-12 09:25:32 -04:00
|
|
|
"github.com/go-check/check"
|
2017-05-23 23:56:26 -04:00
|
|
|
"golang.org/x/net/context"
|
2015-06-12 09:25:32 -04: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-27 21:50:12 -04:00
|
|
|
func (s *DockerSuite) TestVolumesAPIList(c *check.C) {
|
2016-02-03 09:16:00 -05:00
|
|
|
prefix, _ := getPrefixAndSlashFromDaemonPlatform()
|
2016-02-28 05:47:37 -05:00
|
|
|
dockerCmd(c, "run", "-v", prefix+"/foo", "busybox")
|
2015-06-12 09:25:32 -04:00
|
|
|
|
2017-05-23 23:56:26 -04:00
|
|
|
cli, err := client.NewEnvClient()
|
2015-10-13 08:01:58 -04:00
|
|
|
c.Assert(err, checker.IsNil)
|
2017-05-23 23:56:26 -04:00
|
|
|
defer cli.Close()
|
2015-06-12 09:25:32 -04:00
|
|
|
|
2017-05-23 23:56:26 -04:00
|
|
|
volumes, err := cli.VolumeList(context.Background(), filters.Args{})
|
|
|
|
c.Assert(err, checker.IsNil)
|
2015-06-12 09:25:32 -04:00
|
|
|
|
2015-10-13 08:01:58 -04:00
|
|
|
c.Assert(len(volumes.Volumes), checker.Equals, 1, check.Commentf("\n%v", volumes.Volumes))
|
2015-06-12 09:25:32 -04: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-27 21:50:12 -04:00
|
|
|
func (s *DockerSuite) TestVolumesAPICreate(c *check.C) {
|
2016-10-06 12:57:17 -04:00
|
|
|
config := volumetypes.VolumesCreateBody{
|
2015-06-12 09:25:32 -04:00
|
|
|
Name: "test",
|
|
|
|
}
|
|
|
|
|
2017-05-23 23:56:26 -04:00
|
|
|
cli, err := client.NewEnvClient()
|
2015-10-13 08:01:58 -04:00
|
|
|
c.Assert(err, checker.IsNil)
|
2017-05-23 23:56:26 -04:00
|
|
|
defer cli.Close()
|
|
|
|
|
|
|
|
vol, err := cli.VolumeCreate(context.Background(), config)
|
|
|
|
c.Assert(err, check.IsNil)
|
2015-06-12 09:25:32 -04:00
|
|
|
|
2015-09-23 19:04:51 -04:00
|
|
|
c.Assert(filepath.Base(filepath.Dir(vol.Mountpoint)), checker.Equals, config.Name)
|
2015-06-12 09:25:32 -04: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-27 21:50:12 -04:00
|
|
|
func (s *DockerSuite) TestVolumesAPIRemove(c *check.C) {
|
2016-02-03 09:16:00 -05:00
|
|
|
prefix, _ := getPrefixAndSlashFromDaemonPlatform()
|
2016-02-27 12:07:39 -05:00
|
|
|
dockerCmd(c, "run", "-v", prefix+"/foo", "--name=test", "busybox")
|
2015-06-12 09:25:32 -04:00
|
|
|
|
2017-05-23 23:56:26 -04:00
|
|
|
cli, err := client.NewEnvClient()
|
2015-10-13 08:01:58 -04:00
|
|
|
c.Assert(err, checker.IsNil)
|
2017-05-23 23:56:26 -04:00
|
|
|
defer cli.Close()
|
2015-06-12 09:25:32 -04:00
|
|
|
|
2017-05-23 23:56:26 -04:00
|
|
|
volumes, err := cli.VolumeList(context.Background(), filters.Args{})
|
|
|
|
c.Assert(err, checker.IsNil)
|
2015-06-12 09:25:32 -04:00
|
|
|
|
|
|
|
v := volumes.Volumes[0]
|
2017-05-23 23:56:26 -04:00
|
|
|
err = cli.VolumeRemove(context.Background(), v.Name, false)
|
|
|
|
c.Assert(err.Error(), checker.Contains, "volume is in use")
|
2015-06-12 09:25:32 -04:00
|
|
|
|
|
|
|
dockerCmd(c, "rm", "-f", "test")
|
2017-05-23 23:56:26 -04:00
|
|
|
err = cli.VolumeRemove(context.Background(), v.Name, false)
|
2015-10-13 08:01:58 -04:00
|
|
|
c.Assert(err, checker.IsNil)
|
2015-06-12 09:25:32 -04: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-27 21:50:12 -04:00
|
|
|
func (s *DockerSuite) TestVolumesAPIInspect(c *check.C) {
|
2016-10-06 12:57:17 -04:00
|
|
|
config := volumetypes.VolumesCreateBody{
|
2015-06-12 09:25:32 -04:00
|
|
|
Name: "test",
|
|
|
|
}
|
2017-05-23 23:56:26 -04:00
|
|
|
|
2017-05-17 17:19:13 -04:00
|
|
|
// sampling current time minus a minute so to now have false positive in case of delays
|
|
|
|
now := time.Now().Truncate(time.Minute)
|
2015-06-12 09:25:32 -04:00
|
|
|
|
2017-05-23 23:56:26 -04:00
|
|
|
cli, err := client.NewEnvClient()
|
2015-10-13 08:01:58 -04:00
|
|
|
c.Assert(err, checker.IsNil)
|
2017-05-23 23:56:26 -04:00
|
|
|
defer cli.Close()
|
2015-06-12 09:25:32 -04:00
|
|
|
|
2017-05-23 23:56:26 -04:00
|
|
|
_, err = cli.VolumeCreate(context.Background(), config)
|
|
|
|
c.Assert(err, check.IsNil)
|
|
|
|
|
|
|
|
volumes, err := cli.VolumeList(context.Background(), filters.Args{})
|
|
|
|
c.Assert(err, checker.IsNil)
|
2015-10-13 08:01:58 -04:00
|
|
|
c.Assert(len(volumes.Volumes), checker.Equals, 1, check.Commentf("\n%v", volumes.Volumes))
|
2015-06-12 09:25:32 -04:00
|
|
|
|
2017-05-23 23:56:26 -04:00
|
|
|
vol, err := cli.VolumeInspect(context.Background(), config.Name)
|
2015-10-13 08:01:58 -04:00
|
|
|
c.Assert(err, checker.IsNil)
|
|
|
|
c.Assert(vol.Name, checker.Equals, config.Name)
|
2017-05-17 17:19:13 -04:00
|
|
|
|
|
|
|
// comparing CreatedAt field time for the new volume to now. Removing a minute from both to avoid false positive
|
|
|
|
testCreatedAt, err := time.Parse(time.RFC3339, strings.TrimSpace(vol.CreatedAt))
|
|
|
|
c.Assert(err, check.IsNil)
|
|
|
|
testCreatedAt = testCreatedAt.Truncate(time.Minute)
|
|
|
|
if !testCreatedAt.Equal(now) {
|
|
|
|
c.Assert(fmt.Errorf("Time Volume is CreatedAt not equal to current time"), check.NotNil)
|
|
|
|
}
|
2015-06-12 09:25:32 -04:00
|
|
|
}
|