mirror of
https://github.com/kata-containers/kata-containers.git
synced 2025-08-17 07:27:22 +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)
|
assert.Error(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
type TestDataa struct {
|
|
||||||
contents string
|
|
||||||
expectedVendor string
|
|
||||||
expectedModel string
|
|
||||||
expectError bool
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestGetCPUDetails(t *testing.T) {
|
func TestGetCPUDetails(t *testing.T) {
|
||||||
const validVendorName = "a vendor"
|
const validVendorName = "a vendor"
|
||||||
validVendor := fmt.Sprintf(`%s : %s`, archCPUVendorField, validVendorName)
|
validVendor := fmt.Sprintf(`%s : %s`, archCPUVendorField, validVendorName)
|
||||||
@ -505,7 +498,7 @@ foo : bar
|
|||||||
%s
|
%s
|
||||||
`, validVendor, validModel)
|
`, validVendor, validModel)
|
||||||
|
|
||||||
data := []TestDataa{
|
data := []testCPUDetail{
|
||||||
{"", "", "", true},
|
{"", "", "", true},
|
||||||
{"invalid", "", "", true},
|
{"invalid", "", "", true},
|
||||||
{archCPUVendorField, "", "", true},
|
{archCPUVendorField, "", "", true},
|
||||||
|
@ -208,13 +208,6 @@ func TestKvmIsUsable(t *testing.T) {
|
|||||||
assert.Error(err)
|
assert.Error(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
type TestDataa struct {
|
|
||||||
contents string
|
|
||||||
expectedVendor string
|
|
||||||
expectedModel string
|
|
||||||
expectError bool
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestGetCPUDetails(t *testing.T) {
|
func TestGetCPUDetails(t *testing.T) {
|
||||||
|
|
||||||
const validVendorName = ""
|
const validVendorName = ""
|
||||||
@ -230,7 +223,7 @@ foo : bar
|
|||||||
%s
|
%s
|
||||||
`, validVendor, validModel)
|
`, validVendor, validModel)
|
||||||
|
|
||||||
data := []TestDataa{
|
data := []testCPUDetail{
|
||||||
{"", "", "", true},
|
{"", "", "", true},
|
||||||
{"invalid", "", "", true},
|
{"invalid", "", "", true},
|
||||||
{archCPUVendorField, "", "", true},
|
{archCPUVendorField, "", "", true},
|
||||||
|
@ -207,21 +207,7 @@ func TestKvmIsUsable(t *testing.T) {
|
|||||||
assert.Error(err)
|
assert.Error(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
type TestDataa struct {
|
|
||||||
contents string
|
|
||||||
expectedVendor string
|
|
||||||
expectedModel string
|
|
||||||
expectError bool
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestGetCPUDetails(t *testing.T) {
|
func TestGetCPUDetails(t *testing.T) {
|
||||||
type testData struct {
|
|
||||||
contents string
|
|
||||||
expectedVendor string
|
|
||||||
expectedModel string
|
|
||||||
expectError bool
|
|
||||||
}
|
|
||||||
|
|
||||||
const validVendorName = "a vendor"
|
const validVendorName = "a vendor"
|
||||||
validVendor := fmt.Sprintf(`%s : %s`, archCPUVendorField, validVendorName)
|
validVendor := fmt.Sprintf(`%s : %s`, archCPUVendorField, validVendorName)
|
||||||
|
|
||||||
@ -235,7 +221,7 @@ foo : bar
|
|||||||
%s
|
%s
|
||||||
`, validVendor, validModel)
|
`, validVendor, validModel)
|
||||||
|
|
||||||
data := []TestDataa{
|
data := []testCPUDetail{
|
||||||
{"", "", "", true},
|
{"", "", "", true},
|
||||||
{"invalid", "", "", true},
|
{"invalid", "", "", true},
|
||||||
{archCPUVendorField, "", "", true},
|
{archCPUVendorField, "", "", true},
|
||||||
|
@ -33,6 +33,13 @@ type testCPUData struct {
|
|||||||
expectError bool
|
expectError bool
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type testCPUDetail struct {
|
||||||
|
contents string
|
||||||
|
expectedVendor string
|
||||||
|
expectedModel string
|
||||||
|
expectError bool
|
||||||
|
}
|
||||||
|
|
||||||
func createFile(file, contents string) error {
|
func createFile(file, contents string) error {
|
||||||
return ioutil.WriteFile(file, []byte(contents), testFileMode)
|
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)
|
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("", "")
|
tmpdir, err := ioutil.TempDir("", "")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
|
Loading…
Reference in New Issue
Block a user