feat: add Gopkg manifests, move fixtures to testdata, add vendor dependencies
4
.gitignore
vendored
|
|
@ -4,6 +4,6 @@ bin
|
||||||
/*.jpg
|
/*.jpg
|
||||||
/*.png
|
/*.png
|
||||||
/*.webp
|
/*.webp
|
||||||
/fixtures/*_out.*
|
/testdata/*_out.*
|
||||||
/.idea/
|
/.idea/
|
||||||
fixtures/test_vertical_*.jpg
|
testdata/test_vertical_*.jpg
|
||||||
|
|
|
||||||
15
Gopkg.lock
generated
Normal file
|
|
@ -0,0 +1,15 @@
|
||||||
|
# This file is autogenerated, do not edit; changes may be undone by the next 'dep ensure'.
|
||||||
|
|
||||||
|
|
||||||
|
[[projects]]
|
||||||
|
name = "github.com/tj/go-debug"
|
||||||
|
packages = ["."]
|
||||||
|
revision = "ff4a55a20a86994118644bbddc6a216da193cc13"
|
||||||
|
version = "v2.0.0"
|
||||||
|
|
||||||
|
[solve-meta]
|
||||||
|
analyzer-name = "dep"
|
||||||
|
analyzer-version = 1
|
||||||
|
inputs-digest = "6a05cef6e16f81ece71d6125d24af0bceb1d65db5c902c7b46eeb6d2a46826d3"
|
||||||
|
solver-name = "gps-cdcl"
|
||||||
|
solver-version = 1
|
||||||
26
Gopkg.toml
Normal file
|
|
@ -0,0 +1,26 @@
|
||||||
|
|
||||||
|
# Gopkg.toml example
|
||||||
|
#
|
||||||
|
# Refer to https://github.com/golang/dep/blob/master/docs/Gopkg.toml.md
|
||||||
|
# for detailed Gopkg.toml documentation.
|
||||||
|
#
|
||||||
|
# required = ["github.com/user/thing/cmd/thing"]
|
||||||
|
# ignored = ["github.com/user/project/pkgX", "bitbucket.org/user/project/pkgA/pkgY"]
|
||||||
|
#
|
||||||
|
# [[constraint]]
|
||||||
|
# name = "github.com/user/project"
|
||||||
|
# version = "1.0.0"
|
||||||
|
#
|
||||||
|
# [[constraint]]
|
||||||
|
# name = "github.com/user/project2"
|
||||||
|
# branch = "dev"
|
||||||
|
# source = "github.com/myfork/project2"
|
||||||
|
#
|
||||||
|
# [[override]]
|
||||||
|
# name = "github.com/x/y"
|
||||||
|
# version = "2.4.0"
|
||||||
|
|
||||||
|
|
||||||
|
[[constraint]]
|
||||||
|
name = "github.com/tj/go-debug"
|
||||||
|
version = "2.0.0"
|
||||||
|
|
@ -5,7 +5,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestRead(t *testing.T) {
|
func TestRead(t *testing.T) {
|
||||||
buf, err := Read("fixtures/test.jpg")
|
buf, err := Read("testdata/test.jpg")
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("Cannot read the image: %#v", err)
|
t.Errorf("Cannot read the image: %#v", err)
|
||||||
|
|
@ -21,7 +21,7 @@ func TestRead(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestWrite(t *testing.T) {
|
func TestWrite(t *testing.T) {
|
||||||
buf, err := Read("fixtures/test.jpg")
|
buf, err := Read("testdata/test.jpg")
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("Cannot read the image: %#v", err)
|
t.Errorf("Cannot read the image: %#v", err)
|
||||||
|
|
@ -31,7 +31,7 @@ func TestWrite(t *testing.T) {
|
||||||
t.Fatal("Empty buffer")
|
t.Fatal("Empty buffer")
|
||||||
}
|
}
|
||||||
|
|
||||||
err = Write("fixtures/test_write_out.jpg", buf)
|
err = Write("testdata/test_write_out.jpg", buf)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("Cannot write the file: %#v", err)
|
t.Fatalf("Cannot write the file: %#v", err)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -17,7 +17,7 @@ func TestImageResize(t *testing.T) {
|
||||||
t.Error(err)
|
t.Error(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
Write("fixtures/test_resize_out.jpg", buf)
|
Write("testdata/test_resize_out.jpg", buf)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestImageGifResize(t *testing.T) {
|
func TestImageGifResize(t *testing.T) {
|
||||||
|
|
@ -52,7 +52,7 @@ func TestImageGifToJpeg(t *testing.T) {
|
||||||
t.Errorf("Cannot process the image: %#v", err)
|
t.Errorf("Cannot process the image: %#v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
Write("fixtures/test_gif.jpg", buf)
|
Write("testdata/test_gif.jpg", buf)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -67,7 +67,7 @@ func TestImagePdfToJpeg(t *testing.T) {
|
||||||
t.Errorf("Cannot process the image: %#v", err)
|
t.Errorf("Cannot process the image: %#v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
Write("fixtures/test_pdf.jpg", buf)
|
Write("testdata/test_pdf.jpg", buf)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -82,7 +82,7 @@ func TestImageSvgToJpeg(t *testing.T) {
|
||||||
t.Errorf("Cannot process the image: %#v", err)
|
t.Errorf("Cannot process the image: %#v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
Write("fixtures/test_svg.jpg", buf)
|
Write("testdata/test_svg.jpg", buf)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -97,7 +97,7 @@ func TestImageResizeAndCrop(t *testing.T) {
|
||||||
t.Error(err)
|
t.Error(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
Write("fixtures/test_resize_crop_out.jpg", buf)
|
Write("testdata/test_resize_crop_out.jpg", buf)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestImageExtract(t *testing.T) {
|
func TestImageExtract(t *testing.T) {
|
||||||
|
|
@ -111,7 +111,7 @@ func TestImageExtract(t *testing.T) {
|
||||||
t.Error(err)
|
t.Error(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
Write("fixtures/test_extract_out.jpg", buf)
|
Write("testdata/test_extract_out.jpg", buf)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestImageExtractZero(t *testing.T) {
|
func TestImageExtractZero(t *testing.T) {
|
||||||
|
|
@ -125,7 +125,7 @@ func TestImageExtractZero(t *testing.T) {
|
||||||
t.Error(err)
|
t.Error(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
Write("fixtures/test_extract_zero_out.jpg", buf)
|
Write("testdata/test_extract_zero_out.jpg", buf)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestImageEnlarge(t *testing.T) {
|
func TestImageEnlarge(t *testing.T) {
|
||||||
|
|
@ -139,7 +139,7 @@ func TestImageEnlarge(t *testing.T) {
|
||||||
t.Error(err)
|
t.Error(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
Write("fixtures/test_enlarge_out.jpg", buf)
|
Write("testdata/test_enlarge_out.jpg", buf)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestImageEnlargeAndCrop(t *testing.T) {
|
func TestImageEnlargeAndCrop(t *testing.T) {
|
||||||
|
|
@ -153,7 +153,7 @@ func TestImageEnlargeAndCrop(t *testing.T) {
|
||||||
t.Error(err)
|
t.Error(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
Write("fixtures/test_enlarge_crop_out.jpg", buf)
|
Write("testdata/test_enlarge_crop_out.jpg", buf)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestImageCrop(t *testing.T) {
|
func TestImageCrop(t *testing.T) {
|
||||||
|
|
@ -167,7 +167,7 @@ func TestImageCrop(t *testing.T) {
|
||||||
t.Error(err)
|
t.Error(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
Write("fixtures/test_crop_out.jpg", buf)
|
Write("testdata/test_crop_out.jpg", buf)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestImageCropByWidth(t *testing.T) {
|
func TestImageCropByWidth(t *testing.T) {
|
||||||
|
|
@ -181,7 +181,7 @@ func TestImageCropByWidth(t *testing.T) {
|
||||||
t.Error(err)
|
t.Error(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
Write("fixtures/test_crop_width_out.jpg", buf)
|
Write("testdata/test_crop_width_out.jpg", buf)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestImageCropByHeight(t *testing.T) {
|
func TestImageCropByHeight(t *testing.T) {
|
||||||
|
|
@ -195,7 +195,7 @@ func TestImageCropByHeight(t *testing.T) {
|
||||||
t.Error(err)
|
t.Error(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
Write("fixtures/test_crop_height_out.jpg", buf)
|
Write("testdata/test_crop_height_out.jpg", buf)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestImageThumbnail(t *testing.T) {
|
func TestImageThumbnail(t *testing.T) {
|
||||||
|
|
@ -209,7 +209,7 @@ func TestImageThumbnail(t *testing.T) {
|
||||||
t.Error(err)
|
t.Error(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
Write("fixtures/test_thumbnail_out.jpg", buf)
|
Write("testdata/test_thumbnail_out.jpg", buf)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestImageWatermark(t *testing.T) {
|
func TestImageWatermark(t *testing.T) {
|
||||||
|
|
@ -239,7 +239,7 @@ func TestImageWatermark(t *testing.T) {
|
||||||
t.Fatal("Image is not jpeg")
|
t.Fatal("Image is not jpeg")
|
||||||
}
|
}
|
||||||
|
|
||||||
Write("fixtures/test_watermark_text_out.jpg", buf)
|
Write("testdata/test_watermark_text_out.jpg", buf)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestImageWatermarkWithImage(t *testing.T) {
|
func TestImageWatermarkWithImage(t *testing.T) {
|
||||||
|
|
@ -266,7 +266,7 @@ func TestImageWatermarkWithImage(t *testing.T) {
|
||||||
t.Fatal("Image is not jpeg")
|
t.Fatal("Image is not jpeg")
|
||||||
}
|
}
|
||||||
|
|
||||||
Write("fixtures/test_watermark_image_out.jpg", buf)
|
Write("testdata/test_watermark_image_out.jpg", buf)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestImageWatermarkNoReplicate(t *testing.T) {
|
func TestImageWatermarkNoReplicate(t *testing.T) {
|
||||||
|
|
@ -297,7 +297,7 @@ func TestImageWatermarkNoReplicate(t *testing.T) {
|
||||||
t.Fatal("Image is not jpeg")
|
t.Fatal("Image is not jpeg")
|
||||||
}
|
}
|
||||||
|
|
||||||
Write("fixtures/test_watermark_replicate_out.jpg", buf)
|
Write("testdata/test_watermark_replicate_out.jpg", buf)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestImageZoom(t *testing.T) {
|
func TestImageZoom(t *testing.T) {
|
||||||
|
|
@ -318,7 +318,7 @@ func TestImageZoom(t *testing.T) {
|
||||||
t.Error(err)
|
t.Error(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
Write("fixtures/test_zoom_out.jpg", buf)
|
Write("testdata/test_zoom_out.jpg", buf)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestImageFlip(t *testing.T) {
|
func TestImageFlip(t *testing.T) {
|
||||||
|
|
@ -326,7 +326,7 @@ func TestImageFlip(t *testing.T) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("Cannot process the image: %#v", err)
|
t.Errorf("Cannot process the image: %#v", err)
|
||||||
}
|
}
|
||||||
Write("fixtures/test_flip_out.jpg", buf)
|
Write("testdata/test_flip_out.jpg", buf)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestImageFlop(t *testing.T) {
|
func TestImageFlop(t *testing.T) {
|
||||||
|
|
@ -334,7 +334,7 @@ func TestImageFlop(t *testing.T) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("Cannot process the image: %#v", err)
|
t.Errorf("Cannot process the image: %#v", err)
|
||||||
}
|
}
|
||||||
Write("fixtures/test_flop_out.jpg", buf)
|
Write("testdata/test_flop_out.jpg", buf)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestImageRotate(t *testing.T) {
|
func TestImageRotate(t *testing.T) {
|
||||||
|
|
@ -342,7 +342,7 @@ func TestImageRotate(t *testing.T) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("Cannot process the image: %#v", err)
|
t.Errorf("Cannot process the image: %#v", err)
|
||||||
}
|
}
|
||||||
Write("fixtures/test_image_rotate_out.jpg", buf)
|
Write("testdata/test_image_rotate_out.jpg", buf)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestImageConvert(t *testing.T) {
|
func TestImageConvert(t *testing.T) {
|
||||||
|
|
@ -350,7 +350,7 @@ func TestImageConvert(t *testing.T) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("Cannot process the image: %#v", err)
|
t.Errorf("Cannot process the image: %#v", err)
|
||||||
}
|
}
|
||||||
Write("fixtures/test_image_convert_out.png", buf)
|
Write("testdata/test_image_convert_out.png", buf)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestTransparentImageConvert(t *testing.T) {
|
func TestTransparentImageConvert(t *testing.T) {
|
||||||
|
|
@ -363,7 +363,7 @@ func TestTransparentImageConvert(t *testing.T) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("Cannot process the image: %#v", err)
|
t.Errorf("Cannot process the image: %#v", err)
|
||||||
}
|
}
|
||||||
Write("fixtures/test_transparent_image_convert_out.jpg", buf)
|
Write("testdata/test_transparent_image_convert_out.jpg", buf)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestImageMetadata(t *testing.T) {
|
func TestImageMetadata(t *testing.T) {
|
||||||
|
|
@ -452,7 +452,7 @@ func TestFluentInterface(t *testing.T) {
|
||||||
t.Fatal("Invalid image type")
|
t.Fatal("Invalid image type")
|
||||||
}
|
}
|
||||||
|
|
||||||
Write("fixtures/test_image_fluent_out.png", image.Image())
|
Write("testdata/test_image_fluent_out.png", image.Image())
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestImageSmartCrop(t *testing.T) {
|
func TestImageSmartCrop(t *testing.T) {
|
||||||
|
|
@ -472,7 +472,7 @@ func TestImageSmartCrop(t *testing.T) {
|
||||||
t.Error(err)
|
t.Error(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
Write("fixtures/test_smart_crop.jpg", buf)
|
Write("testdata/test_smart_crop.jpg", buf)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestImageTrim(t *testing.T) {
|
func TestImageTrim(t *testing.T) {
|
||||||
|
|
@ -492,7 +492,7 @@ func TestImageTrim(t *testing.T) {
|
||||||
t.Errorf("The image wasn't trimmed.")
|
t.Errorf("The image wasn't trimmed.")
|
||||||
}
|
}
|
||||||
|
|
||||||
Write("fixtures/transparent_trim.png", buf)
|
Write("testdata/transparent_trim.png", buf)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestImageLength(t *testing.T) {
|
func TestImageLength(t *testing.T) {
|
||||||
|
|
@ -512,7 +512,7 @@ func initImage(file string) *Image {
|
||||||
}
|
}
|
||||||
|
|
||||||
func imageBuf(file string) ([]byte, error) {
|
func imageBuf(file string) ([]byte, error) {
|
||||||
return Read(path.Join("fixtures", file))
|
return Read(path.Join("testdata", file))
|
||||||
}
|
}
|
||||||
|
|
||||||
func assertSize(buf []byte, width, height int) error {
|
func assertSize(buf []byte, width, height int) error {
|
||||||
|
|
|
||||||
|
|
@ -118,7 +118,7 @@ func TestColourspaceIsSupported(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func readFile(file string) []byte {
|
func readFile(file string) []byte {
|
||||||
data, _ := os.Open(path.Join("fixtures", file))
|
data, _ := os.Open(path.Join("testdata", file))
|
||||||
buf, _ := ioutil.ReadAll(data)
|
buf, _ := ioutil.ReadAll(data)
|
||||||
return buf
|
return buf
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -14,7 +14,7 @@ import (
|
||||||
|
|
||||||
func TestResize(t *testing.T) {
|
func TestResize(t *testing.T) {
|
||||||
options := Options{Width: 800, Height: 600}
|
options := Options{Width: 800, Height: 600}
|
||||||
buf, _ := Read("fixtures/test.jpg")
|
buf, _ := Read("testdata/test.jpg")
|
||||||
|
|
||||||
newImg, err := Resize(buf, options)
|
newImg, err := Resize(buf, options)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
@ -30,7 +30,7 @@ func TestResize(t *testing.T) {
|
||||||
t.Fatalf("Invalid image size: %dx%d", size.Width, size.Height)
|
t.Fatalf("Invalid image size: %dx%d", size.Width, size.Height)
|
||||||
}
|
}
|
||||||
|
|
||||||
Write("fixtures/test_out.jpg", newImg)
|
Write("testdata/test_out.jpg", newImg)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestResizeVerticalImage(t *testing.T) {
|
func TestResizeVerticalImage(t *testing.T) {
|
||||||
|
|
@ -51,11 +51,11 @@ func TestResizeVerticalImage(t *testing.T) {
|
||||||
{Force: true, Width: 2000, Height: 2000},
|
{Force: true, Width: 2000, Height: 2000},
|
||||||
}
|
}
|
||||||
|
|
||||||
bufJpeg, err := Read("fixtures/vertical.jpg")
|
bufJpeg, err := Read("testdata/vertical.jpg")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
bufWebp, err := Read("fixtures/vertical.webp")
|
bufWebp, err := Read("testdata/vertical.webp")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
@ -90,7 +90,7 @@ func TestResizeVerticalImage(t *testing.T) {
|
||||||
|
|
||||||
Write(
|
Write(
|
||||||
fmt.Sprintf(
|
fmt.Sprintf(
|
||||||
"fixtures/test_vertical_%dx%d_out.%s",
|
"testdata/test_vertical_%dx%d_out.%s",
|
||||||
options.Width,
|
options.Width,
|
||||||
options.Height,
|
options.Height,
|
||||||
ImageTypeName(source.format)),
|
ImageTypeName(source.format)),
|
||||||
|
|
@ -114,11 +114,11 @@ func TestResizeCustomSizes(t *testing.T) {
|
||||||
{Force: true, Width: 2000, Height: 2000},
|
{Force: true, Width: 2000, Height: 2000},
|
||||||
}
|
}
|
||||||
|
|
||||||
bufJpeg, err := Read("fixtures/test.jpg")
|
bufJpeg, err := Read("testdata/test.jpg")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
bufWebp, err := Read("fixtures/test.webp")
|
bufWebp, err := Read("testdata/test.webp")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
@ -181,7 +181,7 @@ func TestResizePrecision(t *testing.T) {
|
||||||
|
|
||||||
func TestRotate(t *testing.T) {
|
func TestRotate(t *testing.T) {
|
||||||
options := Options{Width: 800, Height: 600, Rotate: 270, Crop: true}
|
options := Options{Width: 800, Height: 600, Rotate: 270, Crop: true}
|
||||||
buf, _ := Read("fixtures/test.jpg")
|
buf, _ := Read("testdata/test.jpg")
|
||||||
|
|
||||||
newImg, err := Resize(buf, options)
|
newImg, err := Resize(buf, options)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
@ -197,12 +197,12 @@ func TestRotate(t *testing.T) {
|
||||||
t.Errorf("Invalid image size: %dx%d", size.Width, size.Height)
|
t.Errorf("Invalid image size: %dx%d", size.Width, size.Height)
|
||||||
}
|
}
|
||||||
|
|
||||||
Write("fixtures/test_rotate_out.jpg", newImg)
|
Write("testdata/test_rotate_out.jpg", newImg)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestInvalidRotateDegrees(t *testing.T) {
|
func TestInvalidRotateDegrees(t *testing.T) {
|
||||||
options := Options{Width: 800, Height: 600, Rotate: 111, Crop: true}
|
options := Options{Width: 800, Height: 600, Rotate: 111, Crop: true}
|
||||||
buf, _ := Read("fixtures/test.jpg")
|
buf, _ := Read("testdata/test.jpg")
|
||||||
|
|
||||||
newImg, err := Resize(buf, options)
|
newImg, err := Resize(buf, options)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
@ -218,12 +218,12 @@ func TestInvalidRotateDegrees(t *testing.T) {
|
||||||
t.Errorf("Invalid image size: %dx%d", size.Width, size.Height)
|
t.Errorf("Invalid image size: %dx%d", size.Width, size.Height)
|
||||||
}
|
}
|
||||||
|
|
||||||
Write("fixtures/test_rotate_invalid_out.jpg", newImg)
|
Write("testdata/test_rotate_invalid_out.jpg", newImg)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestCorruptedImage(t *testing.T) {
|
func TestCorruptedImage(t *testing.T) {
|
||||||
options := Options{Width: 800, Height: 600}
|
options := Options{Width: 800, Height: 600}
|
||||||
buf, _ := Read("fixtures/corrupt.jpg")
|
buf, _ := Read("testdata/corrupt.jpg")
|
||||||
|
|
||||||
newImg, err := Resize(buf, options)
|
newImg, err := Resize(buf, options)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
@ -239,12 +239,12 @@ func TestCorruptedImage(t *testing.T) {
|
||||||
t.Fatalf("Invalid image size: %dx%d", size.Width, size.Height)
|
t.Fatalf("Invalid image size: %dx%d", size.Width, size.Height)
|
||||||
}
|
}
|
||||||
|
|
||||||
Write("fixtures/test_corrupt_out.jpg", newImg)
|
Write("testdata/test_corrupt_out.jpg", newImg)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestNoColorProfile(t *testing.T) {
|
func TestNoColorProfile(t *testing.T) {
|
||||||
options := Options{Width: 800, Height: 600, NoProfile: true}
|
options := Options{Width: 800, Height: 600, NoProfile: true}
|
||||||
buf, _ := Read("fixtures/test.jpg")
|
buf, _ := Read("testdata/test.jpg")
|
||||||
|
|
||||||
newImg, err := Resize(buf, options)
|
newImg, err := Resize(buf, options)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
@ -264,7 +264,7 @@ func TestNoColorProfile(t *testing.T) {
|
||||||
|
|
||||||
func TestEmbedExtendColor(t *testing.T) {
|
func TestEmbedExtendColor(t *testing.T) {
|
||||||
options := Options{Width: 400, Height: 600, Crop: false, Embed: true, Extend: ExtendWhite, Background: Color{255, 20, 10}}
|
options := Options{Width: 400, Height: 600, Crop: false, Embed: true, Extend: ExtendWhite, Background: Color{255, 20, 10}}
|
||||||
buf, _ := Read("fixtures/test_issue.jpg")
|
buf, _ := Read("testdata/test_issue.jpg")
|
||||||
|
|
||||||
newImg, err := Resize(buf, options)
|
newImg, err := Resize(buf, options)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
@ -276,12 +276,12 @@ func TestEmbedExtendColor(t *testing.T) {
|
||||||
t.Fatalf("Invalid image size: %dx%d", size.Width, size.Height)
|
t.Fatalf("Invalid image size: %dx%d", size.Width, size.Height)
|
||||||
}
|
}
|
||||||
|
|
||||||
Write("fixtures/test_extend_white_out.jpg", newImg)
|
Write("testdata/test_extend_white_out.jpg", newImg)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestEmbedExtendWithCustomColor(t *testing.T) {
|
func TestEmbedExtendWithCustomColor(t *testing.T) {
|
||||||
options := Options{Width: 400, Height: 600, Crop: false, Embed: true, Extend: 5, Background: Color{255, 20, 10}}
|
options := Options{Width: 400, Height: 600, Crop: false, Embed: true, Extend: 5, Background: Color{255, 20, 10}}
|
||||||
buf, _ := Read("fixtures/test_issue.jpg")
|
buf, _ := Read("testdata/test_issue.jpg")
|
||||||
|
|
||||||
newImg, err := Resize(buf, options)
|
newImg, err := Resize(buf, options)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
@ -293,12 +293,12 @@ func TestEmbedExtendWithCustomColor(t *testing.T) {
|
||||||
t.Fatalf("Invalid image size: %dx%d", size.Width, size.Height)
|
t.Fatalf("Invalid image size: %dx%d", size.Width, size.Height)
|
||||||
}
|
}
|
||||||
|
|
||||||
Write("fixtures/test_extend_background_out.jpg", newImg)
|
Write("testdata/test_extend_background_out.jpg", newImg)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestGaussianBlur(t *testing.T) {
|
func TestGaussianBlur(t *testing.T) {
|
||||||
options := Options{Width: 800, Height: 600, GaussianBlur: GaussianBlur{Sigma: 5}}
|
options := Options{Width: 800, Height: 600, GaussianBlur: GaussianBlur{Sigma: 5}}
|
||||||
buf, _ := Read("fixtures/test.jpg")
|
buf, _ := Read("testdata/test.jpg")
|
||||||
|
|
||||||
newImg, err := Resize(buf, options)
|
newImg, err := Resize(buf, options)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
@ -310,12 +310,12 @@ func TestGaussianBlur(t *testing.T) {
|
||||||
t.Fatalf("Invalid image size: %dx%d", size.Width, size.Height)
|
t.Fatalf("Invalid image size: %dx%d", size.Width, size.Height)
|
||||||
}
|
}
|
||||||
|
|
||||||
Write("fixtures/test_gaussian_out.jpg", newImg)
|
Write("testdata/test_gaussian_out.jpg", newImg)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestSharpen(t *testing.T) {
|
func TestSharpen(t *testing.T) {
|
||||||
options := Options{Width: 800, Height: 600, Sharpen: Sharpen{Radius: 1, X1: 1.5, Y2: 20, Y3: 50, M1: 1, M2: 2}}
|
options := Options{Width: 800, Height: 600, Sharpen: Sharpen{Radius: 1, X1: 1.5, Y2: 20, Y3: 50, M1: 1, M2: 2}}
|
||||||
buf, _ := Read("fixtures/test.jpg")
|
buf, _ := Read("testdata/test.jpg")
|
||||||
|
|
||||||
newImg, err := Resize(buf, options)
|
newImg, err := Resize(buf, options)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
@ -327,12 +327,12 @@ func TestSharpen(t *testing.T) {
|
||||||
t.Fatalf("Invalid image size: %dx%d", size.Width, size.Height)
|
t.Fatalf("Invalid image size: %dx%d", size.Width, size.Height)
|
||||||
}
|
}
|
||||||
|
|
||||||
Write("fixtures/test_sharpen_out.jpg", newImg)
|
Write("testdata/test_sharpen_out.jpg", newImg)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestExtractWithDefaultAxis(t *testing.T) {
|
func TestExtractWithDefaultAxis(t *testing.T) {
|
||||||
options := Options{AreaWidth: 200, AreaHeight: 200}
|
options := Options{AreaWidth: 200, AreaHeight: 200}
|
||||||
buf, _ := Read("fixtures/test.jpg")
|
buf, _ := Read("testdata/test.jpg")
|
||||||
|
|
||||||
newImg, err := Resize(buf, options)
|
newImg, err := Resize(buf, options)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
@ -344,12 +344,12 @@ func TestExtractWithDefaultAxis(t *testing.T) {
|
||||||
t.Fatalf("Invalid image size: %dx%d", size.Width, size.Height)
|
t.Fatalf("Invalid image size: %dx%d", size.Width, size.Height)
|
||||||
}
|
}
|
||||||
|
|
||||||
Write("fixtures/test_extract_defaults_out.jpg", newImg)
|
Write("testdata/test_extract_defaults_out.jpg", newImg)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestExtractCustomAxis(t *testing.T) {
|
func TestExtractCustomAxis(t *testing.T) {
|
||||||
options := Options{Top: 100, Left: 100, AreaWidth: 200, AreaHeight: 200}
|
options := Options{Top: 100, Left: 100, AreaWidth: 200, AreaHeight: 200}
|
||||||
buf, _ := Read("fixtures/test.jpg")
|
buf, _ := Read("testdata/test.jpg")
|
||||||
|
|
||||||
newImg, err := Resize(buf, options)
|
newImg, err := Resize(buf, options)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
@ -361,7 +361,7 @@ func TestExtractCustomAxis(t *testing.T) {
|
||||||
t.Fatalf("Invalid image size: %dx%d", size.Width, size.Height)
|
t.Fatalf("Invalid image size: %dx%d", size.Width, size.Height)
|
||||||
}
|
}
|
||||||
|
|
||||||
Write("fixtures/test_extract_custom_axis_out.jpg", newImg)
|
Write("testdata/test_extract_custom_axis_out.jpg", newImg)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestConvert(t *testing.T) {
|
func TestConvert(t *testing.T) {
|
||||||
|
|
@ -375,7 +375,7 @@ func TestConvert(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, file := range files {
|
for _, file := range files {
|
||||||
img, err := os.Open("fixtures/" + file)
|
img, err := os.Open("testdata/" + file)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
@ -410,7 +410,7 @@ func TestResizePngWithTransparency(t *testing.T) {
|
||||||
width, height := 300, 240
|
width, height := 300, 240
|
||||||
|
|
||||||
options := Options{Width: width, Height: height, Crop: true}
|
options := Options{Width: width, Height: height, Crop: true}
|
||||||
img, err := os.Open("fixtures/transparent.png")
|
img, err := os.Open("testdata/transparent.png")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
@ -435,7 +435,7 @@ func TestResizePngWithTransparency(t *testing.T) {
|
||||||
t.Fatal("Invalid image size")
|
t.Fatal("Invalid image size")
|
||||||
}
|
}
|
||||||
|
|
||||||
Write("fixtures/transparent_out.png", newImg)
|
Write("testdata/transparent_out.png", newImg)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestRotationAndFlip(t *testing.T) {
|
func TestRotationAndFlip(t *testing.T) {
|
||||||
|
|
@ -463,7 +463,7 @@ func TestRotationAndFlip(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, file := range files {
|
for _, file := range files {
|
||||||
img, err := os.Open(fmt.Sprintf("fixtures/exif/%s.jpg", file.Name))
|
img, err := os.Open(fmt.Sprintf("testdata/exif/%s.jpg", file.Name))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
@ -493,7 +493,7 @@ func TestRotationAndFlip(t *testing.T) {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
Write(fmt.Sprintf("fixtures/exif/%s_out.jpg", file.Name), newImg)
|
Write(fmt.Sprintf("testdata/exif/%s_out.jpg", file.Name), newImg)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -506,7 +506,7 @@ func TestIfBothSmartCropOptionsAreIdentical(t *testing.T) {
|
||||||
smartCropOptions := Options{Width: 100, Height: 100, Crop: true, SmartCrop: true}
|
smartCropOptions := Options{Width: 100, Height: 100, Crop: true, SmartCrop: true}
|
||||||
gravityOptions := Options{Width: 100, Height: 100, Crop: true, Gravity: GravitySmart}
|
gravityOptions := Options{Width: 100, Height: 100, Crop: true, Gravity: GravitySmart}
|
||||||
|
|
||||||
testImg, err := os.Open("fixtures/northern_cardinal_bird.jpg")
|
testImg, err := os.Open("testdata/northern_cardinal_bird.jpg")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
@ -543,7 +543,7 @@ func TestIfBothSmartCropOptionsAreIdentical(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func runBenchmarkResize(file string, o Options, b *testing.B) {
|
func runBenchmarkResize(file string, o Options, b *testing.B) {
|
||||||
buf, _ := Read(path.Join("fixtures", file))
|
buf, _ := Read(path.Join("testdata", file))
|
||||||
|
|
||||||
for n := 0; n < b.N; n++ {
|
for n := 0; n < b.N; n++ {
|
||||||
Resize(buf, o)
|
Resize(buf, o)
|
||||||
|
|
|
||||||
0
fixtures/corrupt.jpg → testdata/corrupt.jpg
vendored
|
Before Width: | Height: | Size: 46 KiB After Width: | Height: | Size: 46 KiB |
|
Before Width: | Height: | Size: 186 KiB After Width: | Height: | Size: 186 KiB |
|
Before Width: | Height: | Size: 198 KiB After Width: | Height: | Size: 198 KiB |
|
Before Width: | Height: | Size: 187 KiB After Width: | Height: | Size: 187 KiB |
|
Before Width: | Height: | Size: 199 KiB After Width: | Height: | Size: 199 KiB |
|
Before Width: | Height: | Size: 187 KiB After Width: | Height: | Size: 187 KiB |
|
Before Width: | Height: | Size: 200 KiB After Width: | Height: | Size: 200 KiB |
|
Before Width: | Height: | Size: 186 KiB After Width: | Height: | Size: 186 KiB |
|
Before Width: | Height: | Size: 199 KiB After Width: | Height: | Size: 199 KiB |
|
Before Width: | Height: | Size: 188 KiB After Width: | Height: | Size: 188 KiB |
|
Before Width: | Height: | Size: 205 KiB After Width: | Height: | Size: 205 KiB |
|
Before Width: | Height: | Size: 189 KiB After Width: | Height: | Size: 189 KiB |
|
Before Width: | Height: | Size: 205 KiB After Width: | Height: | Size: 205 KiB |
|
Before Width: | Height: | Size: 188 KiB After Width: | Height: | Size: 188 KiB |
|
Before Width: | Height: | Size: 204 KiB After Width: | Height: | Size: 204 KiB |
|
Before Width: | Height: | Size: 189 KiB After Width: | Height: | Size: 189 KiB |
|
Before Width: | Height: | Size: 205 KiB After Width: | Height: | Size: 205 KiB |
|
Before Width: | Height: | Size: 153 KiB After Width: | Height: | Size: 153 KiB |
|
Before Width: | Height: | Size: 165 KiB After Width: | Height: | Size: 165 KiB |
|
Before Width: | Height: | Size: 154 KiB After Width: | Height: | Size: 154 KiB |
|
Before Width: | Height: | Size: 166 KiB After Width: | Height: | Size: 166 KiB |
|
Before Width: | Height: | Size: 154 KiB After Width: | Height: | Size: 154 KiB |
|
Before Width: | Height: | Size: 166 KiB After Width: | Height: | Size: 166 KiB |
|
Before Width: | Height: | Size: 154 KiB After Width: | Height: | Size: 154 KiB |
|
Before Width: | Height: | Size: 165 KiB After Width: | Height: | Size: 165 KiB |
|
Before Width: | Height: | Size: 154 KiB After Width: | Height: | Size: 154 KiB |
|
Before Width: | Height: | Size: 174 KiB After Width: | Height: | Size: 174 KiB |
|
Before Width: | Height: | Size: 154 KiB After Width: | Height: | Size: 154 KiB |
|
Before Width: | Height: | Size: 174 KiB After Width: | Height: | Size: 174 KiB |
|
Before Width: | Height: | Size: 153 KiB After Width: | Height: | Size: 153 KiB |
|
Before Width: | Height: | Size: 173 KiB After Width: | Height: | Size: 173 KiB |
|
Before Width: | Height: | Size: 154 KiB After Width: | Height: | Size: 154 KiB |
|
Before Width: | Height: | Size: 174 KiB After Width: | Height: | Size: 174 KiB |
|
Before Width: | Height: | Size: 810 KiB After Width: | Height: | Size: 810 KiB |
0
fixtures/test.gif → testdata/test.gif
vendored
|
Before Width: | Height: | Size: 635 KiB After Width: | Height: | Size: 635 KiB |
0
fixtures/test.jp2 → testdata/test.jp2
vendored
0
fixtures/test.jpg → testdata/test.jpg
vendored
|
Before Width: | Height: | Size: 52 KiB After Width: | Height: | Size: 52 KiB |
0
fixtures/test.pdf → testdata/test.pdf
vendored
0
fixtures/test.png → testdata/test.png
vendored
|
Before Width: | Height: | Size: 604 KiB After Width: | Height: | Size: 604 KiB |
0
fixtures/test.svg → testdata/test.svg
vendored
|
Before Width: | Height: | Size: 67 KiB After Width: | Height: | Size: 67 KiB |
0
fixtures/test.webp → testdata/test.webp
vendored
|
Before Width: | Height: | Size: 30 KiB After Width: | Height: | Size: 30 KiB |
|
Before Width: | Height: | Size: 111 KiB After Width: | Height: | Size: 111 KiB |
|
Before Width: | Height: | Size: 142 KiB After Width: | Height: | Size: 142 KiB |
|
Before Width: | Height: | Size: 44 KiB After Width: | Height: | Size: 44 KiB |
|
Before Width: | Height: | Size: 64 KiB After Width: | Height: | Size: 64 KiB |
BIN
testdata/test_smart_crop.jpg
vendored
Normal file
|
After Width: | Height: | Size: 17 KiB |
|
Before Width: | Height: | Size: 134 KiB After Width: | Height: | Size: 134 KiB |
|
Before Width: | Height: | Size: 117 KiB After Width: | Height: | Size: 117 KiB |
|
Before Width: | Height: | Size: 57 KiB After Width: | Height: | Size: 57 KiB |
|
Before Width: | Height: | Size: 78 KiB After Width: | Height: | Size: 78 KiB |
|
Before Width: | Height: | Size: 2.9 MiB After Width: | Height: | Size: 2.9 MiB |
|
Before Width: | Height: | Size: 2 MiB After Width: | Height: | Size: 2 MiB |
|
|
@ -22,7 +22,7 @@ func TestDeterminateImageType(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, file := range files {
|
for _, file := range files {
|
||||||
img, _ := os.Open(path.Join("fixtures", file.name))
|
img, _ := os.Open(path.Join("testdata", file.name))
|
||||||
buf, _ := ioutil.ReadAll(img)
|
buf, _ := ioutil.ReadAll(img)
|
||||||
defer img.Close()
|
defer img.Close()
|
||||||
|
|
||||||
|
|
@ -49,7 +49,7 @@ func TestDeterminateImageTypeName(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, file := range files {
|
for _, file := range files {
|
||||||
img, _ := os.Open(path.Join("fixtures", file.name))
|
img, _ := os.Open(path.Join("testdata", file.name))
|
||||||
buf, _ := ioutil.ReadAll(img)
|
buf, _ := ioutil.ReadAll(img)
|
||||||
defer img.Close()
|
defer img.Close()
|
||||||
|
|
||||||
|
|
|
||||||
21
vendor/github.com/tj/go-debug/History.md
generated
vendored
Normal file
|
|
@ -0,0 +1,21 @@
|
||||||
|
|
||||||
|
v2.0.0 / 2014-10-22
|
||||||
|
==================
|
||||||
|
|
||||||
|
* remove live toggling feature. Closes #10
|
||||||
|
|
||||||
|
1.1.1 / 2014-07-07
|
||||||
|
==================
|
||||||
|
|
||||||
|
* fix: dispose socket. Closes #1
|
||||||
|
|
||||||
|
1.1.0 / 2014-06-29
|
||||||
|
==================
|
||||||
|
|
||||||
|
* add unix domain socket live debugging support
|
||||||
|
* add support for enabling/disabling at runtime
|
||||||
|
|
||||||
|
0.1.0 / 2014-05-24
|
||||||
|
==================
|
||||||
|
|
||||||
|
* add global and debug relative deltas
|
||||||
8
vendor/github.com/tj/go-debug/Makefile
generated
vendored
Normal file
|
|
@ -0,0 +1,8 @@
|
||||||
|
|
||||||
|
test:
|
||||||
|
@go test
|
||||||
|
|
||||||
|
bench:
|
||||||
|
@go test -bench=.
|
||||||
|
|
||||||
|
.PHONY: bench test
|
||||||
75
vendor/github.com/tj/go-debug/Readme.md
generated
vendored
Normal file
|
|
@ -0,0 +1,75 @@
|
||||||
|
|
||||||
|
# go-debug
|
||||||
|
|
||||||
|
Conditional debug logging for Go libraries.
|
||||||
|
|
||||||
|
View the [docs](http://godoc.org/github.com/tj/go-debug).
|
||||||
|
|
||||||
|
## Installation
|
||||||
|
|
||||||
|
```
|
||||||
|
$ go get github.com/tj/go-debug
|
||||||
|
```
|
||||||
|
|
||||||
|
## Example
|
||||||
|
|
||||||
|
```go
|
||||||
|
package main
|
||||||
|
|
||||||
|
import . "github.com/tj/go-debug"
|
||||||
|
import "time"
|
||||||
|
|
||||||
|
var debug = Debug("single")
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
for {
|
||||||
|
debug("sending mail")
|
||||||
|
debug("send email to %s", "tobi@segment.io")
|
||||||
|
debug("send email to %s", "loki@segment.io")
|
||||||
|
debug("send email to %s", "jane@segment.io")
|
||||||
|
time.Sleep(500 * time.Millisecond)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
If you run the program with the `DEBUG=*` environment variable you will see:
|
||||||
|
|
||||||
|
```
|
||||||
|
15:58:15.115 34us 33us single - sending mail
|
||||||
|
15:58:15.116 3us 3us single - send email to tobi@segment.io
|
||||||
|
15:58:15.116 1us 1us single - send email to loki@segment.io
|
||||||
|
15:58:15.116 1us 1us single - send email to jane@segment.io
|
||||||
|
15:58:15.620 504ms 504ms single - sending mail
|
||||||
|
15:58:15.620 6us 6us single - send email to tobi@segment.io
|
||||||
|
15:58:15.620 4us 4us single - send email to loki@segment.io
|
||||||
|
15:58:15.620 4us 4us single - send email to jane@segment.io
|
||||||
|
15:58:16.123 503ms 503ms single - sending mail
|
||||||
|
15:58:16.123 7us 7us single - send email to tobi@segment.io
|
||||||
|
15:58:16.123 4us 4us single - send email to loki@segment.io
|
||||||
|
15:58:16.123 4us 4us single - send email to jane@segment.io
|
||||||
|
15:58:16.625 501ms 501ms single - sending mail
|
||||||
|
15:58:16.625 4us 4us single - send email to tobi@segment.io
|
||||||
|
15:58:16.625 4us 4us single - send email to loki@segment.io
|
||||||
|
15:58:16.625 5us 5us single - send email to jane@segment.io
|
||||||
|
```
|
||||||
|
|
||||||
|
A timestamp and two deltas are displayed. The timestamp consists of hour, minute, second and microseconds. The left-most delta is relative to the previous debug call of any name, followed by a delta specific to that debug function. These may be useful to identify timing issues and potential bottlenecks.
|
||||||
|
|
||||||
|
## The DEBUG environment variable
|
||||||
|
|
||||||
|
Executables often support `--verbose` flags for conditional logging, however
|
||||||
|
libraries typically either require altering your code to enable logging,
|
||||||
|
or simply omit logging all together. go-debug allows conditional logging
|
||||||
|
to be enabled via the __DEBUG__ environment variable, where one or more
|
||||||
|
patterns may be specified.
|
||||||
|
|
||||||
|
For example suppose your application has several models and you want
|
||||||
|
to output logs for users only, you might use `DEBUG=models:user`. In contrast
|
||||||
|
if you wanted to see what all database activity was you might use `DEBUG=models:*`,
|
||||||
|
or if you're love being swamped with logs: `DEBUG=*`. You may also specify a list of names delimited by a comma, for example `DEBUG=mongo,redis:*`.
|
||||||
|
|
||||||
|
The name given _should_ be the package name, however you can use whatever you like.
|
||||||
|
|
||||||
|
# License
|
||||||
|
|
||||||
|
MIT
|
||||||
128
vendor/github.com/tj/go-debug/debug.go
generated
vendored
Normal file
|
|
@ -0,0 +1,128 @@
|
||||||
|
package debug
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"io"
|
||||||
|
"math/rand"
|
||||||
|
"os"
|
||||||
|
"regexp"
|
||||||
|
"strconv"
|
||||||
|
"strings"
|
||||||
|
"sync"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
writer io.Writer = os.Stderr
|
||||||
|
reg *regexp.Regexp
|
||||||
|
m sync.Mutex
|
||||||
|
enabled = false
|
||||||
|
)
|
||||||
|
|
||||||
|
// Debugger function.
|
||||||
|
type DebugFunction func(string, ...interface{})
|
||||||
|
|
||||||
|
// Terminal colors used at random.
|
||||||
|
var colors []string = []string{
|
||||||
|
"31",
|
||||||
|
"32",
|
||||||
|
"33",
|
||||||
|
"34",
|
||||||
|
"35",
|
||||||
|
"36",
|
||||||
|
}
|
||||||
|
|
||||||
|
// Initialize with DEBUG environment variable.
|
||||||
|
func init() {
|
||||||
|
env := os.Getenv("DEBUG")
|
||||||
|
|
||||||
|
if "" != env {
|
||||||
|
Enable(env)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetWriter replaces the default of os.Stderr with `w`.
|
||||||
|
func SetWriter(w io.Writer) {
|
||||||
|
m.Lock()
|
||||||
|
defer m.Unlock()
|
||||||
|
writer = w
|
||||||
|
}
|
||||||
|
|
||||||
|
// Disable all pattern matching. This function is thread-safe.
|
||||||
|
func Disable() {
|
||||||
|
m.Lock()
|
||||||
|
defer m.Unlock()
|
||||||
|
enabled = false
|
||||||
|
}
|
||||||
|
|
||||||
|
// Enable the given debug `pattern`. Patterns take a glob-like form,
|
||||||
|
// for example if you wanted to enable everything, just use "*", or
|
||||||
|
// if you had a library named mongodb you could use "mongodb:connection",
|
||||||
|
// or "mongodb:*". Multiple matches can be made with a comma, for
|
||||||
|
// example "mongo*,redis*".
|
||||||
|
//
|
||||||
|
// This function is thread-safe.
|
||||||
|
func Enable(pattern string) {
|
||||||
|
m.Lock()
|
||||||
|
defer m.Unlock()
|
||||||
|
pattern = regexp.QuoteMeta(pattern)
|
||||||
|
pattern = strings.Replace(pattern, "\\*", ".*?", -1)
|
||||||
|
pattern = strings.Replace(pattern, ",", "|", -1)
|
||||||
|
pattern = "^(" + pattern + ")$"
|
||||||
|
reg = regexp.MustCompile(pattern)
|
||||||
|
enabled = true
|
||||||
|
}
|
||||||
|
|
||||||
|
// Debug creates a debug function for `name` which you call
|
||||||
|
// with printf-style arguments in your application or library.
|
||||||
|
func Debug(name string) DebugFunction {
|
||||||
|
prevGlobal := time.Now()
|
||||||
|
color := colors[rand.Intn(len(colors))]
|
||||||
|
prev := time.Now()
|
||||||
|
|
||||||
|
return func(format string, args ...interface{}) {
|
||||||
|
if !enabled {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if !reg.MatchString(name) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
d := deltas(prevGlobal, prev, color)
|
||||||
|
fmt.Fprintf(writer, d+" \033["+color+"m"+name+"\033[0m - "+format+"\n", args...)
|
||||||
|
prevGlobal = time.Now()
|
||||||
|
prev = time.Now()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Return formatting for deltas.
|
||||||
|
func deltas(prevGlobal, prev time.Time, color string) string {
|
||||||
|
now := time.Now()
|
||||||
|
global := now.Sub(prevGlobal).Nanoseconds()
|
||||||
|
delta := now.Sub(prev).Nanoseconds()
|
||||||
|
ts := now.UTC().Format("15:04:05.000")
|
||||||
|
deltas := fmt.Sprintf("%s %-6s \033["+color+"m%-6s", ts, humanizeNano(global), humanizeNano(delta))
|
||||||
|
return deltas
|
||||||
|
}
|
||||||
|
|
||||||
|
// Humanize nanoseconds to a string.
|
||||||
|
func humanizeNano(n int64) string {
|
||||||
|
var suffix string
|
||||||
|
|
||||||
|
switch {
|
||||||
|
case n > 1e9:
|
||||||
|
n /= 1e9
|
||||||
|
suffix = "s"
|
||||||
|
case n > 1e6:
|
||||||
|
n /= 1e6
|
||||||
|
suffix = "ms"
|
||||||
|
case n > 1e3:
|
||||||
|
n /= 1e3
|
||||||
|
suffix = "us"
|
||||||
|
default:
|
||||||
|
suffix = "ns"
|
||||||
|
}
|
||||||
|
|
||||||
|
return strconv.Itoa(int(n)) + suffix
|
||||||
|
}
|
||||||
152
vendor/github.com/tj/go-debug/debug_test.go
generated
vendored
Normal file
|
|
@ -0,0 +1,152 @@
|
||||||
|
package debug
|
||||||
|
|
||||||
|
import "testing"
|
||||||
|
import "strings"
|
||||||
|
import "bytes"
|
||||||
|
import "time"
|
||||||
|
|
||||||
|
func assertContains(t *testing.T, str, substr string) {
|
||||||
|
if !strings.Contains(str, substr) {
|
||||||
|
t.Fatalf("expected %q to contain %q", str, substr)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func assertNotContains(t *testing.T, str, substr string) {
|
||||||
|
if strings.Contains(str, substr) {
|
||||||
|
t.Fatalf("expected %q to not contain %q", str, substr)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestDefault(t *testing.T) {
|
||||||
|
var b []byte
|
||||||
|
buf := bytes.NewBuffer(b)
|
||||||
|
SetWriter(buf)
|
||||||
|
|
||||||
|
debug := Debug("foo")
|
||||||
|
debug("something")
|
||||||
|
debug("here")
|
||||||
|
debug("whoop")
|
||||||
|
|
||||||
|
if buf.Len() != 0 {
|
||||||
|
t.Fatalf("buffer should be empty")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestEnable(t *testing.T) {
|
||||||
|
var b []byte
|
||||||
|
buf := bytes.NewBuffer(b)
|
||||||
|
SetWriter(buf)
|
||||||
|
|
||||||
|
Enable("foo")
|
||||||
|
|
||||||
|
debug := Debug("foo")
|
||||||
|
debug("something")
|
||||||
|
debug("here")
|
||||||
|
debug("whoop")
|
||||||
|
|
||||||
|
if buf.Len() == 0 {
|
||||||
|
t.Fatalf("buffer should have output")
|
||||||
|
}
|
||||||
|
|
||||||
|
str := string(buf.Bytes())
|
||||||
|
assertContains(t, str, "something")
|
||||||
|
assertContains(t, str, "here")
|
||||||
|
assertContains(t, str, "whoop")
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestMultipleOneEnabled(t *testing.T) {
|
||||||
|
var b []byte
|
||||||
|
buf := bytes.NewBuffer(b)
|
||||||
|
SetWriter(buf)
|
||||||
|
|
||||||
|
Enable("foo")
|
||||||
|
|
||||||
|
foo := Debug("foo")
|
||||||
|
foo("foo")
|
||||||
|
|
||||||
|
bar := Debug("bar")
|
||||||
|
bar("bar")
|
||||||
|
|
||||||
|
if buf.Len() == 0 {
|
||||||
|
t.Fatalf("buffer should have output")
|
||||||
|
}
|
||||||
|
|
||||||
|
str := string(buf.Bytes())
|
||||||
|
assertContains(t, str, "foo")
|
||||||
|
assertNotContains(t, str, "bar")
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestMultipleEnabled(t *testing.T) {
|
||||||
|
var b []byte
|
||||||
|
buf := bytes.NewBuffer(b)
|
||||||
|
SetWriter(buf)
|
||||||
|
|
||||||
|
Enable("foo,bar")
|
||||||
|
|
||||||
|
foo := Debug("foo")
|
||||||
|
foo("foo")
|
||||||
|
|
||||||
|
bar := Debug("bar")
|
||||||
|
bar("bar")
|
||||||
|
|
||||||
|
if buf.Len() == 0 {
|
||||||
|
t.Fatalf("buffer should have output")
|
||||||
|
}
|
||||||
|
|
||||||
|
str := string(buf.Bytes())
|
||||||
|
assertContains(t, str, "foo")
|
||||||
|
assertContains(t, str, "bar")
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestEnableDisable(t *testing.T) {
|
||||||
|
var b []byte
|
||||||
|
buf := bytes.NewBuffer(b)
|
||||||
|
SetWriter(buf)
|
||||||
|
|
||||||
|
Enable("foo,bar")
|
||||||
|
Disable()
|
||||||
|
|
||||||
|
foo := Debug("foo")
|
||||||
|
foo("foo")
|
||||||
|
|
||||||
|
bar := Debug("bar")
|
||||||
|
bar("bar")
|
||||||
|
|
||||||
|
if buf.Len() != 0 {
|
||||||
|
t.Fatalf("buffer should not have output")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func ExampleEnable() {
|
||||||
|
Enable("mongo:connection")
|
||||||
|
Enable("mongo:*")
|
||||||
|
Enable("foo,bar,baz")
|
||||||
|
Enable("*")
|
||||||
|
}
|
||||||
|
|
||||||
|
func ExampleDebug() {
|
||||||
|
var debug = Debug("single")
|
||||||
|
|
||||||
|
for {
|
||||||
|
debug("sending mail")
|
||||||
|
debug("send email to %s", "tobi@segment.io")
|
||||||
|
debug("send email to %s", "loki@segment.io")
|
||||||
|
debug("send email to %s", "jane@segment.io")
|
||||||
|
time.Sleep(500 * time.Millisecond)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func BenchmarkDisabled(b *testing.B) {
|
||||||
|
debug := Debug("something")
|
||||||
|
for i := 0; i < b.N; i++ {
|
||||||
|
debug("stuff")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func BenchmarkNonMatch(b *testing.B) {
|
||||||
|
debug := Debug("something")
|
||||||
|
Enable("nonmatch")
|
||||||
|
for i := 0; i < b.N; i++ {
|
||||||
|
debug("stuff")
|
||||||
|
}
|
||||||
|
}
|
||||||
25
vendor/github.com/tj/go-debug/example/multiple.go
generated
vendored
Normal file
|
|
@ -0,0 +1,25 @@
|
||||||
|
package main
|
||||||
|
|
||||||
|
import . "github.com/visionmedia/go-debug"
|
||||||
|
import "time"
|
||||||
|
|
||||||
|
var a = Debug("multiple:a")
|
||||||
|
var b = Debug("multiple:b")
|
||||||
|
var c = Debug("multiple:c")
|
||||||
|
|
||||||
|
func work(debug DebugFunction, delay time.Duration) {
|
||||||
|
for {
|
||||||
|
debug("doing stuff")
|
||||||
|
time.Sleep(delay)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
q := make(chan bool)
|
||||||
|
|
||||||
|
go work(a, 1000*time.Millisecond)
|
||||||
|
go work(b, 250*time.Millisecond)
|
||||||
|
go work(c, 100*time.Millisecond)
|
||||||
|
|
||||||
|
<-q
|
||||||
|
}
|
||||||
16
vendor/github.com/tj/go-debug/example/single.go
generated
vendored
Normal file
|
|
@ -0,0 +1,16 @@
|
||||||
|
package main
|
||||||
|
|
||||||
|
import . "github.com/visionmedia/go-debug"
|
||||||
|
import "time"
|
||||||
|
|
||||||
|
var debug = Debug("single")
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
for {
|
||||||
|
debug("sending mail")
|
||||||
|
debug("send email to %s", "tobi@segment.io")
|
||||||
|
debug("send email to %s", "loki@segment.io")
|
||||||
|
debug("send email to %s", "jane@segment.io")
|
||||||
|
time.Sleep(500 * time.Millisecond)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -163,7 +163,7 @@ func TestVipsMemory(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func readImage(file string) []byte {
|
func readImage(file string) []byte {
|
||||||
img, _ := os.Open(path.Join("fixtures", file))
|
img, _ := os.Open(path.Join("testdata", file))
|
||||||
buf, _ := ioutil.ReadAll(img)
|
buf, _ := ioutil.ReadAll(img)
|
||||||
defer img.Close()
|
defer img.Close()
|
||||||
return buf
|
return buf
|
||||||
|
|
|
||||||