Skip to content

Commit

Permalink
fixed VCS temp file remove
Browse files Browse the repository at this point in the history
  • Loading branch information
Jguer committed Aug 5, 2022
1 parent 2214d99 commit 4d5131d
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 16 deletions.
18 changes: 10 additions & 8 deletions pkg/vcs/vcs.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down Expand Up @@ -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)
Expand Down
21 changes: 13 additions & 8 deletions pkg/vcs/vcs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down Expand Up @@ -261,17 +262,17 @@ 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
t.Run(tt.name, func(t *testing.T) {
t.Parallel()
v := &InfoStore{
OriginsByPackage: tt.fields.OriginsByPackage,
FilePath: file.Name(),
FilePath: filePath,
CmdBuilder: tt.fields.CmdBuilder,
}
var mux sync.Mutex
Expand All @@ -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) {
Expand Down Expand Up @@ -325,20 +328,22 @@ 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
t.Run(tt.name, func(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))
}

0 comments on commit 4d5131d

Please sign in to comment.