test: delete pod in test cleanup

Otherwise there might be cached pod alive even if we remove
all the config dirs etc.

Signed-off-by: Peng Tao <bergwolf@gmail.com>
This commit is contained in:
Peng Tao
2018-04-08 09:58:18 +08:00
parent 81bb561467
commit b353e36373
4 changed files with 17 additions and 0 deletions

View File

@@ -1029,6 +1029,7 @@ func TestStatusPodFailingFetchPodConfig(t *testing.T) {
path := filepath.Join(configStoragePath, p.ID())
os.RemoveAll(path)
globalPodList.removePod(p.ID())
_, err = StatusPod(p.ID())
if err == nil {
@@ -1050,6 +1051,7 @@ func TestStatusPodPodFailingFetchPodState(t *testing.T) {
assert.True(t, ok)
os.RemoveAll(pImpl.configPath)
globalPodList.removePod(p.ID())
_, err = StatusPod(p.ID())
if err == nil {
@@ -1932,6 +1934,7 @@ func TestStatusContainerFailing(t *testing.T) {
assert.True(t, ok)
os.RemoveAll(pImpl.configPath)
globalPodList.removePod(p.ID())
_, err = StatusContainer(p.ID(), contID)
if err == nil {

View File

@@ -56,6 +56,7 @@ func TestNoopAgentExec(t *testing.T) {
if err != nil {
t.Fatal(err)
}
defer cleanUp()
if _, err = n.exec(pod, *container, cmd); err != nil {
t.Fatal(err)
@@ -88,6 +89,7 @@ func TestNoopAgentCreateContainer(t *testing.T) {
if err != nil {
t.Fatal(err)
}
defer cleanUp()
if err := n.startPod(*pod); err != nil {
t.Fatal(err)
@@ -104,6 +106,7 @@ func TestNoopAgentStartContainer(t *testing.T) {
if err != nil {
t.Fatal(err)
}
defer cleanUp()
err = n.startContainer(*pod, container)
if err != nil {
@@ -117,6 +120,7 @@ func TestNoopAgentStopContainer(t *testing.T) {
if err != nil {
t.Fatal(err)
}
defer cleanUp()
err = n.stopContainer(*pod, *container)
if err != nil {

View File

@@ -86,6 +86,7 @@ func TestCreateEmtpyPod(t *testing.T) {
if err == nil {
t.Fatalf("VirtContainers should not allow empty pods")
}
defer cleanUp()
}
func TestCreateEmtpyHypervisorPod(t *testing.T) {
@@ -93,6 +94,7 @@ func TestCreateEmtpyHypervisorPod(t *testing.T) {
if err == nil {
t.Fatalf("VirtContainers should not allow pods with empty hypervisors")
}
defer cleanUp()
}
func TestCreateMockPod(t *testing.T) {
@@ -102,6 +104,7 @@ func TestCreateMockPod(t *testing.T) {
if err != nil {
t.Fatal(err)
}
defer cleanUp()
}
func TestCreatePodEmtpyID(t *testing.T) {
@@ -111,6 +114,7 @@ func TestCreatePodEmtpyID(t *testing.T) {
if err == nil {
t.Fatalf("Expected pod with empty ID to fail, but got pod %v", p)
}
defer cleanUp()
}
func testPodStateTransition(t *testing.T, state stateString, newState stateString) error {
@@ -120,6 +124,7 @@ func testPodStateTransition(t *testing.T, state stateString, newState stateStrin
if err != nil {
return err
}
defer cleanUp()
p.state = State{
State: state,
@@ -537,6 +542,7 @@ func TestPodSetPodAndContainerState(t *testing.T) {
if err != nil {
t.Fatal(err)
}
defer cleanUp()
l := len(p.GetAllContainers())
if l != 1 {
@@ -896,6 +902,7 @@ func TestPodGetContainer(t *testing.T) {
if err != nil {
t.Fatal(err)
}
defer cleanUp()
contID := "999"
contConfig := newTestContainerConfigNoop(contID)
@@ -941,6 +948,7 @@ func TestContainerSetStateBlockIndex(t *testing.T) {
if err != nil {
t.Fatal(err)
}
defer cleanUp()
fs := &filesystem{}
pod.storage = fs
@@ -1039,6 +1047,7 @@ func TestContainerStateSetFstype(t *testing.T) {
if err != nil {
t.Fatal(err)
}
defer cleanUp()
fs := &filesystem{}
pod.storage = fs

View File

@@ -55,6 +55,7 @@ var testHyperstartTtySocket = ""
// cleanUp Removes any stale pod/container state that can affect
// the next test to run.
func cleanUp() {
globalPodList.removePod(testPodID)
for _, dir := range []string{testDir, defaultSharedDir} {
os.RemoveAll(dir)
os.MkdirAll(dir, dirMode)