Skip to content

Commit 54697ce

Browse files
authored
Merge pull request #2114 from alexandear/downloader-use-httptest-server
pkg/downloader: serve test contents with local HTTP server
2 parents f3dc6ed + a0d5c60 commit 54697ce

File tree

2 files changed

+8
-9
lines changed

2 files changed

+8
-9
lines changed

pkg/downloader/downloader_test.go

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package downloader
22

33
import (
4+
"net/http"
5+
"net/http/httptest"
46
"os"
57
"os/exec"
68
"path/filepath"
@@ -12,21 +14,17 @@ import (
1214
"gotest.tools/v3/assert"
1315
)
1416

15-
// TODO: create a localhost HTTP server to serve the test contents without Internet
16-
const (
17-
dummyRemoteFileURL = "https://raw.githubusercontent.com/lima-vm/lima/7459f4587987ed014c372f17b82de1817feffa2e/README.md"
18-
dummyRemoteFileDigest = "sha256:58d2de96f9d91f0acd93cb1e28bf7c42fc86079037768d6aa63b4e7e7b3c9be0"
19-
)
20-
2117
func TestMain(m *testing.M) {
2218
HideProgress = true
2319
os.Exit(m.Run())
2420
}
2521

2622
func TestDownloadRemote(t *testing.T) {
27-
if testing.Short() {
28-
t.Skip()
29-
}
23+
ts := httptest.NewServer(http.FileServer(http.Dir("testdata")))
24+
t.Cleanup(ts.Close)
25+
dummyRemoteFileURL := ts.URL + "/downloader.txt"
26+
const dummyRemoteFileDigest = "sha256:380481d26f897403368be7cb86ca03a4bc14b125bfaf2b93bff809a5a2ad717e"
27+
3028
t.Run("without cache", func(t *testing.T) {
3129
t.Run("without digest", func(t *testing.T) {
3230
localPath := filepath.Join(t.TempDir(), t.Name())
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
This file is used for testing Download function.

0 commit comments

Comments
 (0)