Skip to content

Commit 84bbfb0

Browse files
authored
Merge pull request #1944 from alexandear/fix-download-local-on-windows
pkg/downloader,pkg/network: fix tests on Windows
2 parents 01869a4 + 0c51390 commit 84bbfb0

File tree

2 files changed

+8
-16
lines changed

2 files changed

+8
-16
lines changed

pkg/downloader/downloader_test.go

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -109,19 +109,15 @@ func TestDownloadRemote(t *testing.T) {
109109
}
110110

111111
func TestDownloadLocal(t *testing.T) {
112-
113-
if runtime.GOOS == "windows" {
114-
// FIXME: `TempDir RemoveAll cleanup: remove C:\users\runner\Temp\TestDownloadLocalwithout_digest2738386858\002\test-file: Sharing violation.`
115-
t.Skip("Skipping on windows")
116-
}
117-
118112
const emptyFileDigest = "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"
119113
const testDownloadLocalDigest = "sha256:0c1e0fba69e8919b306d030bf491e3e0c46cf0a8140ff5d7516ba3a83cbea5b3"
120114

121115
t.Run("without digest", func(t *testing.T) {
122116
localPath := filepath.Join(t.TempDir(), t.Name())
123117
localFile := filepath.Join(t.TempDir(), "test-file")
124-
os.Create(localFile)
118+
f, err := os.Create(localFile)
119+
assert.NilError(t, err)
120+
t.Cleanup(func() { _ = f.Close() })
125121
testLocalFileURL := "file://" + localFile
126122

127123
r, err := Download(localPath, testLocalFileURL)
@@ -150,11 +146,13 @@ func TestDownloadLocal(t *testing.T) {
150146

151147
t.Run("cached", func(t *testing.T) {
152148
localFile := filepath.Join(t.TempDir(), "test-file")
153-
os.Create(localFile)
149+
f, err := os.Create(localFile)
150+
assert.NilError(t, err)
151+
t.Cleanup(func() { _ = f.Close() })
154152
testLocalFileURL := "file://" + localFile
155153

156154
cacheDir := filepath.Join(t.TempDir(), "cache")
157-
_, err := Cached(testLocalFileURL, WithCacheDir(cacheDir))
155+
_, err = Cached(testLocalFileURL, WithCacheDir(cacheDir))
158156
assert.ErrorContains(t, err, "not cached")
159157
})
160158
}

pkg/networks/usernet/gvproxy_test.go

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,12 @@ import (
44
"bufio"
55
"os"
66
"path"
7-
"runtime"
87
"testing"
98

109
"gotest.tools/v3/assert"
1110
)
1211

1312
func TestSearchDomain(t *testing.T) {
14-
15-
if runtime.GOOS == "windows" {
16-
// FIXME: `TempDir RemoveAll cleanup: remove C:\users\runner\Temp\TestDownloadLocalwithout_digest2738386858\002\test-file: Sharing violation.`
17-
t.Skip("Skipping on windows")
18-
}
19-
2013
t.Run("search domain", func(t *testing.T) {
2114
resolvFile := path.Join(t.TempDir(), "resolv.conf")
2215
createResolveFile(t, resolvFile, `
@@ -45,6 +38,7 @@ func createResolveFile(t *testing.T, file string, content string) {
4538
if err != nil {
4639
t.Fatal(err)
4740
}
41+
t.Cleanup(func() { _ = f.Close() })
4842
writer := bufio.NewWriter(f)
4943
_, err = writer.Write([]byte(content))
5044
if err != nil {

0 commit comments

Comments
 (0)