mirror of
https://github.com/astaxie/beego.git
synced 2024-11-22 07:30:55 +00:00
add cache-hit test example
This commit is contained in:
parent
d31975a752
commit
2449aad105
@ -4,6 +4,7 @@ import (
|
|||||||
"bytes"
|
"bytes"
|
||||||
"compress/gzip"
|
"compress/gzip"
|
||||||
"compress/zlib"
|
"compress/zlib"
|
||||||
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
@ -53,6 +54,31 @@ func TestOpenStaticFileDeflate_1(t *testing.T) {
|
|||||||
testOpenFile("deflate", content, t)
|
testOpenFile("deflate", content, t)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestStaticCacheWork(t *testing.T) {
|
||||||
|
encodings := []string{"", "gzip", "deflate"}
|
||||||
|
|
||||||
|
fi, _ := os.Stat(licenseFile)
|
||||||
|
for _, encoding := range encodings {
|
||||||
|
_, _, first, _, err := openFile(licenseFile, fi, encoding)
|
||||||
|
if err != nil {
|
||||||
|
t.Error(err)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
_, _, second, _, err := openFile(licenseFile, fi, encoding)
|
||||||
|
if err != nil {
|
||||||
|
t.Error(err)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
address1 := fmt.Sprintf("%p", first)
|
||||||
|
address2 := fmt.Sprintf("%p", second)
|
||||||
|
if address1 != address2 {
|
||||||
|
t.Errorf("encoding '%v' can not hit cache", encoding)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func assetOpenFileAndContent(sch *serveContentHolder, reader *serveContentReader, content []byte, t *testing.T) {
|
func assetOpenFileAndContent(sch *serveContentHolder, reader *serveContentReader, content []byte, t *testing.T) {
|
||||||
t.Log(sch.size, len(content))
|
t.Log(sch.size, len(content))
|
||||||
if sch.size != int64(len(content)) {
|
if sch.size != int64(len(content)) {
|
||||||
|
Loading…
Reference in New Issue
Block a user