-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathzserv_test.go
50 lines (46 loc) · 1.32 KB
/
zserv_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package main
import (
"fmt"
"io"
"net/http"
"net/url"
"strings"
"testing"
"github.com/stretchr/testify/assert"
)
func downloadFile(port int, path string) []byte {
link := url.URL{
Scheme: "http",
Host: fmt.Sprintf("localhost:%d", port),
Path: path,
}
response, err := http.Get(link.String())
checkError(err, "cannot get file from HTTP")
bytes, err := io.ReadAll(response.Body)
checkError(err, "cannot copy file from HTTP")
return bytes
}
func TestBasicDownload(t *testing.T) {
port := 9688
repeated100 := strings.Repeat("<p>ABCDEFGHIJKLMNOPQRSTUVWXYZ</p>", 100)
repeated10000 := strings.Repeat("<p>ABCDEFGHIJKLMNOPQRSTUVWXYZ</p>", 10000)
entries := []entry{
{"small.html", fmt.Sprintf("<html><body>%s</body></html>\n", repeated100)},
{"big.html", fmt.Sprintf("<html><body>%s</body></html>\n", repeated10000)},
{"nest/ed.html", "<html><body>Hello</body></html>"},
{"nest/ed/nest/ed.html", "alwiehgweioghlafknewi;foghiEGNLAERI"},
}
for index, fs := range createBothTestZipReaderFS(entries) {
t.Run(fs.Name(), func(t *testing.T) {
go StartServer(&Options{
Port: port + index, Host: "127.0.0.1",
Root: ".",
}, fs)
for _, entry := range entries {
bytes := downloadFile(port+index, entry.Name)
assert.Equal(t, entry.Body, string(bytes), "Download %s",
entry.Name)
}
})
}
}