Add test for content length on 404
This commit is contained in:
parent
7c7c49f786
commit
dc5c38354f
|
@ -44,7 +44,7 @@ type httpTest struct {
|
||||||
ResHeader map[string]string
|
ResHeader map[string]string
|
||||||
}
|
}
|
||||||
|
|
||||||
func (test *httpTest) Run(handler http.Handler, t *testing.T) {
|
func (test *httpTest) Run(handler http.Handler, t *testing.T) *httptest.ResponseRecorder {
|
||||||
t.Log(test.Name)
|
t.Log(test.Name)
|
||||||
|
|
||||||
req, _ := http.NewRequest(test.Method, test.URL, test.ReqBody)
|
req, _ := http.NewRequest(test.Method, test.URL, test.ReqBody)
|
||||||
|
@ -77,6 +77,8 @@ func (test *httpTest) Run(handler http.Handler, t *testing.T) {
|
||||||
if test.ResBody != "" && string(w.Body.Bytes()) != test.ResBody {
|
if test.ResBody != "" && string(w.Body.Bytes()) != test.ResBody {
|
||||||
t.Errorf("Expected '%s' as body (got '%s'", test.ResBody, string(w.Body.Bytes()))
|
t.Errorf("Expected '%s' as body (got '%s'", test.ResBody, string(w.Body.Bytes()))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return w
|
||||||
}
|
}
|
||||||
|
|
||||||
type methodOverrideStore struct {
|
type methodOverrideStore struct {
|
||||||
|
|
21
head_test.go
21
head_test.go
|
@ -3,6 +3,7 @@ package tusd
|
||||||
import (
|
import (
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
|
"strconv"
|
||||||
"testing"
|
"testing"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -46,8 +47,15 @@ func TestHead(t *testing.T) {
|
||||||
"Cache-Control": "no-store",
|
"Cache-Control": "no-store",
|
||||||
},
|
},
|
||||||
}).Run(handler, t)
|
}).Run(handler, t)
|
||||||
|
}
|
||||||
|
|
||||||
(&httpTest{
|
func TestHead404(t *testing.T) {
|
||||||
|
handler, _ := NewHandler(Config{
|
||||||
|
BasePath: "https://buy.art/",
|
||||||
|
DataStore: headStore{},
|
||||||
|
})
|
||||||
|
|
||||||
|
resp := (&httpTest{
|
||||||
Name: "Non-existing file",
|
Name: "Non-existing file",
|
||||||
Method: "HEAD",
|
Method: "HEAD",
|
||||||
URL: "no",
|
URL: "no",
|
||||||
|
@ -55,5 +63,16 @@ func TestHead(t *testing.T) {
|
||||||
"Tus-Resumable": "1.0.0",
|
"Tus-Resumable": "1.0.0",
|
||||||
},
|
},
|
||||||
Code: http.StatusNotFound,
|
Code: http.StatusNotFound,
|
||||||
|
ResBody: "",
|
||||||
}).Run(handler, t)
|
}).Run(handler, t)
|
||||||
|
|
||||||
|
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)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue