Skip to content

Commit

Permalink
Merge pull request #1553 from shaloulcy/volume_from_test
Browse files Browse the repository at this point in the history
test: add test for different volume sources
  • Loading branch information
Letty5411 authored Jun 20, 2018
2 parents bd4fa8d + 1198581 commit 6c6ae88
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 3 deletions.
51 changes: 51 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,55 @@ func (suite *PouchRunVolumeSuite) TestRunWithVolumesFromWithDupclicate(c *check.
c.Assert(volumeFound, check.Equals, true)
}

// TestRunWithVolumesFromDifferentSources tests containers with volumes from different sources
func (suite *PouchRunVolumeSuite) TestRunWithVolumesFromDifferentSources(c *check.C) {
// TODO: build the image with volume
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)
defer func() {
command.PouchRun("rmi", "-f", 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)
defer DelContainerForceMultyTime(c, containerName1)

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)
defer DelContainerForceMultyTime(c, containerName2)

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)
}

// only one Mount, as the volumes-from will overwrite the binds
c.Assert(len(container2[0].Mounts), check.Equals, 1)
volumeName2 := container2[0].Mounts[0].Name

// assert the two volumes is the same one
c.Assert(volumeName1, check.Equals, volumeName2)
}

// TestRunWithDiskQuotaRegular tests running container with --disk-quota.
func (suite *PouchRunVolumeSuite) TestRunWithDiskQuotaRegular(c *check.C) {
if !environment.IsDiskQuota() {
Expand Down
4 changes: 1 addition & 3 deletions test/util_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,14 +80,12 @@ func DelContainerForceOk(c *check.C, cname string) {
func DelContainerForce(c *check.C, cname string) (*http.Response, error) {
q := url.Values{}
q.Add("force", "true")
q.Add("v", "true")
return request.Delete("/containers/"+cname, request.WithQuery(q))
}

// DelContainerForceMultyTime forcely deletes the container multy times.
func DelContainerForceMultyTime(c *check.C, cname string) {
q := url.Values{}
q.Add("force", "true")

done := make(chan bool, 1)

ticker := time.NewTicker(500 * time.Millisecond)
Expand Down

0 comments on commit 6c6ae88

Please sign in to comment.