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

Commit

Permalink
unit-test: struct TestDataa should be included in arch-indenpedent .g…
Browse files Browse the repository at this point in the history
…o 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>
  • Loading branch information
Pennyzct authored and Eric Ernst committed Feb 26, 2019
1 parent efe96e8 commit e2a6373
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 32 deletions.
9 changes: 1 addition & 8 deletions cli/kata-check_amd64_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -505,7 +498,7 @@ foo : bar
%s
`, validVendor, validModel)

data := []TestDataa{
data := []testCPUDetail{
{"", "", "", true},
{"invalid", "", "", true},
{archCPUVendorField, "", "", true},
Expand Down
9 changes: 1 addition & 8 deletions cli/kata-check_ppc64le_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 = ""
Expand All @@ -230,7 +223,7 @@ foo : bar
%s
`, validVendor, validModel)

data := []TestDataa{
data := []testCPUDetail{
{"", "", "", true},
{"invalid", "", "", true},
{archCPUVendorField, "", "", true},
Expand Down
16 changes: 1 addition & 15 deletions cli/kata-check_s390x_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -235,7 +221,7 @@ foo : bar
%s
`, validVendor, validModel)

data := []TestDataa{
data := []testCPUDetail{
{"", "", "", true},
{"invalid", "", "", true},
{archCPUVendorField, "", "", true},
Expand Down
9 changes: 8 additions & 1 deletion cli/kata-check_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit e2a6373

Please sign in to comment.