test: add unit tests

This commit is contained in:
rramiachraf
2024-03-06 20:53:29 +01:00
parent c8747c0182
commit afc0347a1b
19 changed files with 358 additions and 31 deletions

38
handlers/proxy_test.go Normal file
View 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)
}
}