From fb14171cba46f331fd9b25efed36c25b6b7ebcea Mon Sep 17 00:00:00 2001 From: Paul Holzinger Date: Wed, 27 Apr 2022 14:28:38 +0200 Subject: enable errcheck linter The errcheck linter makes sure that errors are always check and not ignored by accident. It spotted a lot of unchecked errors, mostly in the tests but also some real problem in the code. Signed-off-by: Paul Holzinger --- test/utils/common_function_test.go | 6 ++++-- test/utils/utils.go | 4 +++- 2 files changed, 7 insertions(+), 3 deletions(-) (limited to 'test/utils') diff --git a/test/utils/common_function_test.go b/test/utils/common_function_test.go index a73d75490..7092e40a1 100644 --- a/test/utils/common_function_test.go +++ b/test/utils/common_function_test.go @@ -113,8 +113,10 @@ var _ = Describe("Common functions test", func() { Expect(err).To(BeNil(), "Can not find the JSON file after we write it.") defer read.Close() - bytes, _ := ioutil.ReadAll(read) - json.Unmarshal(bytes, compareData) + bytes, err := ioutil.ReadAll(read) + Expect(err).ToNot(HaveOccurred()) + err = json.Unmarshal(bytes, compareData) + Expect(err).ToNot(HaveOccurred()) Expect(reflect.DeepEqual(testData, compareData)).To(BeTrue(), "Data changed after we store it to file.") }) diff --git a/test/utils/utils.go b/test/utils/utils.go index f3e14c784..36f5a9414 100644 --- a/test/utils/utils.go +++ b/test/utils/utils.go @@ -489,7 +489,9 @@ func IsCommandAvailable(command string) bool { // WriteJSONFile write json format data to a json file func WriteJSONFile(data []byte, filePath string) error { var jsonData map[string]interface{} - json.Unmarshal(data, &jsonData) + if err := json.Unmarshal(data, &jsonData); err != nil { + return err + } formatJSON, err := json.MarshalIndent(jsonData, "", " ") if err != nil { return err -- cgit v1.2.3-54-g00ecf