func TestMissingFileError(t *testing.T) {
	srv := setupNamedSizesServer()
	rec := srv("GET", "/29/small/nonexisting.jpg")

	img := bimg.NewImage(rec.Body.Bytes())
	meta, err := img.Metadata()
	if err != nil {
		log.Fatal(err.Error())
	}

	th.ExpectInt(t, 200, rec.Code)
	th.ExpectStr(t, "jpeg", img.Type())
	th.ExpectInt(t, 240, meta.Size.Width)

	l := strconv.Itoa(len(rec.Body.Bytes()))
	th.ExpectStr(t, rec.HeaderMap.Get("Content-Length"), l)

	th.ExpectStr(t, rec.HeaderMap.Get("Cache-Control"), "public, max-age=10")
	th.ExpectStr(t, rec.HeaderMap.Get("Content-Type"), "image/jpeg")

	th.ExpectContains(t, rec.HeaderMap.Get("X-Btc-Error"), "open ../fixtures/29/original/nonexisting.jpg: no such file or directory")
}
Beispiel #2
0
func TestCachedImage(t *testing.T) {
	srv := setupCachedEndpoint()

	rec := srv("GET", "/29/small/111900-_MG_2031.JPG")

	th.ExpectInt(t, 200, rec.Code)

	img := bimg.NewImage(rec.Body.Bytes())
	meta, err := img.Metadata()
	if err != nil {
		log.Fatal(err.Error())
	}

	th.ExpectStr(t, img.Type(), "jpeg")

	th.ExpectInt(t, 300, meta.Size.Height)
	th.ExpectInt(t, 240, meta.Size.Width)

	filePath := "../fixtures/test/29/small/111900-_MG_2031.JPG"

	cachedData, err := ioutil.ReadFile(filePath)
	if err != nil {
		log.Fatal(err.Error())
	}

	img = bimg.NewImage(cachedData)
	meta, err = img.Metadata()
	if err != nil {
		log.Fatal(err.Error())
	}

	th.ExpectStr(t, img.Type(), "jpeg")

	th.ExpectInt(t, 300, meta.Size.Height)
	th.ExpectInt(t, 240, meta.Size.Width)

	os.Remove(filePath)
}
Beispiel #3
0
func TestValidSignature(t *testing.T) {

	srv := secureHandlerFor("Hello!", "validsecret")
	rec := srv("GET", "/r/eyJnIjoiMTMweDEzMCNudyIsInNyYyI6ImNoZWV0YWguanBnIn0/62cf3cd857518cd")

	th.ExpectStr(t, rec.Body.String(), "Hello!")
	th.ExpectInt(t, rec.Code, 200)

	srv = secureHandlerFor("Hello!", "invalidsecret")
	rec = srv("GET", "/r/eyJnIjoiMTMweDEzMCNudyIsInNyYyI6ImNoZWV0YWguanBnIn0/62cf3cd857518cd")

	th.ExpectInt(t, rec.Code, 400)
	th.ExpectContains(t, rec.Body.String(), "Invalid cryptographic signature")

}
func TestServeSmallSize(t *testing.T) {
	srv := setupNamedSizesServer()
	rec := srv("GET", "/29/small/111900-_MG_2031.JPG")

	th.ExpectInt(t, 200, rec.Code)

	img := bimg.NewImage(rec.Body.Bytes())
	meta, err := img.Metadata()
	if err != nil {
		log.Fatal(err.Error())
	}

	th.ExpectStr(t, img.Type(), "jpeg")

	th.ExpectInt(t, 300, meta.Size.Height)
	th.ExpectInt(t, 240, meta.Size.Width)

	l := strconv.Itoa(len(rec.Body.Bytes()))
	th.ExpectStr(t, rec.HeaderMap.Get("Content-Length"), l)

	th.ExpectStr(t, rec.HeaderMap.Get("Cache-Control"), "public, max-age=94608000")

	th.ExpectStr(t, rec.HeaderMap.Get("Content-Type"), "image/jpeg")
}
func TestServeLargeSize(t *testing.T) {
	srv := setupNamedSizesServer()
	rec := srv("GET", "/29/large/111900-_MG_2031.JPG")

	th.ExpectInt(t, 200, rec.Code)

	img := bimg.NewImage(rec.Body.Bytes())
	meta, err := img.Metadata()
	if err != nil {
		log.Fatal(err.Error())
	}

	th.ExpectStr(t, img.Type(), "jpeg")

	th.ExpectInt(t, 1000, meta.Size.Height)
	th.ExpectInt(t, 800, meta.Size.Width)
}