Skip to content

Commit

Permalink
add cache-hit test example
Browse files Browse the repository at this point in the history
  • Loading branch information
jianzhiyao committed May 9, 2020
1 parent d31975a commit 2449aad
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions staticfile_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"bytes"
"compress/gzip"
"compress/zlib"
"fmt"
"io"
"io/ioutil"
"os"
Expand Down Expand Up @@ -53,6 +54,31 @@ func TestOpenStaticFileDeflate_1(t *testing.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) {
t.Log(sch.size, len(content))
if sch.size != int64(len(content)) {
Expand Down

0 comments on commit 2449aad

Please sign in to comment.