Skip to content

Commit

Permalink
test: add test for different volume sources
Browse files Browse the repository at this point in the history
the volumes of container have four different sources(volumes-from,
binds, images and Config.Volume). If two volumes have the same destination,
only one volume is reserved. The order is
volumes-from > binds > images > Config.Volume

Signed-off-by: Eric Li <[email protected]>
  • Loading branch information
shaloulcy committed Jun 19, 2018
1 parent 1ac9207 commit 27f0e6b
Showing 1 changed file with 49 additions and 0 deletions.
49 changes: 49 additions & 0 deletions test/cli_run_volume_test.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package main

import (
"encoding/json"
"fmt"
"runtime"
"strings"

"github.com/alibaba/pouch/apis/types"
"github.com/alibaba/pouch/test/command"
"github.com/alibaba/pouch/test/environment"

Expand Down Expand Up @@ -170,6 +172,53 @@ func (suite *PouchRunVolumeSuite) TestRunWithVolumesFromWithDupclicate(c *check.
c.Assert(volumeFound, check.Equals, true)
}

func (suite *PouchRunVolumeSuite) TestRunWithVolumesFromDifferentSources(c *check.C) {
imageWithVolume := "registry.hub.docker.com/shaloulcy/busybox:with-volume"
containerName1 := "TestRunWithVolumesFromImage"
containerName2 := "TestRunWithVolumesFromContainerAndImage"

// pull the image with volume
command.PouchRun("pull", imageWithVolume).Assert(c, icmd.Success)

// start the container1 which has volume from image,
// and the volume destination is /data
command.PouchRun("run", "-d", "-t",
"--name", containerName1, imageWithVolume, "top").Assert(c, icmd.Success)

out1 := command.PouchRun("inspect", containerName1).Assert(c, icmd.Success)
container1 := []types.ContainerJSON{}
if err := json.Unmarshal([]byte(out1.Stdout()), &container1); err != nil {
c.Errorf("failed to decode inspect output: %v", err)
}

c.Assert(len(container1[0].Mounts), check.Equals, 1)
volumeName1 := container1[0].Mounts[0].Name

// start the container2 which has volumes from container1,
// and has an extra volume whose desctination is /data
command.PouchRun("run", "-d", "-t",
"-v", "/data", "--volumes-from", containerName1,
"--name", containerName2, imageWithVolume, "top").Assert(c, icmd.Success)

out2 := command.PouchRun("inspect", containerName2).Assert(c, icmd.Success)
container2 := []types.ContainerJSON{}
if err := json.Unmarshal([]byte(out2.Stdout()), &container2); err != nil {
c.Errorf("failed to decode inspect output: %v", err)
}

c.Assert(len(container2[0].Mounts), check.Equals, 1)
volumeName2 := container2[0].Mounts[0].Name

// assert the volume
c.Assert(volumeName1, check.Equals, volumeName2)

// clean up
DelContainerForceMultyTime(c, containerName1)
DelContainerForceMultyTime(c, containerName2)
RemoveVolume(c, volumeName1)
command.PouchRun("rmi", "-f", imageWithVolume).Assert(c, icmd.Success)
}

// TestRunWithDiskQuotaRegular tests running container with --disk-quota.
func (suite *PouchRunVolumeSuite) TestRunWithDiskQuotaRegular(c *check.C) {
if !environment.IsDiskQuota() {
Expand Down

0 comments on commit 27f0e6b

Please sign in to comment.