-
Notifications
You must be signed in to change notification settings - Fork 949
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #944 from HusterWan/zr/finish-restart-interface
feature: finish restart interface
- Loading branch information
Showing
9 changed files
with
203 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package main | ||
|
||
import ( | ||
"net/url" | ||
|
||
"github.com/alibaba/pouch/test/environment" | ||
"github.com/alibaba/pouch/test/request" | ||
|
||
"github.com/go-check/check" | ||
) | ||
|
||
// APIContainerRestartSuite is the test suite for container upgrade API. | ||
type APIContainerRestartSuite struct{} | ||
|
||
func init() { | ||
check.Suite(&APIContainerRestartSuite{}) | ||
} | ||
|
||
// SetUpTest does common setup in the beginning of each test. | ||
func (suite *APIContainerRestartSuite) SetUpTest(c *check.C) { | ||
SkipIfFalse(c, environment.IsLinux) | ||
} | ||
|
||
// TestAPIContainerRestart is to verify restarting container. | ||
func (suite *APIContainerRestartSuite) TestAPIContainerRestart(c *check.C) { | ||
cname := "TestAPIContainerRestart" | ||
|
||
CreateBusyboxContainerOk(c, cname) | ||
|
||
resp, err := request.Post("/containers/" + cname + "/start") | ||
c.Assert(err, check.IsNil) | ||
CheckRespStatus(c, resp, 204) | ||
|
||
q := url.Values{} | ||
q.Add("t", "1") | ||
query := request.WithQuery(q) | ||
|
||
resp, err = request.Post("/containers/"+cname+"/restart", query) | ||
c.Assert(err, check.IsNil) | ||
CheckRespStatus(c, resp, 204) | ||
|
||
DelContainerForceOk(c, cname) | ||
} | ||
|
||
// TestAPIRestartStoppedContainer it to verify restarting a stopped container. | ||
func (suite *APIContainerRestartSuite) TestAPIRestartStoppedContainer(c *check.C) { | ||
cname := "TestAPIContainerRestart" | ||
|
||
CreateBusyboxContainerOk(c, cname) | ||
|
||
q := url.Values{} | ||
q.Add("t", "1") | ||
query := request.WithQuery(q) | ||
|
||
resp, err := request.Post("/containers/"+cname+"/restart", query) | ||
c.Assert(err, check.IsNil) | ||
CheckRespStatus(c, resp, 500) | ||
|
||
DelContainerForceOk(c, cname) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
package main | ||
|
||
import ( | ||
"strings" | ||
|
||
"github.com/alibaba/pouch/test/command" | ||
"github.com/alibaba/pouch/test/environment" | ||
|
||
"github.com/go-check/check" | ||
"github.com/gotestyourself/gotestyourself/icmd" | ||
) | ||
|
||
// PouchRestartSuite is the test suite for restart CLI. | ||
type PouchRestartSuite struct{} | ||
|
||
func init() { | ||
check.Suite(&PouchRestartSuite{}) | ||
} | ||
|
||
// SetUpSuite does common setup in the beginning of each test suite. | ||
func (suite *PouchRestartSuite) SetUpSuite(c *check.C) { | ||
SkipIfFalse(c, environment.IsLinux) | ||
|
||
environment.PruneAllContainers(apiClient) | ||
|
||
command.PouchRun("pull", busyboxImage).Assert(c, icmd.Success) | ||
} | ||
|
||
// TearDownTest does cleanup work in the end of each test. | ||
func (suite *PouchRestartSuite) TearDownTest(c *check.C) { | ||
} | ||
|
||
// TestPouchRestart is to verify the correctness of restarting a running container. | ||
func (suite *PouchRestartSuite) TestPouchRestart(c *check.C) { | ||
name := "TestPouchRestart" | ||
|
||
command.PouchRun("run", "-d", "--cpu-share", "20", "--name", name, busyboxImage).Assert(c, icmd.Success) | ||
|
||
res := command.PouchRun("restart", "-t", "1", name) | ||
c.Assert(res.Error, check.IsNil) | ||
|
||
if out := res.Combined(); !strings.Contains(out, name) { | ||
c.Fatalf("unexpected output: %s, expected: %s", out, name) | ||
} | ||
|
||
command.PouchRun("rm", "-f", name).Assert(c, icmd.Success) | ||
} | ||
|
||
// TestPouchRestartStoppedContainer is to verify the correctness of restarting a stopped container. | ||
func (suite *PouchRestartSuite) TestPouchRestartStoppedContainer(c *check.C) { | ||
name := "TestPouchRestartStoppedContainer" | ||
|
||
command.PouchRun("create", "--name", name, busyboxImage).Assert(c, icmd.Success) | ||
|
||
res := command.PouchRun("restart", "-t", "1", name) | ||
c.Assert(res.Error, check.NotNil) | ||
|
||
expectString := "cannot restart a non running container" | ||
if out := res.Combined(); !strings.Contains(out, expectString) { | ||
c.Fatalf("unexpected output: %s, expected: %s", out, expectString) | ||
} | ||
|
||
command.PouchRun("rm", "-f", name).Assert(c, icmd.Success) | ||
} |