Skip to content

Commit

Permalink
test: add deamon related function
Browse files Browse the repository at this point in the history
Signed-off-by: letty <[email protected]>
  • Loading branch information
Letty5411 committed Mar 15, 2018
1 parent 1564d7a commit 06269ec
Show file tree
Hide file tree
Showing 30 changed files with 656 additions and 307 deletions.
2 changes: 1 addition & 1 deletion hack/make.sh
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ function target()
pouch version

# If test is failed, print pouch daemon log.
$DIR/test/integration-test -check.v || { echo "pouch daemon log:"; cat $TMP/log; return 1; }
$DIR/test/integration-test -test.v -check.v || { echo "pouch daemon log:"; cat $TMP/log; return 1; }
;;
*)
echo "no such target: $target"
Expand Down
4 changes: 4 additions & 0 deletions test/api_container_attach_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@ package main
import (
"net/url"

"github.com/alibaba/pouch/test/command"
"github.com/alibaba/pouch/test/environment"
"github.com/alibaba/pouch/test/request"

"github.com/go-check/check"
"github.com/gotestyourself/gotestyourself/icmd"
)

// APIContainerAttachSuite is the test suite for container attach API.
Expand All @@ -19,6 +21,8 @@ func init() {
// SetUpTest does common setup in the beginning of each test.
func (suite *APIContainerAttachSuite) SetUpTest(c *check.C) {
SkipIfFalse(c, environment.IsLinux)

command.PouchRun("pull", busyboxImage).Assert(c, icmd.Success)
}

// TestContainerAttachStdin tests attaching stdin is OK.
Expand Down
3 changes: 3 additions & 0 deletions test/api_container_create_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@ import (
"net/url"

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

"github.com/go-check/check"
"github.com/gotestyourself/gotestyourself/icmd"
)

// APIContainerCreateSuite is the test suite for container create API.
Expand All @@ -20,6 +22,7 @@ func init() {
// SetUpTest does common setup in the beginning of each test.
func (suite *APIContainerCreateSuite) SetUpTest(c *check.C) {
SkipIfFalse(c, environment.IsLinux)
command.PouchRun("pull", busyboxImage).Assert(c, icmd.Success)
}

// TestCreateOk test create api is ok with default parameters.
Expand Down
3 changes: 3 additions & 0 deletions test/api_container_delete_test.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package main

import (
"github.com/alibaba/pouch/test/command"
"github.com/alibaba/pouch/test/environment"
"github.com/alibaba/pouch/test/request"

"github.com/go-check/check"
"github.com/gotestyourself/gotestyourself/icmd"
)

// APIContainerDeleteSuite is the test suite for container delete API.
Expand All @@ -17,6 +19,7 @@ func init() {
// SetUpTest does common setup in the beginning of each test.
func (suite *APIContainerDeleteSuite) SetUpTest(c *check.C) {
SkipIfFalse(c, environment.IsLinux)
command.PouchRun("pull", busyboxImage).Assert(c, icmd.Success)
}

// TestDeleteNonExisting tests deleting a non-existing container return error.
Expand Down
3 changes: 3 additions & 0 deletions test/api_container_exec_start_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@ import (
"io"
"net"

"github.com/alibaba/pouch/test/command"
"github.com/alibaba/pouch/test/environment"
"github.com/alibaba/pouch/test/request"

"github.com/go-check/check"
"github.com/gotestyourself/gotestyourself/icmd"
)

// APIContainerExecStartSuite is the test suite for container exec start API.
Expand All @@ -21,6 +23,7 @@ func init() {
// SetUpTest does common setup in the beginning of each test.
func (suite *APIContainerExecStartSuite) SetUpTest(c *check.C) {
SkipIfFalse(c, environment.IsLinux)
command.PouchRun("pull", busyboxImage).Assert(c, icmd.Success)
}

func checkEchoSuccess(c *check.C, conn net.Conn, br *bufio.Reader, exp string) {
Expand Down
3 changes: 3 additions & 0 deletions test/api_container_exec_test.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package main

import (
"github.com/alibaba/pouch/test/command"
"github.com/alibaba/pouch/test/environment"
"github.com/alibaba/pouch/test/request"

"github.com/go-check/check"
"github.com/gotestyourself/gotestyourself/icmd"
)

// APIContainerExecSuite is the test suite for container exec API.
Expand All @@ -17,6 +19,7 @@ func init() {
// SetUpTest does common setup in the beginning of each test.
func (suite *APIContainerExecSuite) SetUpTest(c *check.C) {
SkipIfFalse(c, environment.IsLinux)
command.PouchRun("pull", busyboxImage).Assert(c, icmd.Success)
}

// TestContainerCreateExecOk tests execing containers is OK.
Expand Down
3 changes: 3 additions & 0 deletions test/api_container_inspect_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@ package main

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

"github.com/go-check/check"
"github.com/gotestyourself/gotestyourself/icmd"
)

// APIContainerInspectSuite is the test suite for container inspect API.
Expand All @@ -18,6 +20,7 @@ func init() {
// SetUpTest does common setup in the beginning of each test.
func (suite *APIContainerInspectSuite) SetUpTest(c *check.C) {
SkipIfFalse(c, environment.IsLinux)
command.PouchRun("pull", busyboxImage).Assert(c, icmd.Success)
}

// TestInspectNoSuchContainer tests inspecting a container that doesn't exits return error.
Expand Down
3 changes: 3 additions & 0 deletions test/api_container_list_test.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package main

import (
"github.com/alibaba/pouch/test/command"
"github.com/alibaba/pouch/test/environment"
"github.com/alibaba/pouch/test/request"

"github.com/go-check/check"
"github.com/gotestyourself/gotestyourself/icmd"
)

// APIContainerListSuite is the test suite for container list API.
Expand All @@ -17,6 +19,7 @@ func init() {
// SetUpTest does common setup in the beginning of each test.
func (suite *APIContainerListSuite) SetUpTest(c *check.C) {
SkipIfFalse(c, environment.IsLinux)
command.PouchRun("pull", busyboxImage).Assert(c, icmd.Success)
}

// TestListOk test api is ok with default parameters.
Expand Down
3 changes: 3 additions & 0 deletions test/api_container_pause_test.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package main

import (
"github.com/alibaba/pouch/test/command"
"github.com/alibaba/pouch/test/environment"
"github.com/alibaba/pouch/test/request"

"github.com/go-check/check"
"github.com/gotestyourself/gotestyourself/icmd"
)

// APIContainerPauseSuite is the test suite for container pause/unpause API.
Expand All @@ -17,6 +19,7 @@ func init() {
// SetUpTest does common setup in the beginning of each test.
func (suite *APIContainerPauseSuite) SetUpTest(c *check.C) {
SkipIfFalse(c, environment.IsLinux)
command.PouchRun("pull", busyboxImage).Assert(c, icmd.Success)
}

// TestPauseUnpauseOk tests a running container could be paused and unpaused.
Expand Down
3 changes: 3 additions & 0 deletions test/api_container_rename_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@ package main
import (
"net/url"

"github.com/alibaba/pouch/test/command"
"github.com/alibaba/pouch/test/environment"
"github.com/alibaba/pouch/test/request"

"github.com/go-check/check"
"github.com/gotestyourself/gotestyourself/icmd"
)

// APIContainerRenameSuite is the test suite for container create API.
Expand All @@ -19,6 +21,7 @@ func init() {
// SetUpTest does common setup in the beginning of each test.
func (suite *APIContainerRenameSuite) SetUpTest(c *check.C) {
SkipIfFalse(c, environment.IsLinux)
command.PouchRun("pull", busyboxImage).Assert(c, icmd.Success)
}

// TestRenameOk test create api is ok with default parameters.
Expand Down
3 changes: 3 additions & 0 deletions test/api_container_start_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@ package main
import (
"net/url"

"github.com/alibaba/pouch/test/command"
"github.com/alibaba/pouch/test/environment"
"github.com/alibaba/pouch/test/request"

"github.com/go-check/check"
"github.com/gotestyourself/gotestyourself/icmd"
)

// APIContainerStartSuite is the test suite for container pause/unpause API.
Expand All @@ -19,6 +21,7 @@ func init() {
// SetUpTest does common setup in the beginning of each test.
func (suite *APIContainerStartSuite) SetUpTest(c *check.C) {
SkipIfFalse(c, environment.IsLinux)
command.PouchRun("pull", busyboxImage).Assert(c, icmd.Success)
}

// TestStartOk tests starting container could work.
Expand Down
3 changes: 3 additions & 0 deletions test/api_container_stop_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@ package main
import (
"net/url"

"github.com/alibaba/pouch/test/command"
"github.com/alibaba/pouch/test/environment"
"github.com/alibaba/pouch/test/request"

"github.com/go-check/check"
"github.com/gotestyourself/gotestyourself/icmd"
)

// APIContainerStopSuite is the test suite for container stop API.
Expand All @@ -19,6 +21,7 @@ func init() {
// SetUpTest does common setup in the beginning of each test.
func (suite *APIContainerStopSuite) SetUpTest(c *check.C) {
SkipIfFalse(c, environment.IsLinux)
command.PouchRun("pull", busyboxImage).Assert(c, icmd.Success)
}

// TestStopOk tests a running container could be stopped.
Expand Down
14 changes: 10 additions & 4 deletions test/api_image_create_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"github.com/alibaba/pouch/test/environment"
"github.com/alibaba/pouch/test/request"

"github.com/alibaba/pouch/test/util"
"github.com/go-check/check"
)

Expand Down Expand Up @@ -77,9 +78,14 @@ func (suite *APIImageCreateSuite) TestImageCreateWithoutRegistry(c *check.C) {
c.Assert(err, check.IsNil)
CheckRespStatus(c, resp, 200)

time.Sleep(5000 * time.Millisecond)
ret := util.WaitTimeout(10*time.Second, DelHelloworldImage)
c.Assert(ret, check.Equals, true)
}

resp, err = request.Delete("/images/" + helloworldImageOnlyRepoName + ":latest")
c.Assert(err, check.IsNil)
CheckRespStatus(c, resp, 204)
func DelHelloworldImage() bool {
resp, err := request.Delete("/images/" + helloworldImageOnlyRepoName + ":latest")
if err == nil && resp.StatusCode == 204 {
return true
}
return false
}
6 changes: 0 additions & 6 deletions test/api_image_delete_test.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package main

import (
"net/url"

"github.com/alibaba/pouch/test/environment"
"github.com/alibaba/pouch/test/request"

Expand Down Expand Up @@ -35,10 +33,6 @@ func (suite *APIImageDeleteSuite) TestDeleteUsingImage(c *check.C) {
CreateBusyboxContainerOk(c, cname)
StartContainerOk(c, cname)

q := url.Values{}
q.Add("fromImage", helloworldImage)
q.Add("tag", "latest")

resp, err := request.Delete("/images/" + busyboxImage)
c.Assert(err, check.IsNil)
CheckRespStatus(c, resp, 500)
Expand Down
5 changes: 4 additions & 1 deletion test/api_image_inspect_test.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
package main

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

"github.com/alibaba/pouch/apis/types"
"github.com/go-check/check"
"github.com/gotestyourself/gotestyourself/icmd"
)

// APIImageInspectSuite is the test suite for image inspect API.
Expand All @@ -18,6 +20,7 @@ func init() {
// SetUpTest does common setup in the beginning of each test.
func (suite *APIImageInspectSuite) SetUpTest(c *check.C) {
SkipIfFalse(c, environment.IsLinux)
command.PouchRun("pull", busyboxImage).Assert(c, icmd.Success)
}

// TestImageInspectOk tests inspecting images is OK.
Expand Down
4 changes: 2 additions & 2 deletions test/cli_alikernel_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func (suite *PouchAliKernelSuite) TestAliKernelDiskQuotaWorks(c *check.C) {
defer command.PouchRun("volume", "rm", funcname)

command.PouchRun("run", "-d", "-v", funcname+":/mnt", "--name", funcname, busyboxImage, "top").Assert(c, icmd.Success)
defer command.PouchRun("rm", "-f", funcname)
defer DelContainerForceMultyTime(c, funcname)

expct := icmd.Expected{
ExitCode: 0,
Expand Down Expand Up @@ -82,7 +82,7 @@ func (suite *PouchAliKernelSuite) TestAliKernelDiskQuotaMultiWorks(c *check.C) {
defer command.PouchRun("volume", "rm", name2)

command.PouchRun("run", "-d", "-v", name1+":/mnt/test1", "-v", name2+":/mnt/test2", "--name", funcname, busyboxImage, "top").Assert(c, icmd.Success)
defer command.PouchRun("rm", "-f", funcname)
defer DelContainerForceMultyTime(c, funcname)

{
expct := icmd.Expected{
Expand Down
Loading

0 comments on commit 06269ec

Please sign in to comment.