From 6fa6c34ccbdebe067a2fb7a75b8765b0016c3680 Mon Sep 17 00:00:00 2001 From: Justin Hawkins Date: Mon, 1 Nov 2021 20:59:01 +1030 Subject: [PATCH] Add new function to generate files that can be resized. Add states for upcoming queue changes. --- upload/upload.go | 10 ++++++++++ upload/upload_test.go | 29 +++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+) diff --git a/upload/upload.go b/upload/upload.go index eafca1c..5c9cd8d 100644 --- a/upload/upload.go +++ b/upload/upload.go @@ -23,6 +23,16 @@ import ( "golang.org/x/image/font/inconsolata" ) +type State int + +const ( + Pending = iota + Queued + Uploading + Complete + Failed +) + type HTTPClient interface { Do(req *http.Request) (*http.Response, error) } diff --git a/upload/upload_test.go b/upload/upload_test.go index 46c9fc4..3996ff3 100644 --- a/upload/upload_test.go +++ b/upload/upload_test.go @@ -2,7 +2,11 @@ package upload import ( "bytes" + "image" + "image/color" + "image/png" "io/ioutil" + "math/rand" "net/http" "os" "testing" @@ -70,3 +74,28 @@ func TestTooBigUpload(t *testing.T) { t.Error("upload should have been marked failed") } } + +func tempImageGt8Mb() { + // about 12Mb + width := 2000 + height := 2000 + + upLeft := image.Point{0, 0} + lowRight := image.Point{width, height} + + img := image.NewRGBA(image.Rectangle{upLeft, lowRight}) + + // Colors are defined by Red, Green, Blue, Alpha uint8 values. + + // Set color for each pixel. + for x := 0; x < width; x++ { + for y := 0; y < height; y++ { + color := color.RGBA{uint8(rand.Int31n(256)), uint8(rand.Int31n(256)), uint8(rand.Int31n(256)), 0xff} + img.Set(x, y, color) + } + } + + // Encode as PNG. + f, _ := os.Create("image.png") + png.Encode(f, img) +}