diff --git a/hack/make.sh b/hack/make.sh index 384b2bd1d..b4048cb08 100755 --- a/hack/make.sh +++ b/hack/make.sh @@ -120,7 +120,7 @@ function target() fi done - pouch pull registry.hub.docker.com/library/busybox:latest >/dev/null + pouch pull registry.hub.docker.com/library/busybox:1.28 >/dev/null echo "verify pouch version" pouch version diff --git a/test/api_container_attach_test.go b/test/api_container_attach_test.go index 75a975123..a2e7d6992 100644 --- a/test/api_container_attach_test.go +++ b/test/api_container_attach_test.go @@ -3,12 +3,10 @@ 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. @@ -22,7 +20,7 @@ func init() { func (suite *APIContainerAttachSuite) SetUpTest(c *check.C) { SkipIfFalse(c, environment.IsLinux) - command.PouchRun("pull", busyboxImage).Assert(c, icmd.Success) + PullImage(c, busyboxImage) } // TestContainerAttachStdin tests attaching stdin is OK. diff --git a/test/api_container_create_test.go b/test/api_container_create_test.go index ccbb61099..39010e281 100644 --- a/test/api_container_create_test.go +++ b/test/api_container_create_test.go @@ -4,12 +4,10 @@ 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. @@ -22,7 +20,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) + PullImage(c, busyboxImage) } // TestCreateOk test create api is ok with default parameters. diff --git a/test/api_container_delete_test.go b/test/api_container_delete_test.go index 22733b9af..3c7862aa9 100644 --- a/test/api_container_delete_test.go +++ b/test/api_container_delete_test.go @@ -1,12 +1,10 @@ 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. @@ -19,7 +17,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) + PullImage(c, busyboxImage) } // TestDeleteNonExisting tests deleting a non-existing container return error. diff --git a/test/api_container_exec_start_test.go b/test/api_container_exec_start_test.go index 5e4650e0e..6de5f7364 100644 --- a/test/api_container_exec_start_test.go +++ b/test/api_container_exec_start_test.go @@ -5,12 +5,10 @@ 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. @@ -23,7 +21,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) + PullImage(c, busyboxImage) } func checkEchoSuccess(c *check.C, conn net.Conn, br *bufio.Reader, exp string) { diff --git a/test/api_container_exec_test.go b/test/api_container_exec_test.go index cf80d425c..ed13facf6 100644 --- a/test/api_container_exec_test.go +++ b/test/api_container_exec_test.go @@ -1,12 +1,10 @@ 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. @@ -19,7 +17,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) + PullImage(c, busyboxImage) } // TestContainerCreateExecOk tests execing containers is OK. diff --git a/test/api_container_inspect_test.go b/test/api_container_inspect_test.go index 7c4900363..c8238c6c9 100644 --- a/test/api_container_inspect_test.go +++ b/test/api_container_inspect_test.go @@ -2,12 +2,10 @@ 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. @@ -20,7 +18,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) + PullImage(c, busyboxImage) } // TestInspectNoSuchContainer tests inspecting a container that doesn't exits return error. diff --git a/test/api_container_list_test.go b/test/api_container_list_test.go index 403f08dcb..52ed8d2c1 100644 --- a/test/api_container_list_test.go +++ b/test/api_container_list_test.go @@ -1,12 +1,10 @@ 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. @@ -19,7 +17,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) + PullImage(c, busyboxImage) } // TestListOk test api is ok with default parameters. diff --git a/test/api_container_pause_test.go b/test/api_container_pause_test.go index 2fe8246a7..c7843c130 100644 --- a/test/api_container_pause_test.go +++ b/test/api_container_pause_test.go @@ -1,12 +1,10 @@ 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. @@ -19,7 +17,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) + PullImage(c, busyboxImage) } // TestPauseUnpauseOk tests a running container could be paused and unpaused. diff --git a/test/api_container_rename_test.go b/test/api_container_rename_test.go index 9fc7d9e35..f2eafb36e 100644 --- a/test/api_container_rename_test.go +++ b/test/api_container_rename_test.go @@ -3,12 +3,10 @@ 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. @@ -21,7 +19,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) + PullImage(c, busyboxImage) } // TestRenameOk test create api is ok with default parameters. diff --git a/test/api_container_resize.go b/test/api_container_resize.go index 96f782ca8..f661b74f6 100644 --- a/test/api_container_resize.go +++ b/test/api_container_resize.go @@ -20,6 +20,7 @@ func init() { func (suite *APIContainerResizeSuite) SetUpTest(c *check.C) { SkipIfFalse(c, environment.IsLinux) + PullImage(c, busyboxImage) } // TestContainerResizeOk is to verify resize container. diff --git a/test/api_container_start_test.go b/test/api_container_start_test.go index 0ca089c95..77eac994c 100644 --- a/test/api_container_start_test.go +++ b/test/api_container_start_test.go @@ -3,12 +3,10 @@ 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. @@ -21,7 +19,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) + PullImage(c, busyboxImage) } // TestStartOk tests starting container could work. diff --git a/test/api_container_stop_test.go b/test/api_container_stop_test.go index e2f1fac7d..919d3ba51 100644 --- a/test/api_container_stop_test.go +++ b/test/api_container_stop_test.go @@ -3,12 +3,10 @@ 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. @@ -21,7 +19,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) + PullImage(c, busyboxImage) } // TestStopOk tests a running container could be stopped. diff --git a/test/api_image_create_test.go b/test/api_image_create_test.go index 80a3fe341..686b48bad 100644 --- a/test/api_image_create_test.go +++ b/test/api_image_create_test.go @@ -26,8 +26,8 @@ func (suite *APIImageCreateSuite) SetUpTest(c *check.C) { // TestImageCreateOk tests creating an image is OK. func (suite *APIImageCreateSuite) TestImageCreateOk(c *check.C) { q := url.Values{} - q.Add("fromImage", helloworldImage) - q.Add("tag", "latest") + q.Add("fromImage", environment.HelloworldRepo) + q.Add("tag", "linux") query := request.WithQuery(q) resp, err := request.Post("/images/create", query) c.Assert(err, check.IsNil) @@ -36,7 +36,7 @@ func (suite *APIImageCreateSuite) TestImageCreateOk(c *check.C) { // TODO: add a waituntil func to check the exsitence of image time.Sleep(5000 * time.Millisecond) - resp, err = request.Delete("/images/" + helloworldImage + ":latest") + resp, err = request.Delete("/images/" + environment.HelloworldRepo + ":linux") c.Assert(err, check.IsNil) CheckRespStatus(c, resp, 204) } @@ -56,7 +56,7 @@ func (suite *APIImageCreateSuite) TestImageCreateNil(c *check.C) { // TestImageCreateWithoutTag tests creating an image without tag, will use "latest" by default. func (suite *APIImageCreateSuite) TestImageCreateWithoutTag(c *check.C) { q := url.Values{} - q.Add("fromImage", helloworldImage) + q.Add("fromImage", environment.HelloworldRepo) query := request.WithQuery(q) resp, err := request.Post("/images/create", query) c.Assert(err, check.IsNil) @@ -64,7 +64,7 @@ func (suite *APIImageCreateSuite) TestImageCreateWithoutTag(c *check.C) { time.Sleep(5000 * time.Millisecond) - resp, err = request.Delete("/images/" + helloworldImage + ":latest") + resp, err = request.Delete("/images/" + environment.HelloworldRepo + ":latest") c.Assert(err, check.IsNil) CheckRespStatus(c, resp, 204) } diff --git a/test/api_image_inspect_test.go b/test/api_image_inspect_test.go index 38a7410f4..bee407bca 100644 --- a/test/api_image_inspect_test.go +++ b/test/api_image_inspect_test.go @@ -2,12 +2,10 @@ 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" ) // APIImageInspectSuite is the test suite for image inspect API. @@ -20,7 +18,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) + PullImage(c, busyboxImage) } // TestImageInspectOk tests inspecting images is OK. diff --git a/test/cli_alikernel_test.go b/test/cli_alikernel_test.go index d1764a771..1fcae2450 100644 --- a/test/cli_alikernel_test.go +++ b/test/cli_alikernel_test.go @@ -25,7 +25,7 @@ func (suite *PouchAliKernelSuite) SetUpSuite(c *check.C) { environment.PruneAllContainers(apiClient) - command.PouchRun("pull", busyboxImage).Assert(c, icmd.Success) + PullImage(c, busyboxImage) } // TearDownTest does cleanup work in the end of each test. diff --git a/test/cli_create_test.go b/test/cli_create_test.go index 75ec6775e..66e94a2bc 100644 --- a/test/cli_create_test.go +++ b/test/cli_create_test.go @@ -26,7 +26,7 @@ func (suite *PouchCreateSuite) SetUpSuite(c *check.C) { environment.PruneAllContainers(apiClient) - command.PouchRun("pull", busyboxImage).Assert(c, icmd.Success) + PullImage(c, busyboxImage) } // TearDownTest does cleanup work in the end of each test. diff --git a/test/cli_exec_test.go b/test/cli_exec_test.go index 5327f3a7f..e4624322d 100644 --- a/test/cli_exec_test.go +++ b/test/cli_exec_test.go @@ -23,7 +23,7 @@ func (suite *PouchExecSuite) SetUpSuite(c *check.C) { environment.PruneAllContainers(apiClient) - command.PouchRun("pull", busyboxImage).Assert(c, icmd.Success) + PullImage(c, busyboxImage) } // TearDownTest does cleanup work in the end of each test. diff --git a/test/cli_images_test.go b/test/cli_images_test.go index e11b18c66..1c6f44a18 100644 --- a/test/cli_images_test.go +++ b/test/cli_images_test.go @@ -3,6 +3,7 @@ package main import ( "context" "encoding/json" + "fmt" "strings" "github.com/alibaba/pouch/apis/types" @@ -30,7 +31,7 @@ func (suite *PouchImagesSuite) SetUpSuite(c *check.C) { environment.PruneAllContainers(apiClient) - command.PouchRun("pull", busyboxImage).Assert(c, icmd.Success) + PullImage(c, busyboxImage) } // TestImagesWorks tests "pouch image" work. @@ -52,7 +53,8 @@ func (suite *PouchImagesSuite) TestImagesWorks(c *check.C) { resQuiet := command.PouchRun("images", "--quiet").Assert(c, icmd.Success) c.Assert(resQ.Combined(), check.Equals, resQuiet.Combined()) - c.Assert(strings.TrimSpace(resQ.Combined()), check.Equals, utils.TruncateID(image.ID)) + err := util.PartialEqual(strings.TrimSpace(resQ.Combined()), utils.TruncateID(image.ID)) + c.Assert(err, check.IsNil) } // with --digest @@ -106,9 +108,7 @@ func (suite *PouchImagesSuite) TestInspectImage(c *check.C) { // inspect image name output = command.PouchRun("image", "inspect", "-f", "{{.RepoTags}}", busyboxImage).Stdout() - if !strings.Contains(output, busyboxImage) { - c.Fatalf("output %s should contains %s", output, busyboxImage) - } + c.Assert(output, check.Equals, fmt.Sprintf("[%s]\n", busyboxImage)) } // TestLoginAndLogout is to test login and logout command diff --git a/test/cli_inspect_test.go b/test/cli_inspect_test.go index 56a23d590..877544a93 100644 --- a/test/cli_inspect_test.go +++ b/test/cli_inspect_test.go @@ -26,7 +26,7 @@ func (suite *PouchInspectSuite) SetUpSuite(c *check.C) { environment.PruneAllContainers(apiClient) - command.PouchRun("pull", busyboxImage).Assert(c, icmd.Success) + PullImage(c, busyboxImage) } // TearDownTest does cleanup work in the end of each test. diff --git a/test/cli_logs_test.go b/test/cli_logs_test.go index 99727b540..5ec441d34 100644 --- a/test/cli_logs_test.go +++ b/test/cli_logs_test.go @@ -1,12 +1,9 @@ package main import ( - //"github.com/alibaba/pouch/apis/types" - "github.com/alibaba/pouch/test/command" "github.com/alibaba/pouch/test/environment" "github.com/go-check/check" - "github.com/gotestyourself/gotestyourself/icmd" ) // PouchLogsSuite is the test suite for logs CLI. @@ -22,7 +19,7 @@ func (suite *PouchLogsSuite) SetUpSuite(c *check.C) { environment.PruneAllContainers(apiClient) - command.PouchRun("pull", busyboxImage).Assert(c, icmd.Success) + PullImage(c, busyboxImage) } // TearDownTest does cleanup work in the end of each test. diff --git a/test/cli_network_test.go b/test/cli_network_test.go index 98bcdc541..83b14772d 100644 --- a/test/cli_network_test.go +++ b/test/cli_network_test.go @@ -24,7 +24,7 @@ func init() { // SetUpSuite does common setup in the beginning of each test suite. func (suite *PouchNetworkSuite) SetUpSuite(c *check.C) { SkipIfFalse(c, environment.IsLinux) - command.PouchRun("pull", busyboxImage).Assert(c, icmd.Success) + PullImage(c, busyboxImage) // Remove all Containers, in case there are legacy containers connecting network. environment.PruneAllContainers(apiClient) @@ -301,7 +301,6 @@ func (suite *PouchNetworkSuite) TestNetworkCreateDup(c *check.C) { } func (suite *PouchNetworkSuite) TestNetworkPortMapping(c *check.C) { - c.Skip("Skip this test due to httpd image can't be pulled") pc, _, _, _ := runtime.Caller(0) tmpname := strings.Split(runtime.FuncForPC(pc).Name(), ".") var funcname string @@ -319,7 +318,7 @@ func (suite *PouchNetworkSuite) TestNetworkPortMapping(c *check.C) { Out: "It works", } - image := "registry.hub.docker.com/library/httpd" + image := "registry.hub.docker.com/library/httpd:2" command.PouchRun("pull", image).Assert(c, icmd.Success) command.PouchRun("run", "-d", diff --git a/test/cli_ps_test.go b/test/cli_ps_test.go index 82b212d40..74097be08 100644 --- a/test/cli_ps_test.go +++ b/test/cli_ps_test.go @@ -25,7 +25,7 @@ func (suite *PouchPsSuite) SetUpSuite(c *check.C) { SkipIfFalse(c, environment.IsLinux) environment.PruneAllContainers(apiClient) - command.PouchRun("pull", busyboxImage).Assert(c, icmd.Success) + PullImage(c, busyboxImage) } // TearDownTest does cleanup work in the end of each test. diff --git a/test/cli_rich_container_test.go b/test/cli_rich_container_test.go index 1847869ea..9db09a191 100644 --- a/test/cli_rich_container_test.go +++ b/test/cli_rich_container_test.go @@ -29,7 +29,7 @@ func (suite *PouchRichContainerSuite) SetUpSuite(c *check.C) { SkipIfFalse(c, environment.IsLinux) SkipIfFalse(c, environment.IsRuncVersionSupportRichContianer) - command.PouchRun("pull", busyboxImage).Assert(c, icmd.Success) + PullImage(c, busyboxImage) // Use image from AliYun on AliOS. if environment.IsAliKernel() { diff --git a/test/cli_rmi_test.go b/test/cli_rmi_test.go index 16b4ef4c9..c2c23d345 100644 --- a/test/cli_rmi_test.go +++ b/test/cli_rmi_test.go @@ -25,42 +25,42 @@ func (suite *PouchRmiSuite) SetUpSuite(c *check.C) { // TestRmiWorks tests "pouch rmi" work. func (suite *PouchRmiSuite) TestRmiWorks(c *check.C) { - command.PouchRun("pull", helloworldImageLatest).Assert(c, icmd.Success) + command.PouchRun("pull", helloworldImage).Assert(c, icmd.Success) - command.PouchRun("rmi", helloworldImageLatest).Assert(c, icmd.Success) + command.PouchRun("rmi", helloworldImage).Assert(c, icmd.Success) res := command.PouchRun("images").Assert(c, icmd.Success) - if out := res.Combined(); strings.Contains(out, helloworldImageLatest) { - c.Fatalf("unexpected output %s: should rm image %s\n", out, helloworldImageLatest) + if out := res.Combined(); strings.Contains(out, helloworldImage) { + c.Fatalf("unexpected output %s: should rm image %s\n", out, helloworldImage) } } // TestRmiForce tests "pouch rmi -f" work func (suite *PouchRmiSuite) TestRmiForce(c *check.C) { - command.PouchRun("pull", helloworldImageLatest).Assert(c, icmd.Success) + command.PouchRun("pull", helloworldImage).Assert(c, icmd.Success) // TODO: rmi -f after create/start containers. - command.PouchRun("rmi", "-f", helloworldImageLatest).Assert(c, icmd.Success) + command.PouchRun("rmi", "-f", helloworldImage).Assert(c, icmd.Success) res := command.PouchRun("images").Assert(c, icmd.Success) - if out := res.Combined(); strings.Contains(out, helloworldImageLatest) { - c.Fatalf("unexpected output %s: should rm image %s\n", out, helloworldImageLatest) + if out := res.Combined(); strings.Contains(out, helloworldImage) { + c.Fatalf("unexpected output %s: should rm image %s\n", out, helloworldImage) } } // TestRmiByImageID tests "pouch rmi {ID}" work. func (suite *PouchRmiSuite) TestRmiByImageID(c *check.C) { - command.PouchRun("pull", helloworldImageLatest).Assert(c, icmd.Success) + command.PouchRun("pull", helloworldImage).Assert(c, icmd.Success) res := command.PouchRun("images") res.Assert(c, icmd.Success) - imageID := imagesListToKV(res.Combined())[helloworldImageLatest][0] + imageID := imagesListToKV(res.Combined())[helloworldImage][0] command.PouchRun("rmi", imageID).Assert(c, icmd.Success) res = command.PouchRun("images").Assert(c, icmd.Success) - if out := res.Combined(); strings.Contains(out, helloworldImageLatest) { - c.Fatalf("unexpected output %s: should rm image %s\n", out, helloworldImageLatest) + if out := res.Combined(); strings.Contains(out, helloworldImage) { + c.Fatalf("unexpected output %s: should rm image %s\n", out, helloworldImage) } } diff --git a/test/cli_run_test.go b/test/cli_run_test.go index 541c1865c..31e8b5a4d 100644 --- a/test/cli_run_test.go +++ b/test/cli_run_test.go @@ -30,7 +30,7 @@ func (suite *PouchRunSuite) SetUpSuite(c *check.C) { environment.PruneAllContainers(apiClient) - command.PouchRun("pull", busyboxImage).Assert(c, icmd.Success) + PullImage(c, busyboxImage) } // TearDownTest does cleanup work in the end of each test. diff --git a/test/cli_start_test.go b/test/cli_start_test.go index 611f1d8fb..052e2fb32 100644 --- a/test/cli_start_test.go +++ b/test/cli_start_test.go @@ -26,7 +26,7 @@ func (suite *PouchStartSuite) SetUpSuite(c *check.C) { environment.PruneAllContainers(apiClient) - command.PouchRun("pull", busyboxImage).Assert(c, icmd.Success) + PullImage(c, busyboxImage) } // TearDownTest does cleanup work in the end of each test. diff --git a/test/cli_stop_test.go b/test/cli_stop_test.go index 2f9368980..ebaff1e76 100644 --- a/test/cli_stop_test.go +++ b/test/cli_stop_test.go @@ -23,7 +23,7 @@ func (suite *PouchStopSuite) SetUpSuite(c *check.C) { environment.PruneAllContainers(apiClient) - command.PouchRun("pull", busyboxImage).Assert(c, icmd.Success) + PullImage(c, busyboxImage) } // TearDownTest does cleanup work in the end of each test. diff --git a/test/cli_top_test.go b/test/cli_top_test.go index 5aecf041a..39fac8737 100644 --- a/test/cli_top_test.go +++ b/test/cli_top_test.go @@ -24,7 +24,7 @@ func (suite *PouchTopSuite) SetUpSuite(c *check.C) { environment.PruneAllContainers(apiClient) - command.PouchRun("pull", busyboxImage).Assert(c, icmd.Success) + PullImage(c, busyboxImage) } // TearDownTest does cleanup work in the end of each test. diff --git a/test/cli_unpause_test.go b/test/cli_unpause_test.go index 7d71d1a2f..d0e4341cd 100644 --- a/test/cli_unpause_test.go +++ b/test/cli_unpause_test.go @@ -19,7 +19,7 @@ func init() { func (suite *PouchUnpauseSuite) SetUpSuite(c *check.C) { SkipIfFalse(c, environment.IsLinux) - command.PouchRun("pull", busyboxImage).Assert(c, icmd.Success) + PullImage(c, busyboxImage) } // TearDownTest does cleanup work in the end of each test. diff --git a/test/cli_update_test.go b/test/cli_update_test.go index 4b36aa8e1..b409b9820 100644 --- a/test/cli_update_test.go +++ b/test/cli_update_test.go @@ -27,7 +27,7 @@ func (suite *PouchUpdateSuite) SetUpSuite(c *check.C) { environment.PruneAllContainers(apiClient) - command.PouchRun("pull", busyboxImage).Assert(c, icmd.Success) + PullImage(c, busyboxImage) } // TearDownTest does cleanup work in the end of each test. diff --git a/test/cli_upgrade_test.go b/test/cli_upgrade_test.go index 1436b775a..d5d23a340 100644 --- a/test/cli_upgrade_test.go +++ b/test/cli_upgrade_test.go @@ -28,7 +28,7 @@ func (suite *PouchUpgradeSuite) SetUpSuite(c *check.C) { environment.PruneAllContainers(apiClient) - command.PouchRun("pull", busyboxImage).Assert(c, icmd.Success) + PullImage(c, busyboxImage) command.PouchRun("pull", busyboxImage125).Assert(c, icmd.Success) } @@ -82,7 +82,7 @@ func (suite *PouchUpgradeSuite) TestPouchUpgradeStoppedContainer(c *check.C) { c.Assert(res.Error, check.IsNil) if out := res.Combined(); !strings.Contains(out, name) { - c.Fatalf("unexpected output: %s, expected %s", out, name) + c.Fatal("unexpected output: %s, expected %s", out, name) } command.PouchRun("start", name).Assert(c, icmd.Success) diff --git a/test/cli_volume_test.go b/test/cli_volume_test.go index d3d097c67..e4f5a2303 100644 --- a/test/cli_volume_test.go +++ b/test/cli_volume_test.go @@ -25,7 +25,7 @@ func init() { func (suite *PouchVolumeSuite) SetUpSuite(c *check.C) { SkipIfFalse(c, environment.IsLinux) - command.PouchRun("pull", busyboxImage).Assert(c, icmd.Success) + PullImage(c, busyboxImage) } // TestVolumeWorks tests "pouch volume" work. diff --git a/test/daemon/daemon.go b/test/daemon/daemon.go index ad76542b5..a323f4113 100644 --- a/test/daemon/daemon.go +++ b/test/daemon/daemon.go @@ -48,6 +48,11 @@ type Config struct { // DConfig is the global variable used to pouch daemon test. var DConfig Config +func init() { + DConfig.Args = make([]string, 0, 1) + DConfig.Listen = make([]string, 0, 1) +} + // NewConfig initialize the DConfig with default value. func NewConfig() Config { result := Config{} @@ -55,13 +60,11 @@ func NewConfig() Config { result.Bin = PouchdBin result.LogPath = DaemonLog - result.Args = make([]string, 0, 1) result.Args = append(result.Args, "--listen="+Listen) result.Args = append(result.Args, "--home-dir="+HomeDir) result.Args = append(result.Args, "--containerd="+ContainerdAdd) result.Args = append(result.Args, "--listen-cri="+ListenCRI) - result.Listen = make([]string, 0, 1) result.Listen = append(result.Listen, Listen) result.HomeDir = HomeDir @@ -156,14 +159,14 @@ func (d *Config) KillDaemon() { return } - if _, err := os.Stat(d.HomeDir); err == nil { - err = os.RemoveAll(d.HomeDir) - if err != nil { - fmt.Printf("remove path %s failed, this may effect start pouchd in the same path", - d.HomeDir) - return - } - } + //if _, err := os.Stat(d.HomeDir); err == nil { + // err = os.RemoveAll(d.HomeDir) + // if err != nil { + // fmt.Printf("remove path %s failed, this may effect start pouchd in the same path", + // d.HomeDir) + // return + // } + //} d.LogFile.Close() } diff --git a/test/environment/env.go b/test/environment/env.go index 1087d1af1..0f8c4ec6d 100644 --- a/test/environment/env.go +++ b/test/environment/env.go @@ -5,6 +5,7 @@ import ( "runtime" "github.com/alibaba/pouch/client" + "github.com/gotestyourself/gotestyourself/icmd" ) @@ -20,8 +21,56 @@ var ( // TLSConfig is default tls config TLSConfig = client.TLSConfig{} + + // BusyboxRepo the repository of busybox image + BusyboxRepo = "registry.hub.docker.com/library/busybox" + + // BusyboxTag the tag used for busybox image + BusyboxTag = "1.28" + + // HelloworldRepo the repository of hello-world image + HelloworldRepo = "registry.hub.docker.com/library/hello-world" + + // HelloworldTag the tag used for hello-world image + HelloworldTag = "linux" + + // GateWay default gateway for test + GateWay = "192.168.1.1" + + // Subnet default subnet for test + Subnet = "192.168.1.0/24" ) +// GetBusybox get image info from test envrionment variable. +func GetBusybox() { + if len(os.Getenv("POUCH_BUSYBOXREPO")) != 0 { + BusyboxRepo = os.Getenv("POUCH_BUSYBOXREPO") + } + if len(os.Getenv("POUCH_BUSYBOXTAG")) != 0 { + BusyboxTag = os.Getenv("POUCH_BUSYBOXTAG") + } +} + +// GetHelloWorld get image info from test envrionment variable. +func GetHelloWorld() { + if len(os.Getenv("POUCH_HELLOWORLDREPO")) != 0 { + HelloworldRepo = os.Getenv("POUCH_HELLOWORLDREPO") + } + if len(os.Getenv("POUCH_HELLOWORLDTAG")) != 0 { + HelloworldTag = os.Getenv("POUCH_HELLOWORLDTAG") + } +} + +// GetTestNetwork get gateway and subnet from test environment variable. +func GetTestNetwork() { + if len(os.Getenv("POUCH_TEST_GATEWAY")) != 0 { + GateWay = os.Getenv("POUCH_TEST_GATEWAY") + } + if len(os.Getenv("POUCH_TEST_SUBNET")) != 0 { + Subnet = os.Getenv("POUCH_TEST_SUBNET") + } +} + // IsLinux checks if the OS of test environment is Linux. func IsLinux() bool { return runtime.GOOS == "linux" @@ -66,3 +115,15 @@ func IsDiskQuota() bool { } return false } + +// IsPrjquota checks if there is prjquota set on test machine +func IsPrjquota() bool { + return IsDiskQuota() && + (icmd.RunCommand("mount", "|grep prjquota").ExitCode == 0) +} + +// IsGrpquota checks if there is grpquota set on test machine +func IsGrpquota() bool { + return IsDiskQuota() && + (icmd.RunCommand("mount", "|grep grpquota").ExitCode == 0) +} diff --git a/test/main_test.go b/test/main_test.go index 584901660..f819c8cae 100644 --- a/test/main_test.go +++ b/test/main_test.go @@ -6,6 +6,7 @@ import ( "testing" "github.com/alibaba/pouch/client" + "github.com/alibaba/pouch/test/command" "github.com/alibaba/pouch/test/environment" "github.com/go-check/check" ) @@ -26,6 +27,8 @@ func TestMain(m *testing.M) { } apiClient = commonAPIClient.(*client.APIClient) + command.PouchRun("pull", busyboxImage) + os.Exit(m.Run()) } diff --git a/test/util_api.go b/test/util_api.go index 02dcfd0fc..687815290 100644 --- a/test/util_api.go +++ b/test/util_api.go @@ -255,3 +255,17 @@ func DelNetworkOk(c *check.C, cname string) { func DelNetwork(c *check.C, cname string) (*http.Response, error) { return request.Delete("/networks/" + cname) } + +// PullImage pull image if it doesn't exist, image format should be repo:tag. +func PullImage(c *check.C, image string) { + resp, err := request.Get("/images/" + image + "/json") + c.Assert(err, check.IsNil) + + if resp.StatusCode == 404 { + q := url.Values{} + q.Add("fromImage", image) + query := request.WithQuery(q) + resp, err = request.Post("/images/create", query) + c.Assert(resp.StatusCode, check.Equals, 200) + } +} diff --git a/test/utils.go b/test/utils.go index 190ff8420..9a453aa7d 100644 --- a/test/utils.go +++ b/test/utils.go @@ -1,25 +1,44 @@ package main import ( + "github.com/alibaba/pouch/test/environment" + "github.com/go-check/check" ) // const defines common image name -const ( - busyboxImage = "registry.hub.docker.com/library/busybox:latest" - busyboxImage125 = "registry.hub.docker.com/library/busybox:1.25" - helloworldImage = "registry.hub.docker.com/library/hello-world" - helloworldImageLatest = "registry.hub.docker.com/library/hello-world:latest" +var ( + busyboxImage string + helloworldImage string helloworldImageOnlyRepoName = "hello-world" - GateWay = "192.168.1.1" - Subnet = "192.168.1.0/24" + // GateWay test gateway + GateWay string - testHubAddress = "registry.hub.docker.com" - testHubUser = "pouchcontainertest" - testHubPasswd = "pouchcontainertest" + // Subnet test subnet + Subnet string +) + +const ( + busyboxImage125 = "registry.hub.docker.com/library/busybox:1.25" + testHubAddress = "registry.hub.docker.com" + testHubUser = "pouchcontainertest" + testHubPasswd = "pouchcontainertest" ) +func init() { + // Get test images config from test environment. + environment.GetBusybox() + environment.GetHelloWorld() + + busyboxImage = environment.BusyboxRepo + ":" + environment.BusyboxTag + helloworldImage = environment.HelloworldRepo + ":" + environment.HelloworldTag + + GateWay = environment.GateWay + Subnet = environment.Subnet + +} + // VerifyCondition is used to check the condition value. type VerifyCondition func() bool diff --git a/test/z_cli_daemon_test.go b/test/z_cli_daemon_test.go index 2a6858c42..abedc7339 100644 --- a/test/z_cli_daemon_test.go +++ b/test/z_cli_daemon_test.go @@ -10,6 +10,7 @@ import ( "github.com/alibaba/pouch/test/environment" "github.com/go-check/check" + "github.com/gotestyourself/gotestyourself/icmd" ) // PouchDaemonSuite is the test suite fo daemon. @@ -64,7 +65,7 @@ func (suite *PouchDaemonSuite) TestDaemonCgroupParent(c *check.C) { c.Errorf("failed to decode inspect output: %v", err) } - // test if cgroup has the right parent path + //// test if cgroup has the right parent path //path := fmt.Sprintf("/sys/fs/cgroup/memory/tmp/%s", result.ID) //_, err = os.Stat(path) //if err != nil { @@ -72,3 +73,56 @@ func (suite *PouchDaemonSuite) TestDaemonCgroupParent(c *check.C) { // c.Fatalf("get cgroup path failed, err:%s", err) //} } + +// TestDaemonListenTCP tests daemon listen with tcp address. +func (suite *PouchDaemonSuite) TestDaemonListenTCP(c *check.C) { + // Start a test daemon with test args. + tcp := "tcp://127.0.0.1:5151" + daemon.DConfig = daemon.NewConfig() + daemon.DConfig.Listen = append(daemon.DConfig.Listen, tcp) + daemon.DConfig.Args = append(daemon.DConfig.Args, "--listen="+tcp) + + err := daemon.DConfig.StartDaemon() + if err != nil { + fmt.Printf("start deamon failed with error:%s", err) + daemon.DConfig.DumpLog() + c.Skip("deamon start failed.") + } + + // verify listen to tcp works + command.PouchRun("--host", tcp, "version").Assert(c, icmd.Success) + + // Must kill it, as we may loose the pid in next call. + defer daemon.DConfig.KillDaemon() +} + +// TestDaemonConfigFile tests start daemon with configfile works. +func (suite *PouchDaemonSuite) TestDaemonConfigFile(c *check.C) { + //configFile := "/etc/pouch/config.json" + //err := os.MkdirAll("/etc/pouch", 0777) + //c.Assert(err, check.IsNil) + // + //file, err := os.Create(configFile) + //c.Assert(err, check.IsNil) + //defer os.Remove(configFile) + // + //// Construct configure file + //file.WriteString("--quota-driver grpquota\n") + // + //daemon.DConfig = daemon.NewConfig() + //daemon.DConfig.Args = append(daemon.DConfig.Args, "--config-file="+configFile) + // + //{ + // err := daemon.DConfig.StartDaemon() + // if err != nil { + // fmt.Printf("start deamon failed with error:%s", err) + // daemon.DConfig.DumpLog() + // c.Skip("deamon start failed.") + // } + //} + // + //// TODO: verify quota driver is grpquota. + // + //// Must kill it, as we may loose the pid in next call. + //defer daemon.DConfig.KillDaemon() +}