From 4d5131d6c70785ce8248505a26ddffefab244fa3 Mon Sep 17 00:00:00 2001 From: jguer Date: Fri, 5 Aug 2022 18:56:28 +0200 Subject: [PATCH] fixed VCS temp file remove --- pkg/vcs/vcs.go | 18 ++++++++++-------- pkg/vcs/vcs_test.go | 21 +++++++++++++-------- 2 files changed, 23 insertions(+), 16 deletions(-) diff --git a/pkg/vcs/vcs.go b/pkg/vcs/vcs.go index 19b946c5..f8851ee0 100644 --- a/pkg/vcs/vcs.go +++ b/pkg/vcs/vcs.go @@ -30,13 +30,14 @@ type OriginInfoByURL map[string]OriginInfo // OriginInfo contains the last commit sha of a repo // Example: -// "github.com/Jguer/yay.git": { -// "protocols": [ -// "https" -// ], -// "branch": "next", -// "sha": "c1171d41467c68ffd3c46748182a16366aaaf87b" -// }. +// +// "github.com/Jguer/yay.git": { +// "protocols": [ +// "https" +// ], +// "branch": "next", +// "sha": "c1171d41467c68ffd3c46748182a16366aaaf87b" +// }. type OriginInfo struct { Protocols []string `json:"protocols"` Branch string `json:"branch"` @@ -90,7 +91,8 @@ func (v *InfoStore) getCommit(ctx context.Context, url, branch string, protocols } func (v *InfoStore) Update(ctx context.Context, pkgName string, - sources []gosrc.ArchString, mux sync.Locker, wg *sync.WaitGroup) { + sources []gosrc.ArchString, mux sync.Locker, wg *sync.WaitGroup, +) { defer wg.Done() info := make(OriginInfoByURL) diff --git a/pkg/vcs/vcs_test.go b/pkg/vcs/vcs_test.go index ed943f9b..2f27f75a 100644 --- a/pkg/vcs/vcs_test.go +++ b/pkg/vcs/vcs_test.go @@ -13,6 +13,7 @@ import ( gosrc "github.com/Morganamilo/go-srcinfo" "github.com/bradleyjkemp/cupaloy" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/Jguer/yay/v11/pkg/settings/exe" ) @@ -261,9 +262,9 @@ func TestInfoStore_Update(t *testing.T) { }, } - file, err := os.CreateTemp("/tmp", "yay-vcs-test") - assert.NoError(t, err) - defer os.Remove(file.Name()) + file, err := os.CreateTemp("/tmp", "yay-infostore-*-test") + filePath := file.Name() + require.NoError(t, err) for _, tt := range tests { tt := tt @@ -271,7 +272,7 @@ func TestInfoStore_Update(t *testing.T) { t.Parallel() v := &InfoStore{ OriginsByPackage: tt.fields.OriginsByPackage, - FilePath: file.Name(), + FilePath: filePath, CmdBuilder: tt.fields.CmdBuilder, } var mux sync.Mutex @@ -296,6 +297,8 @@ func TestInfoStore_Update(t *testing.T) { cupaloy.SnapshotT(t, marshalledinfo) }) } + + require.NoError(t, os.Remove(filePath)) } func TestInfoStore_Remove(t *testing.T) { @@ -325,9 +328,9 @@ func TestInfoStore_Remove(t *testing.T) { }, } - file, err := os.CreateTemp("/tmp", "yay-vcs-test") - assert.NoError(t, err) - defer os.Remove(file.Name()) + file, err := os.CreateTemp("/tmp", "yay-vcs-*-test") + filePath := file.Name() + require.NoError(t, err) for _, tt := range tests { tt := tt @@ -335,10 +338,12 @@ func TestInfoStore_Remove(t *testing.T) { t.Parallel() v := &InfoStore{ OriginsByPackage: tt.fields.OriginsByPackage, - FilePath: file.Name(), + FilePath: filePath, } v.RemovePackage(tt.args.pkgs) assert.Len(t, tt.fields.OriginsByPackage, 2) }) } + + require.NoError(t, os.Remove(filePath)) }