From d88d45c6aa80b299ed85382c7b0b4d57aef71810 Mon Sep 17 00:00:00 2001 From: Penny Zheng Date: Thu, 31 Jan 2019 11:17:31 +0800 Subject: [PATCH] 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 --- cli/kata-check_amd64_test.go | 9 +-------- cli/kata-check_ppc64le_test.go | 9 +-------- cli/kata-check_s390x_test.go | 16 +--------------- cli/kata-check_test.go | 9 ++++++++- 4 files changed, 11 insertions(+), 32 deletions(-) diff --git a/cli/kata-check_amd64_test.go b/cli/kata-check_amd64_test.go index 69e49083ab..8cb06167fb 100644 --- a/cli/kata-check_amd64_test.go +++ b/cli/kata-check_amd64_test.go @@ -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}, diff --git a/cli/kata-check_ppc64le_test.go b/cli/kata-check_ppc64le_test.go index 6c1bd12996..e0267d768f 100644 --- a/cli/kata-check_ppc64le_test.go +++ b/cli/kata-check_ppc64le_test.go @@ -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}, diff --git a/cli/kata-check_s390x_test.go b/cli/kata-check_s390x_test.go index 47b1b72291..d04b44a650 100644 --- a/cli/kata-check_s390x_test.go +++ b/cli/kata-check_s390x_test.go @@ -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}, diff --git a/cli/kata-check_test.go b/cli/kata-check_test.go index 441fb28f66..7c2cde4d59 100644 --- a/cli/kata-check_test.go +++ b/cli/kata-check_test.go @@ -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)