From eb84946974f7e285b40cf31c68029a9bf79b6d84 Mon Sep 17 00:00:00 2001 From: saqib-perwaiz_navi Date: Thu, 14 Sep 2023 15:24:58 +0530 Subject: [PATCH] INFRA-2175 | Saqib | Fix lint errors --- main.go | 7 +++++-- main_test.go | 6 ++---- resource.go | 7 ++++++- util.go | 6 +++++- 4 files changed, 18 insertions(+), 8 deletions(-) diff --git a/main.go b/main.go index a284359..ce496ba 100644 --- a/main.go +++ b/main.go @@ -67,7 +67,7 @@ func parseManifest(manifestPath string, tfActions *Actions) (*Manifest, error) { } if manifest.ExtraResources.Workspace == "" { - var workspace = "" + var workspace string if manifest.Cluster != "" { workspace = manifest.Cluster log.Printf("Got workspace from manifest.cluster: %v", workspace) @@ -282,5 +282,8 @@ func main() { }, } - app.Run(os.Args) + err := app.Run(os.Args) + if err != nil { + log.Fatalf("\nErr: %v", err) + } } diff --git a/main_test.go b/main_test.go index 611eeb7..62e9910 100644 --- a/main_test.go +++ b/main_test.go @@ -26,8 +26,6 @@ const documentDbTfPath = "document-db-tf" var manifestFiles = [2]string{"sample_infra_manifest", "sample_infra_manifest_2"} -var testActions Actions - func textDiff(text1, text2 string) string { dmp := diffmatchpatch.New() diffs := dmp.DiffMain(text1, text2, false) @@ -72,7 +70,7 @@ func compareResourceWithOutput(resouceDir string, resource string, manifestFileN if err != nil { return err } - if bytes.Compare(expectedOutput, actualOutput) != 0 { + if !bytes.Equal(expectedOutput, actualOutput) { return fmt.Errorf("Mismatch for %s, diff: %s\n", path, textDiff(string(actualOutput), string(expectedOutput))) } return nil @@ -103,7 +101,7 @@ func TestBinData_CompareWithTemplates(t *testing.T) { t.Error(err) } - if bytes.Compare(actualTemplate, binDataTemplate) != 0 { + if !bytes.Equal(actualTemplate, binDataTemplate) { t.Errorf("Found outdated bindata for %s", path) } return nil diff --git a/resource.go b/resource.go index 22c1871..2009ee1 100644 --- a/resource.go +++ b/resource.go @@ -59,7 +59,12 @@ func provisionAllResource(manifest *Manifest) error { func checkResourceExists(resourceName string, manifest *Manifest) bool { var myMap map[string]interface{} data, _ := json.Marshal(manifest.ExtraResources) - json.Unmarshal(data, &myMap) + err := json.Unmarshal(data, &myMap) + + if err != nil { + log.Fatalf("\nErr: %v", err) + } + val, ok := myMap[resourceName] if ok && val != nil { return true diff --git a/util.go b/util.go index dfe203d..7ce0f24 100644 --- a/util.go +++ b/util.go @@ -21,7 +21,11 @@ func createFile(dir, fileName string) (*os.File, error) { return nil, err } - os.Chmod(filePath, os.ModePerm) + if err := os.Chmod(filePath, os.ModePerm); err != nil { + log.Fatalf("\nErr: %v", err) + return nil, err + } + return file, err }