We don't want to have a large bandwidth on bedetheque.com, so the pace at which we perform GET request is limited by a maximal number of request over a window (per example no more than 10 request over 10 second) If more request are required, the request is simply paused until we go back within the limit ;). Go rulez !
45 lines
1.5 KiB
Go
45 lines
1.5 KiB
Go
package main
|
|
|
|
import (
|
|
"io/ioutil"
|
|
"os"
|
|
"time"
|
|
|
|
. "gopkg.in/check.v1"
|
|
)
|
|
|
|
type AlbumDescriptionCacheSuite struct{}
|
|
|
|
var _ = Suite(&AlbumDescriptionCacheSuite{})
|
|
|
|
func (s *AlbumDescriptionCacheSuite) TestCanFetchCache(c *C) {
|
|
data := map[AlbumID]AlbumDescription{
|
|
41693: AlbumDescription{
|
|
CoverExt: ".jpg",
|
|
Description: `Un couple Pennagolans - une race de vampire - s'est substitué depuis longtemps à une famille d'aristocrates japonais. Ils se font régulièrement livrer des proies humaines pour changer de corps, et ainsi survivre. Cependant leur dernier enlèvement n'est pas aussi discret que les précédents... Voilà les puissants vampires traqués par le redoutable Okko et ses deux compagnons !`,
|
|
Note: 4.2,
|
|
Scenarist: []Link{Link{"Hub", "http://www.bedetheque.com/auteur-9851-BD-Hub.html"}},
|
|
Designer: []Link{Link{"Hub", "http://www.bedetheque.com/auteur-9851-BD-Hub.html"}},
|
|
Colorist: []Link{
|
|
Link{"Hub", "http://www.bedetheque.com/auteur-9851-BD-Hub.html"},
|
|
Link{"Pelayo, Stephan", "http://www.bedetheque.com/auteur-9852-BD-Pelayo-Stephan.html"},
|
|
},
|
|
},
|
|
}
|
|
|
|
tmpdir, err := ioutil.TempDir("", "satbdexplorer-tests-cache")
|
|
c.Assert(err, IsNil)
|
|
defer os.RemoveAll(tmpdir)
|
|
|
|
cache, err := NewAlbumDescriptionCache(tmpdir, 10, 10*time.Second)
|
|
c.Assert(err, IsNil)
|
|
|
|
for ID, expected := range data {
|
|
desc, err := cache.GetDescription(ID)
|
|
if c.Check(err, IsNil) && c.Check(desc, NotNil) == true {
|
|
c.Check(*desc, DeepEquals, expected)
|
|
}
|
|
}
|
|
|
|
}
|