Makes http request cached for tests

This commit is contained in:
2016-01-20 13:28:07 +01:00
parent 261c43184e
commit ea62247dad
5 changed files with 23 additions and 20 deletions

View File

@@ -9,10 +9,16 @@ import (
"path/filepath"
"regexp"
"time"
"github.com/gregjones/httpcache"
"github.com/gregjones/httpcache/diskcache"
"github.com/peterbourgon/diskv"
)
var albumsDataTest []Album
var testGetter HTTPGetter
// StripNonCsvField strips all the fields which are not in the Csv
func StripNonCsvField(a Album) Album {
return Album{
@@ -89,4 +95,11 @@ func init() {
if err = dec.Decode(&albumsDataTest); err != nil {
panic(fmt.Sprintf("Could not parse '%s': %s", albumsPath, err))
}
dv := diskv.New(diskv.Options{
BasePath: filepath.Join("testdata", "web-cache"),
CacheSizeMax: 100 * 1024 * 1024, // 100MB
})
testGetter = httpcache.NewTransport(diskcache.NewWithDiskv(dv)).Client()
}