test: add unit tests
This commit is contained in:
38
handlers/proxy_test.go
Normal file
38
handlers/proxy_test.go
Normal file
@ -0,0 +1,38 @@
|
||||
package handlers
|
||||
|
||||
import (
|
||||
"mime"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"testing"
|
||||
|
||||
"github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
func TestImageProxy(t *testing.T) {
|
||||
imgURL := "/images/3852401ae6c6d6a51aafe814d67199f0.1000x1000x1.jpg"
|
||||
|
||||
r, err := http.NewRequest(http.MethodGet, imgURL, nil)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
rr := httptest.NewRecorder()
|
||||
l := logrus.New()
|
||||
m := New(l)
|
||||
|
||||
m.ServeHTTP(rr, r)
|
||||
|
||||
cc := rr.Result().Header.Get("cache-control")
|
||||
maxAge := "max-age=1296000"
|
||||
ct := rr.Result().Header.Get("content-type")
|
||||
mimeType := mime.TypeByExtension(".jpg")
|
||||
|
||||
if cc != maxAge {
|
||||
t.Fatalf("expected %q, got %q\n", maxAge, cc)
|
||||
}
|
||||
|
||||
if ct != mimeType {
|
||||
t.Fatalf("expected %q, got %q\n", mimeType, ct)
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user