package main import ( "bytes" "fmt" "io/ioutil" "net/http" "regexp" "strings" "testing" ) func dieMaybe(t *testing.T, err error) { if err != nil { t.Fatal(err) } } func trimSpaces(str string) string { space := regexp.MustCompile(`\s+`) return space.ReplaceAllString(str, " ") } func get(t *testing.T, url string) string { resp, err := http.Get(url) dieMaybe(t, err) body, err := ioutil.ReadAll(resp.Body) dieMaybe(t, err) return trimSpaces(string(body)) } func postDummyFile(t *testing.T, path string, payload string) string { // Generated by curl-to-Go: https://mholt.github.io/curl-to-go body := strings.NewReader("------WebKitFormBoundarycCRIderiXxJWEUcU\r\nContent-Disposition: form-data; name=\"\u1112\u1161 \u1112\u1161\"; filename=\"\u1112\u1161 \u1112\u1161\"\r\nContent-Type: application/octet-stream\r\n\r\n" + payload) req, err := http.NewRequest("POST", "http://127.0.0.1:8001/post", body) dieMaybe(t, err) req.Header.Set("Content-Type", "multipart/form-data; boundary=----WebKitFormBoundarycCRIderiXxJWEUcU") req.Header.Set("Gossa-Path", path) resp, err := http.DefaultClient.Do(req) dieMaybe(t, err) defer resp.Body.Close() bodyS, err := ioutil.ReadAll(resp.Body) dieMaybe(t, err) return trimSpaces(string(bodyS)) } func postJSON(t *testing.T, url string, what string) string { resp, err := http.Post(url, "application/json", bytes.NewBuffer([]byte(what))) dieMaybe(t, err) body, err := ioutil.ReadAll(resp.Body) dieMaybe(t, err) return trimSpaces(string(body)) } var mainPage = `
| compress/ | ||
| curimit@gmail.com (40%)/ | ||
| gzip/ | ||
| hols/ | ||
| show-dir$$href_encoding$$/ | ||
| subdir/ | ||
| subdir_with space/ | ||
| 中文/ | ||
13.0B | 404.html | ||
40.0B | 404.html.gz | ||
5.0B | b.txt | ||
211.0B | custom_mime_type.types |