-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgurl_test.go
More file actions
49 lines (42 loc) · 991 Bytes
/
gurl_test.go
File metadata and controls
49 lines (42 loc) · 991 Bytes
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
package gurl
import (
"fmt"
"net/http"
"net/http/httptest"
"os"
"path"
"strconv"
"testing"
)
var (
server = httptest.NewServer(&testHandler{})
local_url = fmt.Sprintf("%s/%s", server.URL, "foobar.tar.gz")
)
type testHandler struct {
}
func (t *testHandler) ServeHTTP(w http.ResponseWriter, req *http.Request) {
size := 1024 * 1024
b := make([]byte, size)
w.Header().Set("Accept-Ranges", "bytes")
w.Header().Set("Content-Length", strconv.Itoa(size))
w.Write(b)
}
func TestLocal(t *testing.T) {
defer os.Remove(path.Base(local_url))
if err := Download("./", local_url); err != nil {
t.Errorf("Download : %v", err)
}
}
func TestLocalAll(t *testing.T) {
urls := []string{local_url, local_url}
defer os.Remove(path.Base(local_url))
if err := DownloadAll("./", urls); err != nil {
t.Errorf("Download : %v", err)
}
}
func TestTimeOut(t *testing.T) {
err := Download("./", "https://127.0.0.1:7777")
if err == nil {
t.Errorf("Expected Client to timeout.")
}
}