-
Notifications
You must be signed in to change notification settings - Fork 742
add the function of restartest #683
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,55 @@ | ||
| package main | ||
|
|
||
| import ( | ||
| "fmt" | ||
| "io/ioutil" | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Deprecated ( https://golang.org/doc/go1.16#ioutil) plz use |
||
| "strings" | ||
| "testing" | ||
| "time" | ||
|
|
||
| "github.com/containerd/nerdctl/pkg/testutil" | ||
| "github.com/pkg/errors" | ||
| "gotest.tools/v3/assert" | ||
| ) | ||
|
|
||
| func TestRestart(t *testing.T) { | ||
| const ( | ||
| hostPort = 8080 | ||
| testContainerName = "nerdctl-test-stop-start-nginx" | ||
| sleepTime = 3 * time.Second | ||
| ) | ||
| base := testutil.NewBase(t) | ||
| defer base.Cmd("rm", "-f", testContainerName).Run() | ||
|
|
||
| base.Cmd("run", "-d", | ||
| "--restart=no", | ||
| "--name", testContainerName, | ||
| "-p", fmt.Sprintf("127.0.0.1:%d:80", hostPort), | ||
| testutil.NginxAlpineImage).AssertOK() | ||
|
|
||
| check := func(httpGetRetry int) error { | ||
| resp, err := httpGet(fmt.Sprintf("http://127.0.0.1:%d", hostPort), httpGetRetry) | ||
| if err != nil { | ||
| return err | ||
| } | ||
| respBody, err := ioutil.ReadAll(resp.Body) | ||
| if err != nil { | ||
| return err | ||
| } | ||
| if !strings.Contains(string(respBody), testutil.NginxAlpineIndexHTMLSnippet) { | ||
| return errors.Errorf("expected contain %q, got %q", | ||
| testutil.NginxAlpineIndexHTMLSnippet, string(respBody)) | ||
| } | ||
| return nil | ||
| } | ||
|
|
||
| assert.NilError(t, check(30)) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why check the container output Before excuting restart ? |
||
|
|
||
| base.Cmd("restart", testContainerName).AssertOK() | ||
| base.Cmd("exec", testContainerName, "ps").AssertOK() | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why exec here ? Check not enough ? |
||
| time.Sleep(sleepTime) | ||
| if check(3) != nil { | ||
| t.Fatal("restart faild,expected to get an error") | ||
| } | ||
| assert.NilError(t, check(30)) | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Needs copyright header
nerdctl/cmd/nerdctl/main.go
Lines 1 to 17 in 12a06bb