Skip to content

Commit

Permalink
fixing linter error
Browse files Browse the repository at this point in the history
Signed-off-by: Vishwanath Hiremath <[email protected]>
  • Loading branch information
vishwahiremat committed Feb 23, 2024
1 parent 8c178ca commit c7091f0
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions pkg/recipes/driver/gitconfig_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
Expand Down Expand Up @@ -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"))
Expand All @@ -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 {
Expand Down

0 comments on commit c7091f0

Please sign in to comment.