forked from kata-containers/tests
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
functional: Add test checking for container state
Following an issue that we found with the kata-runtime regarding a wrong state being reported after the container workload terminated, this patch introduces a test that runs a simple container workload and validate that the value obtained after a few seconds is "stopped". Previously, this test would have failed as we would have retrieved "running", which is a wrong value in this case. Fixes kata-containers#956 Signed-off-by: Sebastien Boeuf <[email protected]>
- Loading branch information
Sebastien Boeuf
committed
Nov 29, 2018
1 parent
1c7f5e6
commit d9e2fbc
Showing
2 changed files
with
74 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
// Copyright (c) 2018 Intel Corporation | ||
// | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package functional | ||
|
||
import ( | ||
"fmt" | ||
"time" | ||
|
||
. "github.com/kata-containers/tests" | ||
. "github.com/onsi/ginkgo" | ||
. "github.com/onsi/ginkgo/extensions/table" | ||
. "github.com/onsi/gomega" | ||
) | ||
|
||
var ( | ||
stateWorkload = []string{"true"} | ||
) | ||
|
||
const ( | ||
stateStopped = "stopped" | ||
stateWaitTime = 5 | ||
) | ||
|
||
var _ = Describe("state", func() { | ||
var ( | ||
container *Container | ||
err error | ||
) | ||
|
||
BeforeEach(func() { | ||
container, err = NewContainer(stateWorkload, true) | ||
Expect(err).NotTo(HaveOccurred()) | ||
Expect(container).NotTo(BeNil()) | ||
}) | ||
|
||
AfterEach(func() { | ||
Expect(container.Teardown()).To(Succeed()) | ||
}) | ||
|
||
DescribeTable("container", | ||
func(status string, waitTime int) { | ||
_, stderr, exitCode := container.Run() | ||
Expect(exitCode).To(Equal(0)) | ||
Expect(stderr).To(BeEmpty()) | ||
|
||
time.Sleep(time.Second * time.Duration(waitTime)) | ||
|
||
stdout, stderr, exitCode := container.State() | ||
Expect(exitCode).To(Equal(0)) | ||
Expect(stderr).To(BeEmpty()) | ||
subString := fmt.Sprintf("\"status\": \"%s\"", status) | ||
Expect(stdout).To(ContainSubstring(subString)) | ||
}, | ||
Entry(fmt.Sprintf("with workload %s, timeWait %d", stateWorkload, stateWaitTime), stateStopped, stateWaitTime), | ||
) | ||
}) |