2015-02-09 18:37:06 +00:00
|
|
|
package tusd
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net/http"
|
|
|
|
"os"
|
2015-11-06 00:59:24 +00:00
|
|
|
"strconv"
|
2015-02-09 18:37:06 +00:00
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
|
|
|
type headStore struct {
|
|
|
|
zeroStore
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s headStore) GetInfo(id string) (FileInfo, error) {
|
|
|
|
if id != "yes" {
|
|
|
|
return FileInfo{}, os.ErrNotExist
|
|
|
|
}
|
|
|
|
|
|
|
|
return FileInfo{
|
|
|
|
Offset: 11,
|
|
|
|
Size: 44,
|
2015-03-08 00:06:39 +00:00
|
|
|
MetaData: map[string]string{
|
|
|
|
"name": "lunrjs.png",
|
|
|
|
"type": "image/png",
|
|
|
|
},
|
2015-02-09 18:37:06 +00:00
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestHead(t *testing.T) {
|
|
|
|
handler, _ := NewHandler(Config{
|
|
|
|
BasePath: "https://buy.art/",
|
|
|
|
DataStore: headStore{},
|
|
|
|
})
|
|
|
|
|
2015-02-17 14:44:12 +00:00
|
|
|
(&httpTest{
|
|
|
|
Name: "Successful request",
|
|
|
|
Method: "HEAD",
|
|
|
|
URL: "yes",
|
|
|
|
ReqHeader: map[string]string{
|
2015-03-23 17:15:05 +00:00
|
|
|
"Tus-Resumable": "1.0.0",
|
2015-02-17 14:44:12 +00:00
|
|
|
},
|
|
|
|
Code: http.StatusNoContent,
|
|
|
|
ResHeader: map[string]string{
|
2015-03-23 17:15:05 +00:00
|
|
|
"Upload-Offset": "11",
|
|
|
|
"Upload-Length": "44",
|
|
|
|
"Upload-Metadata": "name bHVucmpzLnBuZw==,type aW1hZ2UvcG5n",
|
2015-05-26 14:17:35 +00:00
|
|
|
"Cache-Control": "no-store",
|
2015-02-17 14:44:12 +00:00
|
|
|
},
|
|
|
|
}).Run(handler, t)
|
2015-11-06 00:59:24 +00:00
|
|
|
}
|
2015-02-17 14:44:12 +00:00
|
|
|
|
2015-11-06 00:59:24 +00:00
|
|
|
func TestHead404(t *testing.T) {
|
|
|
|
handler, _ := NewHandler(Config{
|
|
|
|
BasePath: "https://buy.art/",
|
|
|
|
DataStore: headStore{},
|
|
|
|
})
|
|
|
|
|
|
|
|
resp := (&httpTest{
|
2015-02-17 14:44:12 +00:00
|
|
|
Name: "Non-existing file",
|
|
|
|
Method: "HEAD",
|
|
|
|
URL: "no",
|
|
|
|
ReqHeader: map[string]string{
|
2015-03-23 17:15:05 +00:00
|
|
|
"Tus-Resumable": "1.0.0",
|
2015-02-17 14:44:12 +00:00
|
|
|
},
|
2015-11-06 00:59:24 +00:00
|
|
|
Code: http.StatusNotFound,
|
|
|
|
ResBody: "",
|
2015-02-17 14:44:12 +00:00
|
|
|
}).Run(handler, t)
|
2015-11-06 00:59:24 +00:00
|
|
|
|
|
|
|
body := string(resp.Body.Bytes())
|
|
|
|
if body != "" {
|
|
|
|
t.Errorf("Expected body to be empty. Got: %v", body)
|
|
|
|
}
|
|
|
|
|
|
|
|
contentLength := resp.Header().Get("Content-Length")
|
|
|
|
if contentLength != strconv.Itoa(len(body)) {
|
|
|
|
t.Errorf("Expected content length header to match body length. Got: %v", contentLength)
|
|
|
|
}
|
2015-02-09 18:37:06 +00:00
|
|
|
}
|