Skip to content

Commit b62bbea

Browse files
committed
tests: Add tests for download
1 parent 4859b51 commit b62bbea

File tree

5 files changed

+59
-0
lines changed

5 files changed

+59
-0
lines changed

go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ go 1.15
44

55
require (
66
github.com/dustin/go-humanize v1.0.0
7+
github.com/gorilla/mux v1.8.0
78
github.com/mholt/archiver/v3 v3.5.0
89
github.com/spf13/cobra v1.1.1
910
)

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,8 @@ github.com/google/renameio v0.1.0/go.mod h1:KWCgfxg9yswjAJkECMjeO8J8rahYeXnNhOm4
7373
github.com/googleapis/gax-go/v2 v2.0.4/go.mod h1:0Wqv26UfaUD9n4G6kQubkQ+KchISgw+vpHVxEJEs9eg=
7474
github.com/googleapis/gax-go/v2 v2.0.5/go.mod h1:DWXyrwAJ9X0FpwwEdw+IPEYBICEFu5mhpdKc/us6bOk=
7575
github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY=
76+
github.com/gorilla/mux v1.8.0 h1:i40aqfkR1h2SlN9hojwV5ZA91wcXFOvkdNIeFDP5koI=
77+
github.com/gorilla/mux v1.8.0/go.mod h1:DVbg23sWSpFRCP0SfiEN6jmj59UnW/n46BH5rLB71So=
7678
github.com/gorilla/websocket v1.4.2/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
7779
github.com/grpc-ecosystem/go-grpc-middleware v1.0.0/go.mod h1:FiyG127CGDf3tlThmgyCl78X/SZQqEOJBCDaAfeWzPs=
7880
github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0/go.mod h1:8NvIoxWQoOIhqOTXgfV/d3M/q6VIi02HzZEHgUlZvzk=

nsd/download/download_test.go

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
package download
2+
3+
import (
4+
"net/http"
5+
"net/http/httptest"
6+
"os"
7+
"testing"
8+
9+
"github.com/gorilla/mux"
10+
)
11+
12+
func TestDownloadTgz(t *testing.T) {
13+
router := mux.NewRouter()
14+
router.PathPrefix("/").Handler(http.FileServer(http.Dir("./testdata/")))
15+
16+
server := httptest.NewServer(router)
17+
defer server.Close()
18+
19+
filePath, err := File(server.URL + "/basic.tar.gz")
20+
if filePath == "" {
21+
t.Errorf("File() returned no path")
22+
}
23+
defer os.Remove(filePath)
24+
25+
if err != nil {
26+
t.Errorf("File() did error %s", err)
27+
}
28+
29+
info, err := os.Stat(filePath)
30+
if os.IsNotExist(err) || info.IsDir() {
31+
t.Errorf("File() returned path to file, but file does not exist")
32+
}
33+
}
34+
35+
func TestDownloadZip(t *testing.T) {
36+
router := mux.NewRouter()
37+
router.PathPrefix("/").Handler(http.FileServer(http.Dir("./testdata/")))
38+
39+
server := httptest.NewServer(router)
40+
defer server.Close()
41+
42+
filePath, err := File(server.URL + "/basic.zip")
43+
if filePath == "" {
44+
t.Errorf("File() returned no path")
45+
}
46+
defer os.Remove(filePath)
47+
48+
if err != nil {
49+
t.Errorf("File() did error %s", err)
50+
}
51+
52+
info, err := os.Stat(filePath)
53+
if os.IsNotExist(err) || info.IsDir() {
54+
t.Errorf("File() returned path to file, but file does not exist")
55+
}
56+
}

nsd/download/testdata/basic.tar.gz

169 Bytes
Binary file not shown.

nsd/download/testdata/basic.zip

370 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)