old test file will create a leak file in current directory.

this patch fix this.
	modified:   pkg/kubelet/cm/deviceplugin/manager_test.go
This commit is contained in:
WanLinghao 2017-12-07 10:34:53 +08:00
parent 050956b08e
commit 3e7e4ab397

View File

@ -19,6 +19,8 @@ package deviceplugin
import ( import (
"flag" "flag"
"fmt" "fmt"
"io/ioutil"
"os"
"reflect" "reflect"
"sync/atomic" "sync/atomic"
"testing" "testing"
@ -260,7 +262,12 @@ func TestCheckpoint(t *testing.T) {
resourceName1 := "domain1.com/resource1" resourceName1 := "domain1.com/resource1"
resourceName2 := "domain2.com/resource2" resourceName2 := "domain2.com/resource2"
as := assert.New(t)
tmpDir, err := ioutil.TempDir("", "checkpoint")
as.Nil(err)
defer os.RemoveAll(tmpDir)
testManager := &ManagerImpl{ testManager := &ManagerImpl{
socketdir: tmpDir,
allDevices: make(map[string]sets.String), allDevices: make(map[string]sets.String),
allocatedDevices: make(map[string]sets.String), allocatedDevices: make(map[string]sets.String),
podDevices: make(podDevices), podDevices: make(podDevices),
@ -298,8 +305,7 @@ func TestCheckpoint(t *testing.T) {
expectedAllocatedDevices := testManager.podDevices.devices() expectedAllocatedDevices := testManager.podDevices.devices()
expectedAllDevices := testManager.allDevices expectedAllDevices := testManager.allDevices
err := testManager.writeCheckpoint() err = testManager.writeCheckpoint()
as := assert.New(t)
as.Nil(err) as.Nil(err)
testManager.podDevices = make(podDevices) testManager.podDevices = make(podDevices)
@ -385,7 +391,11 @@ func TestPodContainerDeviceAllocation(t *testing.T) {
nodeInfo := &schedulercache.NodeInfo{} nodeInfo := &schedulercache.NodeInfo{}
nodeInfo.SetNode(cachedNode) nodeInfo.SetNode(cachedNode)
tmpDir, err := ioutil.TempDir("", "checkpoint")
as.Nil(err)
defer os.RemoveAll(tmpDir)
testManager := &ManagerImpl{ testManager := &ManagerImpl{
socketdir: tmpDir,
callback: monitorCallback, callback: monitorCallback,
allDevices: make(map[string]sets.String), allDevices: make(map[string]sets.String),
allocatedDevices: make(map[string]sets.String), allocatedDevices: make(map[string]sets.String),
@ -485,7 +495,7 @@ func TestPodContainerDeviceAllocation(t *testing.T) {
} }
podsStub.updateActivePods([]*v1.Pod{pod}) podsStub.updateActivePods([]*v1.Pod{pod})
err := testManager.Allocate(nodeInfo, &lifecycle.PodAdmitAttributes{Pod: pod}) err = testManager.Allocate(nodeInfo, &lifecycle.PodAdmitAttributes{Pod: pod})
as.Nil(err) as.Nil(err)
runContainerOpts := testManager.GetDeviceRunContainerOptions(pod, &pod.Spec.Containers[0]) runContainerOpts := testManager.GetDeviceRunContainerOptions(pod, &pod.Spec.Containers[0])
as.NotNil(runContainerOpts) as.NotNil(runContainerOpts)