mirror of
https://github.com/nkanaev/yarr.git
synced 2025-09-14 02:10:04 +00:00
cache feed icons
This commit is contained in:
@@ -1,10 +1,13 @@
|
||||
package server
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
"log"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"os"
|
||||
"reflect"
|
||||
"testing"
|
||||
|
||||
"github.com/nkanaev/yarr/src/storage"
|
||||
@@ -71,3 +74,41 @@ func TestIndexGzipped(t *testing.T) {
|
||||
t.Errorf("invalid content-type header: %#v", response.Header.Get("content-type"))
|
||||
}
|
||||
}
|
||||
|
||||
func TestFeedIcons(t *testing.T) {
|
||||
log.SetOutput(io.Discard)
|
||||
db, _ := storage.New(":memory:")
|
||||
icon := []byte("test")
|
||||
feed := db.CreateFeed("", "", "", "", nil)
|
||||
db.UpdateFeedIcon(feed.Id, &icon)
|
||||
log.SetOutput(os.Stderr)
|
||||
|
||||
recorder := httptest.NewRecorder()
|
||||
url := fmt.Sprintf("/api/feeds/%d/icon", feed.Id)
|
||||
request := httptest.NewRequest("GET", url, nil)
|
||||
|
||||
handler := NewServer(db, "127.0.0.1:8000").handler()
|
||||
handler.ServeHTTP(recorder, request)
|
||||
response := recorder.Result()
|
||||
|
||||
if response.StatusCode != http.StatusOK {
|
||||
t.Fatal()
|
||||
}
|
||||
body, _ := io.ReadAll(response.Body)
|
||||
if !reflect.DeepEqual(body, icon) {
|
||||
t.Fatal()
|
||||
}
|
||||
if response.Header.Get("Etag") == "" {
|
||||
t.Fatal()
|
||||
}
|
||||
|
||||
recorder2 := httptest.NewRecorder()
|
||||
request2 := httptest.NewRequest("GET", url, nil)
|
||||
request2.Header.Set("If-None-Match", response.Header.Get("Etag"))
|
||||
handler.ServeHTTP(recorder2, request2)
|
||||
response2 := recorder2.Result()
|
||||
|
||||
if response2.StatusCode != http.StatusNotModified {
|
||||
t.Fatal("got", response2.StatusCode)
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user