mirror of
https://github.com/intel/intel-device-plugins-for-kubernetes.git
synced 2025-06-03 03:59:37 +00:00
fpga tests cleanup
- used t.Run api for better visibility - used ioutil.TempDir to create temporary directories Signed-off-by: Ed Bartosh <eduard.bartosh@intel.com>
This commit is contained in:
parent
08fde67a88
commit
2ec6677ab0
@ -15,13 +15,12 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
"path"
|
"path"
|
||||||
"reflect"
|
"reflect"
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
|
||||||
|
|
||||||
dpapi "github.com/intel/intel-device-plugins-for-kubernetes/pkg/deviceplugin"
|
dpapi "github.com/intel/intel-device-plugins-for-kubernetes/pkg/deviceplugin"
|
||||||
pluginapi "k8s.io/kubelet/pkg/apis/deviceplugin/v1beta1"
|
pluginapi "k8s.io/kubelet/pkg/apis/deviceplugin/v1beta1"
|
||||||
@ -48,10 +47,15 @@ func TestNewDevicePluginDFL(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for _, tcase := range tcases {
|
for _, tcase := range tcases {
|
||||||
_, err := newDevicePluginDFL("", "", tcase.mode)
|
t.Run(tcase.mode, func(t *testing.T) {
|
||||||
if tcase.expectedErr && err == nil {
|
_, err := newDevicePluginDFL("", "", tcase.mode)
|
||||||
t.Error("No error generated when creating Cache with invalid parameters")
|
if tcase.expectedErr && err == nil {
|
||||||
}
|
t.Error("Unexpected success")
|
||||||
|
}
|
||||||
|
if !tcase.expectedErr && err != nil {
|
||||||
|
t.Errorf("Unexpected error: %+v", err)
|
||||||
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -282,7 +286,10 @@ func TestGetAfuTreeDFL(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestScanFPGAsDFL(t *testing.T) {
|
func TestScanFPGAsDFL(t *testing.T) {
|
||||||
tmpdir := fmt.Sprintf("/tmp/fpgaplugin-TestDiscoverFPGAs-%d", time.Now().Unix())
|
tmpdir, err := ioutil.TempDir("", "TestScanFPGAsDFL")
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("can't create temporary directory: %+v", err)
|
||||||
|
}
|
||||||
sysfs := path.Join(tmpdir, "sys", "class", "fpga_region")
|
sysfs := path.Join(tmpdir, "sys", "class", "fpga_region")
|
||||||
devfs := path.Join(tmpdir, "dev")
|
devfs := path.Join(tmpdir, "dev")
|
||||||
tcases := []struct {
|
tcases := []struct {
|
||||||
@ -490,32 +497,34 @@ func TestScanFPGAsDFL(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for _, tcase := range tcases {
|
for _, tcase := range tcases {
|
||||||
err := createTestDirs(devfs, sysfs, tcase.devfsdirs, tcase.sysfsdirs, tcase.sysfsfiles)
|
t.Run(tcase.name, func(t *testing.T) {
|
||||||
if err != nil {
|
err := createTestDirs(devfs, sysfs, tcase.devfsdirs, tcase.sysfsdirs, tcase.sysfsfiles)
|
||||||
t.Fatalf("%+v", err)
|
if err != nil {
|
||||||
}
|
t.Fatalf("%+v", err)
|
||||||
|
|
||||||
plugin, err := newDevicePluginDFL(sysfs, devfs, tcase.mode)
|
|
||||||
if err != nil {
|
|
||||||
t.Errorf("Test case '%s': %+v", tcase.name, err)
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
plugin.getDevTree = func(devices []device) dpapi.DeviceTree {
|
|
||||||
return dpapi.NewDeviceTree()
|
|
||||||
}
|
|
||||||
|
|
||||||
_, err = plugin.scanFPGAs()
|
|
||||||
if tcase.errorContains != "" {
|
|
||||||
if err == nil || !strings.Contains(err.Error(), tcase.errorContains) {
|
|
||||||
t.Errorf("Test case '%s': expected error '%s', but got '%v'", tcase.name, tcase.errorContains, err)
|
|
||||||
}
|
}
|
||||||
} else if err != nil {
|
|
||||||
t.Errorf("Test case '%s': expected no error, but got '%+v'", tcase.name, err)
|
|
||||||
}
|
|
||||||
|
|
||||||
err = os.RemoveAll(tmpdir)
|
plugin, err := newDevicePluginDFL(sysfs, devfs, tcase.mode)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Errorf("error creating DFL plugin: %+v", err)
|
||||||
}
|
return
|
||||||
|
}
|
||||||
|
plugin.getDevTree = func(devices []device) dpapi.DeviceTree {
|
||||||
|
return dpapi.NewDeviceTree()
|
||||||
|
}
|
||||||
|
|
||||||
|
_, err = plugin.scanFPGAs()
|
||||||
|
if tcase.errorContains != "" {
|
||||||
|
if err == nil || !strings.Contains(err.Error(), tcase.errorContains) {
|
||||||
|
t.Errorf("expected error '%s', but got '%v'", tcase.errorContains, err)
|
||||||
|
}
|
||||||
|
} else if err != nil {
|
||||||
|
t.Errorf("expected no error, but got '%+v'", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
err = os.RemoveAll(tmpdir)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -15,13 +15,12 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
"path"
|
"path"
|
||||||
"reflect"
|
"reflect"
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
|
||||||
|
|
||||||
dpapi "github.com/intel/intel-device-plugins-for-kubernetes/pkg/deviceplugin"
|
dpapi "github.com/intel/intel-device-plugins-for-kubernetes/pkg/deviceplugin"
|
||||||
pluginapi "k8s.io/kubelet/pkg/apis/deviceplugin/v1beta1"
|
pluginapi "k8s.io/kubelet/pkg/apis/deviceplugin/v1beta1"
|
||||||
@ -48,10 +47,15 @@ func TestNewDevicePluginOPAE(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for _, tcase := range tcases {
|
for _, tcase := range tcases {
|
||||||
_, err := newDevicePluginOPAE("", "", tcase.mode)
|
t.Run(tcase.mode, func(t *testing.T) {
|
||||||
if tcase.expectedErr && err == nil {
|
_, err := newDevicePluginOPAE("", "", tcase.mode)
|
||||||
t.Error("No error generated when creating Cache with invalid parameters")
|
if tcase.expectedErr && err == nil {
|
||||||
}
|
t.Error("Unexpected success")
|
||||||
|
}
|
||||||
|
if !tcase.expectedErr && err != nil {
|
||||||
|
t.Errorf("Unexpected error: %+v", err)
|
||||||
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -233,7 +237,10 @@ func TestGetAfuTreeOPAE(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestScanFPGAsOPAE(t *testing.T) {
|
func TestScanFPGAsOPAE(t *testing.T) {
|
||||||
tmpdir := fmt.Sprintf("/tmp/fpgaplugin-TestDiscoverFPGAs-%d", time.Now().Unix())
|
tmpdir, err := ioutil.TempDir("", "TestScanFPGAsOPAE")
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("can't create temporary directory: %+v", err)
|
||||||
|
}
|
||||||
sysfs := path.Join(tmpdir, "sys", "class", "fpga")
|
sysfs := path.Join(tmpdir, "sys", "class", "fpga")
|
||||||
devfs := path.Join(tmpdir, "dev")
|
devfs := path.Join(tmpdir, "dev")
|
||||||
tcases := []struct {
|
tcases := []struct {
|
||||||
@ -353,33 +360,35 @@ func TestScanFPGAsOPAE(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for _, tcase := range tcases {
|
for _, tcase := range tcases {
|
||||||
err := createTestDirs(devfs, sysfs, tcase.devfsdirs, tcase.sysfsdirs, tcase.sysfsfiles)
|
t.Run(tcase.name, func(t *testing.T) {
|
||||||
if err != nil {
|
err := createTestDirs(devfs, sysfs, tcase.devfsdirs, tcase.sysfsdirs, tcase.sysfsfiles)
|
||||||
t.Fatalf("%+v", err)
|
if err != nil {
|
||||||
}
|
t.Fatalf("%+v", err)
|
||||||
|
|
||||||
plugin, err := newDevicePluginOPAE(sysfs, devfs, tcase.mode)
|
|
||||||
|
|
||||||
plugin.getDevTree = func(devices []device) dpapi.DeviceTree {
|
|
||||||
return dpapi.NewDeviceTree()
|
|
||||||
}
|
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("%+v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
_, err = plugin.scanFPGAs()
|
|
||||||
if tcase.errorContains != "" {
|
|
||||||
if err == nil || !strings.Contains(err.Error(), tcase.errorContains) {
|
|
||||||
t.Errorf("Test case '%s': expected error '%s', but got '%v'", tcase.name, tcase.errorContains, err)
|
|
||||||
}
|
}
|
||||||
} else if err != nil {
|
|
||||||
t.Errorf("Test case '%s': expected no error, but got '%+v'", tcase.name, err)
|
|
||||||
}
|
|
||||||
|
|
||||||
err = os.RemoveAll(tmpdir)
|
plugin, err := newDevicePluginOPAE(sysfs, devfs, tcase.mode)
|
||||||
if err != nil {
|
|
||||||
t.Fatal(err)
|
plugin.getDevTree = func(devices []device) dpapi.DeviceTree {
|
||||||
}
|
return dpapi.NewDeviceTree()
|
||||||
|
}
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("%+v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
_, err = plugin.scanFPGAs()
|
||||||
|
if tcase.errorContains != "" {
|
||||||
|
if err == nil || !strings.Contains(err.Error(), tcase.errorContains) {
|
||||||
|
t.Errorf("expected error '%s', but got '%v'", tcase.errorContains, err)
|
||||||
|
}
|
||||||
|
} else if err != nil {
|
||||||
|
t.Errorf("expected no error, but got '%+v'", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
err = os.RemoveAll(tmpdir)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user