Skip to content
This repository was archived by the owner on May 12, 2021. It is now read-only.

Commit d0173c0

Browse files
authored
Merge pull request #2968 from Kvasscn/fix-warning-in-device-manager-test
[backport | master] devices: fix go test warning in manager_test.go
2 parents 40cc2aa + eab5102 commit d0173c0

File tree

1 file changed

+16
-4
lines changed

1 file changed

+16
-4
lines changed

virtcontainers/device/manager/manager_test.go

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ func TestAttachVFIODevice(t *testing.T) {
105105
}
106106
tmpDir, err := ioutil.TempDir("", "")
107107
assert.Nil(t, err)
108-
os.RemoveAll(tmpDir)
108+
defer os.RemoveAll(tmpDir)
109109

110110
testFDIOGroup := "2"
111111
testDeviceBDFPath := "0000:00:1c.0"
@@ -114,15 +114,27 @@ func TestAttachVFIODevice(t *testing.T) {
114114
err = os.MkdirAll(devicesDir, dirMode)
115115
assert.Nil(t, err)
116116

117-
deviceFile := filepath.Join(devicesDir, testDeviceBDFPath)
118-
_, err = os.Create(deviceFile)
117+
deviceBDFDir := filepath.Join(devicesDir, testDeviceBDFPath)
118+
err = os.MkdirAll(deviceBDFDir, dirMode)
119+
assert.Nil(t, err)
120+
121+
deviceClassFile := filepath.Join(deviceBDFDir, "class")
122+
_, err = os.Create(deviceClassFile)
123+
assert.Nil(t, err)
124+
125+
deviceConfigFile := filepath.Join(deviceBDFDir, "config")
126+
_, err = os.Create(deviceConfigFile)
119127
assert.Nil(t, err)
120128

121129
savedIOMMUPath := config.SysIOMMUPath
122130
config.SysIOMMUPath = tmpDir
123131

132+
savedSysBusPciDevicesPath := config.SysBusPciDevicesPath
133+
config.SysBusPciDevicesPath = devicesDir
134+
124135
defer func() {
125136
config.SysIOMMUPath = savedIOMMUPath
137+
config.SysBusPciDevicesPath = savedSysBusPciDevicesPath
126138
}()
127139

128140
path := filepath.Join(vfioPath, testFDIOGroup)
@@ -220,7 +232,7 @@ func TestAttachVhostUserBlkDevice(t *testing.T) {
220232
vhostUserStorePath: tmpDir,
221233
}
222234
assert.Nil(t, err)
223-
os.RemoveAll(tmpDir)
235+
defer os.RemoveAll(tmpDir)
224236

225237
vhostUserDevNodePath := filepath.Join(tmpDir, "/block/devices/")
226238
vhostUserSockPath := filepath.Join(tmpDir, "/block/sockets/")

0 commit comments

Comments
 (0)