Esempio n. 1
0
// TestGetSet is a helper to test Cache.Get()/Set().
func TestGetSet(t *testing.T, cache imageserver_cache.Cache) {
	err := cache.Set(KeyValid, testdata.Medium, imageserver.Params{})
	if err != nil {
		t.Fatal(err)
	}
	im, err := cache.Get(KeyValid, imageserver.Params{})
	if err != nil {
		t.Fatal(err)
	}
	if im == nil {
		t.Fatal("image nil")
	}
	if !imageserver.ImageEqual(im, testdata.Medium) {
		t.Fatal("image not equals")
	}
}
func TestServer(t *testing.T) {
	srv := newTestServer(
		&imageserver.StaticServer{
			Image: testdata.Medium,
		},
		imageserver_cache.StringKeyGenerator("test"),
	)
	im, err := srv.Get(imageserver.Params{
		imageserver.SourceParam: testdata.MediumFileName,
	})
	if err != nil {
		t.Fatal(err)
	}
	if !imageserver.ImageEqual(im, testdata.Medium) {
		t.Fatal("not equal")
	}
}
Esempio n. 3
0
func TestServer(t *testing.T) {
	srv := newTestServer(
		imageserver.ServerFunc(func(params imageserver.Params) (*imageserver.Image, error) {
			return testdata.Medium, nil
		}),
		imageserver_cache.StringKeyGenerator("test"),
	)
	im, err := srv.Get(imageserver.Params{
		imageserver.SourceParam: testdata.MediumFileName,
	})
	if err != nil {
		t.Fatal(err)
	}
	if !imageserver.ImageEqual(im, testdata.Medium) {
		t.Fatal("not equal")
	}
}
Esempio n. 4
0
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")
	}
}
Esempio n. 5
0
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 TestGetter(t *testing.T) {
	ctx := &Context{
		Params: imageserver.Params{},
	}
	var data []byte
	dest := groupcache.AllocatingByteSliceSink(&data)
	gt := &Getter{
		Server: &imageserver.StaticServer{
			Image: testdata.Medium,
		},
	}
	err := gt.Get(ctx, "foo", dest)
	if err != nil {
		t.Fatal(err)
	}
	im := new(imageserver.Image)
	err = im.UnmarshalBinary(data)
	if err != nil {
		t.Fatal(err)
	}
	if !imageserver.ImageEqual(im, testdata.Medium) {
		t.Fatal("not equal")
	}
}