forked from msf/go-minipypi
-
Notifications
You must be signed in to change notification settings - Fork 0
/
frontend_test.go
56 lines (47 loc) · 1.13 KB
/
frontend_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
51
52
53
54
55
56
package main
import (
"io/ioutil"
"net/http"
"net/http/httptest"
"testing"
)
var (
server *httptest.Server
testFetcher FileFetcher
)
func init() {
cfgs := WebServerConfigs{
fetcher: NewTestFetcher("psycopg2-2.5.3-cp27-none-linux_x86_64.whl"),
}
server = httptest.NewServer(http.HandlerFunc(cfgs.handleRequest))
}
func TestDirList(t *testing.T) {
resp, err := http.Get(server.URL + "/psycopg2/")
if err != nil {
t.Fatal("failed to handle DirList, error:", err)
}
if resp.StatusCode != 200 {
t.Fatal("bad statuscode", resp)
}
defer resp.Body.Close()
buf, err := ioutil.ReadAll(resp.Body)
if err != nil {
t.Fatal("failed to handle DirList, error:", err)
}
t.Logf("body: %v", string(buf))
}
func TestFetchFile(t *testing.T) {
resp, err := http.Get(server.URL + "/psycopg2/psycopg2-2.5.3-cp27-none-linux_x86_64.whl")
if err != nil {
t.Fatal("failed to handle FetchFile, error:", err)
}
if resp.StatusCode != 200 {
t.Fatal("bad statuscode", resp)
}
defer resp.Body.Close()
buf, err := ioutil.ReadAll(resp.Body)
if err != nil {
t.Fatal("failed to handle DirList, error:", err)
}
t.Logf("body: %v", string(buf))
}