mirror of
https://github.com/binwiederhier/ntfy.git
synced 2025-04-05 14:07:39 +03:00
parent
02f8a32b46
commit
534b93e142
13 changed files with 425 additions and 29 deletions
44
util/embedfs_test.go
Normal file
44
util/embedfs_test.go
Normal file
|
@ -0,0 +1,44 @@
|
|||
package util
|
||||
|
||||
import (
|
||||
"embed"
|
||||
"github.com/stretchr/testify/require"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
var (
|
||||
modTime = time.Now()
|
||||
|
||||
//go:embed embedfs
|
||||
testFs embed.FS
|
||||
testFsCached = &CachingEmbedFS{ModTime: modTime, FS: testFs}
|
||||
)
|
||||
|
||||
func TestCachingEmbedFS(t *testing.T) {
|
||||
s := http.FileServer(http.FS(testFsCached))
|
||||
|
||||
rr := httptest.NewRecorder()
|
||||
req, _ := http.NewRequest("GET", "/embedfs/test.txt", nil)
|
||||
s.ServeHTTP(rr, req)
|
||||
require.Equal(t, 200, rr.Code)
|
||||
lastModified := rr.Header().Get("Last-Modified")
|
||||
|
||||
rr = httptest.NewRecorder()
|
||||
req, _ = http.NewRequest("GET", "/embedfs/test.txt", nil)
|
||||
req.Header.Set("If-Modified-Since", lastModified)
|
||||
s.ServeHTTP(rr, req)
|
||||
require.Equal(t, 304, rr.Code) // Huzzah!
|
||||
}
|
||||
|
||||
func TestCachingEmbedFS_Range(t *testing.T) {
|
||||
s := http.FileServer(http.FS(testFsCached))
|
||||
rr := httptest.NewRecorder()
|
||||
req, _ := http.NewRequest("GET", "/embedfs/test.txt", nil)
|
||||
req.Header.Set("Range", "bytes=1-20")
|
||||
s.ServeHTTP(rr, req)
|
||||
require.Equal(t, 206, rr.Code)
|
||||
require.Equal(t, "his is a test file f", rr.Body.String())
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue