mirror of
https://github.com/kata-containers/kata-containers.git
synced 2025-08-16 15:07:46 +00:00
unit-test: struct TestDataa should be included in arch-indenpedent .go file
argument struct TestDataa in generic func genericTestGetCPUDetails is repeatedly defined in almost all arch-dependent .go file, cli/kata-check_amd64_test.go, cli/kata-check_ppc64le_test.go, etcm, except arm64. let's only declare it once in cli/kata-check_test.go. change its name to testCPUDetail for better understanding. Fixes: #1200 Signed-off-by: Penny Zheng <penny.zheng@arm.com>
This commit is contained in:
parent
136b188fd4
commit
44e2b9aa0a
@ -484,13 +484,6 @@ func TestKvmIsUsable(t *testing.T) {
|
||||
assert.Error(err)
|
||||
}
|
||||
|
||||
type TestDataa struct {
|
||||
contents string
|
||||
expectedVendor string
|
||||
expectedModel string
|
||||
expectError bool
|
||||
}
|
||||
|
||||
func TestGetCPUDetails(t *testing.T) {
|
||||
const validVendorName = "a vendor"
|
||||
validVendor := fmt.Sprintf(`%s : %s`, archCPUVendorField, validVendorName)
|
||||
@ -505,7 +498,7 @@ foo : bar
|
||||
%s
|
||||
`, validVendor, validModel)
|
||||
|
||||
data := []TestDataa{
|
||||
data := []testCPUDetail{
|
||||
{"", "", "", true},
|
||||
{"invalid", "", "", true},
|
||||
{archCPUVendorField, "", "", true},
|
||||
|
@ -208,13 +208,6 @@ func TestKvmIsUsable(t *testing.T) {
|
||||
assert.Error(err)
|
||||
}
|
||||
|
||||
type TestDataa struct {
|
||||
contents string
|
||||
expectedVendor string
|
||||
expectedModel string
|
||||
expectError bool
|
||||
}
|
||||
|
||||
func TestGetCPUDetails(t *testing.T) {
|
||||
|
||||
const validVendorName = ""
|
||||
@ -230,7 +223,7 @@ foo : bar
|
||||
%s
|
||||
`, validVendor, validModel)
|
||||
|
||||
data := []TestDataa{
|
||||
data := []testCPUDetail{
|
||||
{"", "", "", true},
|
||||
{"invalid", "", "", true},
|
||||
{archCPUVendorField, "", "", true},
|
||||
|
@ -207,21 +207,7 @@ func TestKvmIsUsable(t *testing.T) {
|
||||
assert.Error(err)
|
||||
}
|
||||
|
||||
type TestDataa struct {
|
||||
contents string
|
||||
expectedVendor string
|
||||
expectedModel string
|
||||
expectError bool
|
||||
}
|
||||
|
||||
func TestGetCPUDetails(t *testing.T) {
|
||||
type testData struct {
|
||||
contents string
|
||||
expectedVendor string
|
||||
expectedModel string
|
||||
expectError bool
|
||||
}
|
||||
|
||||
const validVendorName = "a vendor"
|
||||
validVendor := fmt.Sprintf(`%s : %s`, archCPUVendorField, validVendorName)
|
||||
|
||||
@ -235,7 +221,7 @@ foo : bar
|
||||
%s
|
||||
`, validVendor, validModel)
|
||||
|
||||
data := []TestDataa{
|
||||
data := []testCPUDetail{
|
||||
{"", "", "", true},
|
||||
{"invalid", "", "", true},
|
||||
{archCPUVendorField, "", "", true},
|
||||
|
@ -33,6 +33,13 @@ type testCPUData struct {
|
||||
expectError bool
|
||||
}
|
||||
|
||||
type testCPUDetail struct {
|
||||
contents string
|
||||
expectedVendor string
|
||||
expectedModel string
|
||||
expectError bool
|
||||
}
|
||||
|
||||
func createFile(file, contents string) error {
|
||||
return ioutil.WriteFile(file, []byte(contents), testFileMode)
|
||||
}
|
||||
@ -138,7 +145,7 @@ func makeCPUInfoFile(path, vendorID, flags string) error {
|
||||
return ioutil.WriteFile(path, contents.Bytes(), testFileMode)
|
||||
}
|
||||
|
||||
func genericTestGetCPUDetails(t *testing.T, validVendor string, validModel string, validContents string, data []TestDataa) {
|
||||
func genericTestGetCPUDetails(t *testing.T, validVendor string, validModel string, validContents string, data []testCPUDetail) {
|
||||
tmpdir, err := ioutil.TempDir("", "")
|
||||
if err != nil {
|
||||
panic(err)
|
||||
|
Loading…
Reference in New Issue
Block a user