Skip to content

Commit adda9a2

Browse files
committed
go-lint fixes
1 parent d2ce526 commit adda9a2

File tree

6 files changed

+30
-14
lines changed

6 files changed

+30
-14
lines changed

helpers/foundation-deployer/gcp/gcp_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ func TestIsComponentInstalledFound(t *gotest.T) {
3232
Runf: func(t testing.TB, cmd string, args ...interface{}) gjson.Result {
3333
return gjson.Result{
3434
Type: gjson.JSON,
35-
Raw: fmt.Sprintf("%s", string(betaComponents[:])),
35+
Raw: string(betaComponents[:]),
3636
}
3737
},
3838
sleepTime: 1,
@@ -49,7 +49,7 @@ func TestIsComponentInstalledNotFound(t *gotest.T) {
4949
Runf: func(t testing.TB, cmd string, args ...interface{}) gjson.Result {
5050
return gjson.Result{
5151
Type: gjson.JSON,
52-
Raw: fmt.Sprintf("%s", string(betaComponents[:])),
52+
Raw: string(betaComponents[:]),
5353
}
5454
},
5555
sleepTime: 1,

helpers/foundation-deployer/stages/data.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -320,11 +320,11 @@ func ReadGlobalTFVars(file string) (GlobalTFVars, error) {
320320
}
321321
_, err := os.Stat(file)
322322
if os.IsNotExist(err) {
323-
return globalTfvars, fmt.Errorf("tfvars file '%s' does not exits\n", file)
323+
return globalTfvars, fmt.Errorf("tfvars file '%s' does not exits", file)
324324
}
325325
err = utils.ReadTfvars(file, &globalTfvars)
326326
if err != nil {
327-
return globalTfvars, fmt.Errorf("Failed to load tfvars file %s. Error: %s\n", file, err.Error())
327+
return globalTfvars, fmt.Errorf("failed to load tfvars file %s. Error: %s", file, err.Error())
328328
}
329329
return globalTfvars, nil
330330
}

helpers/foundation-deployer/stages/validate.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,11 @@ const (
3333
func ValidateDirectories(g GlobalTFVars) error {
3434
_, err := os.Stat(g.FoundationCodePath)
3535
if os.IsNotExist(err) {
36-
return fmt.Errorf("Stopping execution, FoundationCodePath directory '%s' does not exits\n", g.FoundationCodePath)
36+
return fmt.Errorf("stopping execution, FoundationCodePath directory '%s' does not exits", g.FoundationCodePath)
3737
}
3838
_, err = os.Stat(g.CodeCheckoutPath)
3939
if os.IsNotExist(err) {
40-
return fmt.Errorf("Stopping execution, CodeCheckoutPath directory '%s' does not exits\n", g.CodeCheckoutPath)
40+
return fmt.Errorf("stopping execution, CodeCheckoutPath directory '%s' does not exits", g.CodeCheckoutPath)
4141
}
4242
return nil
4343
}
@@ -56,7 +56,7 @@ func ValidateComponents(t testing.TB) error {
5656
}
5757
}
5858
if len(missing) > 0 {
59-
return fmt.Errorf("Missing Google Cloud SDK component:%v", missing)
59+
return fmt.Errorf("missing Google Cloud SDK component:%v", missing)
6060
}
6161
return nil
6262
}

helpers/foundation-deployer/stages/vet.go

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,22 +51,35 @@ func TerraformVet(t testing.TB, terraformDir, policyPath, project string) error
5151
return err
5252
}
5353
jsonFile, err := utils.WriteTmpFileWithExtension(jsonPlan, "json")
54-
defer os.Remove(jsonFile)
55-
defer os.Remove(options.PlanFilePath)
54+
55+
defer func() {
56+
err := os.Remove(jsonFile)
57+
if err != nil {
58+
fmt.Fprintf(os.Stderr, "Error removing file: %s\n", err)
59+
}
60+
}()
61+
62+
defer func() {
63+
err := os.Remove(options.PlanFilePath)
64+
if err != nil {
65+
fmt.Fprintf(os.Stderr, "Error removing file: %s\n", err)
66+
}
67+
}()
68+
5669
if err != nil {
5770
return err
5871
}
5972
command := fmt.Sprintf("beta terraform vet %s --policy-library=%s --project=%s --quiet", jsonFile, policyPath, project)
6073
result, err := gcloud.RunCmdE(t, command)
61-
if err != nil && !(strings.Contains(err.Error(), "Validating resources") && strings.Contains(err.Error(), "done")) {
74+
if err != nil && (!strings.Contains(err.Error(), "Validating resources") || !strings.Contains(err.Error(), "done")) {
6275
return err
6376
}
6477
if !gjson.Valid(result) {
65-
return fmt.Errorf("Error parsing output, invalid json: %s", result)
78+
return fmt.Errorf("error parsing output, invalid json: %s", result)
6679
}
6780

6881
if len(gjson.Parse(result).Array()) > 0 {
69-
return fmt.Errorf("Policy violations found: %s", result)
82+
return fmt.Errorf("policy violations found: %s", result)
7083
}
7184
fmt.Println("")
7285
fmt.Println("# The configuration passed tf vet.")

helpers/foundation-deployer/utils/files.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ func ReplaceStringInFile(filename, old, new string) error {
7474
if err != nil {
7575
return err
7676
}
77-
return os.WriteFile(filename, bytes.Replace(f, []byte(old), []byte(new), -1), 0644)
77+
return os.WriteFile(filename, bytes.ReplaceAll(f, []byte(old), []byte(new)), 0644)
7878
}
7979

8080
// FindFiles find files with the given filename under the directory skipping terraform temp dir.

helpers/foundation-deployer/utils/logger.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,10 @@ func NewCustomLogger() CustomLogger {
3232
}
3333
}
3434
func (c CustomLogger) Logf(t grunttest.TestingT, format string, args ...interface{}) {
35-
fmt.Fprintln(os.Stdout, fmt.Sprintf(c.baseFmt, fmt.Sprintf(format, args...)))
35+
_, err := fmt.Fprintln(os.Stdout, fmt.Sprintf(c.baseFmt, fmt.Sprintf(format, args...)))
36+
if err != nil {
37+
fmt.Fprintf(os.Stderr, "Error writing log: %s\n", err)
38+
}
3639
}
3740

3841
func GetLogger(quiet bool) *logger.Logger {

0 commit comments

Comments
 (0)