From c7091f015c98da618265453b67e3a34323b52f1d Mon Sep 17 00:00:00 2001 From: Vishwanath Hiremath Date: Fri, 23 Feb 2024 12:24:02 -0800 Subject: [PATCH] fixing linter error Signed-off-by: Vishwanath Hiremath --- pkg/recipes/driver/gitconfig_test.go | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/pkg/recipes/driver/gitconfig_test.go b/pkg/recipes/driver/gitconfig_test.go index 657753ddb9..f7a11329a3 100644 --- a/pkg/recipes/driver/gitconfig_test.go +++ b/pkg/recipes/driver/gitconfig_test.go @@ -54,13 +54,14 @@ func TestAddConfig(t *testing.T) { for _, tt := range tests { t.Run(tt.desc, func(t *testing.T) { tmpdir := t.TempDir() - config := withGlobalGitConfigFile(tmpdir, ``) + config, err := withGlobalGitConfigFile(tmpdir, ``) + require.NoError(t, err) defer config() _, recipeMetadata, _ := buildTestInputs() if tt.desc == "invalid resource id" { recipeMetadata.EnvironmentID = "//planes/radius/local/resourceGroups/r1/providers/Applications.Core/environments/env" } - err := addSecretsToGitConfig(getSecretList(), &recipeMetadata, tt.templatePath) + err = addSecretsToGitConfig(getSecretList(), &recipeMetadata, tt.templatePath) if tt.expectedErr == nil { require.NoError(t, err) fileContent, err := os.ReadFile(filepath.Join(tmpdir, ".gitconfig")) @@ -109,9 +110,10 @@ func TestUnsetConfig(t *testing.T) { } for _, tt := range tests { tmpdir := t.TempDir() - config := withGlobalGitConfigFile(tmpdir, tt.fileContent) + config, err := withGlobalGitConfigFile(tmpdir, tt.fileContent) + require.NoError(t, err) defer config() - err := unsetSecretsFromGitConfig(getSecretList(), tt.templatePath) + err = unsetSecretsFromGitConfig(getSecretList(), tt.templatePath) if tt.expectedErr == nil { require.NoError(t, err) contents, err := os.ReadFile(filepath.Join(tmpdir, ".gitconfig")) @@ -124,23 +126,25 @@ func TestUnsetConfig(t *testing.T) { } } -func withGlobalGitConfigFile(tmpdir string, content string) func() { +func withGlobalGitConfigFile(tmpdir string, content string) (func(), error) { tmpGitConfigFile := filepath.Join(tmpdir, ".gitconfig") - err:=os.WriteFile( + err := os.WriteFile( tmpGitConfigFile, []byte(content), 0777, ) - require.NoError(t,err) + if err != nil { + return func() {}, err + } prevGitConfigEnv := os.Getenv("HOME") os.Setenv("HOME", tmpdir) return func() { os.Setenv("HOME", prevGitConfigEnv) - } + }, nil } func getSecretList() v20231001preview.SecretStoresClientListSecretsResponse {