Add new function to generate files that can be resized. Add states for upcoming queue changes.

This commit is contained in:
Justin Hawkins 2021-11-01 20:59:01 +10:30
parent 71c70ce965
commit 6fa6c34ccb
2 changed files with 39 additions and 0 deletions

View File

@ -23,6 +23,16 @@ import (
"golang.org/x/image/font/inconsolata" "golang.org/x/image/font/inconsolata"
) )
type State int
const (
Pending = iota
Queued
Uploading
Complete
Failed
)
type HTTPClient interface { type HTTPClient interface {
Do(req *http.Request) (*http.Response, error) Do(req *http.Request) (*http.Response, error)
} }

View File

@ -2,7 +2,11 @@ package upload
import ( import (
"bytes" "bytes"
"image"
"image/color"
"image/png"
"io/ioutil" "io/ioutil"
"math/rand"
"net/http" "net/http"
"os" "os"
"testing" "testing"
@ -70,3 +74,28 @@ func TestTooBigUpload(t *testing.T) {
t.Error("upload should have been marked failed") 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)
}