func TestAsyncGetSet(t *testing.T) { mapCache := cachetest.NewMapCache() setCallCh := make(chan struct{}) asyncCache := &Async{ Cache: &Func{ GetFunc: func(key string, params imageserver.Params) (*imageserver.Image, error) { return mapCache.Get(key, params) }, SetFunc: func(key string, image *imageserver.Image, params imageserver.Params) error { err := mapCache.Set(key, image, params) setCallCh <- struct{}{} return err }, }, } err := asyncCache.Set("foo", testdata.Small, imageserver.Params{}) if err != nil { panic(err) } <-setCallCh im, err := asyncCache.Get("foo", imageserver.Params{}) if err != nil { panic(err) } if im == nil { t.Fatal("no image") } }
func TestServerErrorServer(t *testing.T) { s := &Server{ Server: &imageserver.StaticServer{Error: errors.New("error")}, Cache: cachetest.NewMapCache(), KeyGenerator: StringKeyGenerator("test"), } _, err := s.Get(imageserver.Params{}) if err == nil { t.Fatal("no error") } }
func TestServerErrorServer(t *testing.T) { s := &Server{ Server: imageserver.ServerFunc(func(params imageserver.Params) (*imageserver.Image, error) { return nil, fmt.Errorf("error") }), Cache: cachetest.NewMapCache(), KeyGenerator: StringKeyGenerator("test"), } _, err := s.Get(imageserver.Params{}) if err == nil { t.Fatal("no error") } }
func TestServer(t *testing.T) { s := &Server{ Server: &imageserver.StaticServer{Image: testdata.Medium}, Cache: cachetest.NewMapCache(), KeyGenerator: StringKeyGenerator("test"), } image1, err := s.Get(imageserver.Params{}) if err != nil { t.Fatal(err) } image2, err := s.Get(imageserver.Params{}) if err != nil { t.Fatal(err) } if !imageserver.ImageEqual(image1, image2) { t.Fatal("not equal") } }
func TestServer(t *testing.T) { s := &Server{ Server: imageserver.ServerFunc(func(params imageserver.Params) (*imageserver.Image, error) { return testdata.Medium, nil }), Cache: cachetest.NewMapCache(), KeyGenerator: StringKeyGenerator("test"), } image1, err := s.Get(imageserver.Params{}) if err != nil { t.Fatal(err) } image2, err := s.Get(imageserver.Params{}) if err != nil { t.Fatal(err) } if !imageserver.ImageEqual(image1, image2) { t.Fatal("not equal") } }
func TestIgnoreErrorGetSet(t *testing.T) { c := &IgnoreError{ Cache: cachetest.NewMapCache(), } cachetest.TestGetSet(t, c) }