Skip to content

Commit 474eec4

Browse files
authored
Merge pull request #2869 from alexandear/refactor/downloader-test
downloader: simplify tests
2 parents be3c98b + b1d0619 commit 474eec4

File tree

2 files changed

+9
-14
lines changed

2 files changed

+9
-14
lines changed

.golangci.yml

+5
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,11 @@ linters-settings:
144144
- name: unused-parameter
145145
- name: var-declaration
146146
- name: var-naming
147+
staticcheck:
148+
# https://staticcheck.dev/docs/configuration/options/#checks
149+
checks:
150+
- "all"
151+
- "-SA3000" # false positive for Go 1.15+. See https://github.com/golang/go/issues/34129
147152
issues:
148153
# Maximum issues count per one linter.
149154
max-issues-per-linter: 0

pkg/downloader/downloader_test.go

+4-14
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import (
1919

2020
func TestMain(m *testing.M) {
2121
HideProgress = true
22-
os.Exit(m.Run())
22+
m.Run()
2323
}
2424

2525
type downloadResult struct {
@@ -189,21 +189,13 @@ func TestDownloadRemote(t *testing.T) {
189189
}
190190

191191
func TestRedownloadRemote(t *testing.T) {
192-
remoteDir, err := os.MkdirTemp("", "redownloadRemote")
193-
assert.NilError(t, err)
194-
t.Cleanup(func() { _ = os.RemoveAll(remoteDir) })
192+
remoteDir := t.TempDir()
195193
ts := httptest.NewServer(http.FileServer(http.Dir(remoteDir)))
196194
t.Cleanup(ts.Close)
197195

198-
cacheDir, err := os.MkdirTemp("", "redownloadCache")
199-
assert.NilError(t, err)
200-
t.Cleanup(func() { _ = os.RemoveAll(cacheDir) })
196+
downloadDir := t.TempDir()
201197

202-
downloadDir, err := os.MkdirTemp("", "redownloadLocal")
203-
assert.NilError(t, err)
204-
t.Cleanup(func() { _ = os.RemoveAll(downloadDir) })
205-
206-
cacheOpt := WithCacheDir(cacheDir)
198+
cacheOpt := WithCacheDir(t.TempDir())
207199

208200
t.Run("digest-less", func(t *testing.T) {
209201
remoteFile := filepath.Join(remoteDir, "digest-less.txt")
@@ -283,8 +275,6 @@ func TestDownloadLocal(t *testing.T) {
283275
r, err := Download(context.Background(), localPath, testLocalFileURL, WithExpectedDigest(testDownloadLocalDigest))
284276
assert.NilError(t, err)
285277
assert.Equal(t, StatusDownloaded, r.Status)
286-
287-
os.Remove(localTestFile)
288278
})
289279

290280
t.Run("cached", func(t *testing.T) {

0 commit comments

Comments
 (0)