Browse Source

Add pipeline test image dimension assertions

feature/update-route-registration
Roman Zipp 3 years ago
committed by Fabian Vowie
parent
commit
dba9e2aeb4
No known key found for this signature in database GPG Key ID: C27317C33B27C410
  1. 31
      pipelines/pipeline_test.go
  2. BIN
      tests/files/800x500.jpg

31
pipelines/pipeline_test.go

@ -2,6 +2,7 @@ package pipelines
import ( import (
"github.com/geplauder/lithium/storage" "github.com/geplauder/lithium/storage"
"image"
"os" "os"
"path/filepath" "path/filepath"
"testing" "testing"
@ -121,14 +122,26 @@ func TestResizeImage(t *testing.T) {
storageProvider := storage.GetFileSystemStorageProvider("test", "..") storageProvider := storage.GetFileSystemStorageProvider("test", "..")
// copy test file to storage bucket
_, err := storageProvider.StoreExisting(Bucket, "source.jpg", filepath.Join(wd, "../tests/files/900x900.jpg")) _, err := storageProvider.StoreExisting(Bucket, "source.jpg", filepath.Join(wd, "../tests/files/900x900.jpg"))
assert.Nil(t, err, "Test file should be readable") assert.Nil(t, err, "Test file should be readable")
assert.FileExists(t, storageProvider.GetPath(Bucket, "source.jpg")) assert.FileExists(t, storageProvider.GetPath(Bucket, "source.jpg"))
// run pipeline steps
dest, err := pipe.Run("source.jpg", Bucket, storageProvider) dest, err := pipe.Run("source.jpg", Bucket, storageProvider)
assert.Nil(t, err) assert.Nil(t, err)
assert.FileExists(t, storageProvider.GetPath(Bucket, dest)) assert.FileExists(t, storageProvider.GetPath(Bucket, dest))
// read image config
file, err := storageProvider.OpenFile(Bucket, dest)
assert.Nil(t, err)
imgConf, _, err := image.DecodeConfig(file)
assert.Nil(t, err)
assert.Equal(t, 1280, imgConf.Width)
assert.Equal(t, 720, imgConf.Height)
// clean up // clean up
os.Remove(storageProvider.GetPath(Bucket, "source.jpg")) os.Remove(storageProvider.GetPath(Bucket, "source.jpg"))
os.Remove(storageProvider.GetPath(Bucket, dest)) os.Remove(storageProvider.GetPath(Bucket, dest))
@ -152,20 +165,32 @@ func TestRotateImage(t *testing.T) {
}` }`
const Bucket string = "pipeline_test_03" const Bucket string = "pipeline_test_03"
t.Run("Image rotating is successful", func(t *testing.T) {
t.Run("Image rotation step is successful", func(t *testing.T) {
wd, _ := os.Getwd() wd, _ := os.Getwd()
pipe := DeserializePipelines([][]byte{[]byte(Payload)})[0] pipe := DeserializePipelines([][]byte{[]byte(Payload)})[0]
storageProvider := storage.GetFileSystemStorageProvider("test", "..") storageProvider := storage.GetFileSystemStorageProvider("test", "..")
_, err := storageProvider.StoreExisting(Bucket, "source.jpg", filepath.Join(wd, "../tests/files/900x900.jpg"))
// copy test file to storage bucket
_, err := storageProvider.StoreExisting(Bucket, "source.jpg", filepath.Join(wd, "../tests/files/800x500.jpg"))
assert.Nil(t, err, "Test file should be readable") assert.Nil(t, err, "Test file should be readable")
assert.FileExists(t, storageProvider.GetPath(Bucket, "source.jpg")) assert.FileExists(t, storageProvider.GetPath(Bucket, "source.jpg"))
// run pipeline steps
dest, err := pipe.Run("source.jpg", Bucket, storageProvider) dest, err := pipe.Run("source.jpg", Bucket, storageProvider)
assert.Nil(t, err) assert.Nil(t, err)
assert.FileExists(t, storageProvider.GetPath(Bucket, dest)) assert.FileExists(t, storageProvider.GetPath(Bucket, dest))
// read image config
file, err := storageProvider.OpenFile(Bucket, dest)
assert.Nil(t, err)
imgConf, _, err := image.DecodeConfig(file)
assert.Nil(t, err)
assert.Equal(t, 500, imgConf.Width)
assert.Equal(t, 800, imgConf.Height)
// clean up // clean up
os.Remove(storageProvider.GetPath(Bucket, "source.jpg")) os.Remove(storageProvider.GetPath(Bucket, "source.jpg"))
os.Remove(storageProvider.GetPath(Bucket, dest)) os.Remove(storageProvider.GetPath(Bucket, dest))
@ -202,10 +227,12 @@ func TestEncodeImageWithJpegQuality(t *testing.T) {
storageProvider := storage.GetFileSystemStorageProvider("test", "..") storageProvider := storage.GetFileSystemStorageProvider("test", "..")
// copy test file to storage bucket
_, err := storageProvider.StoreExisting(Bucket, "source.jpg", filepath.Join(wd, "../tests/files/900x900.jpg")) _, err := storageProvider.StoreExisting(Bucket, "source.jpg", filepath.Join(wd, "../tests/files/900x900.jpg"))
assert.Nil(t, err, "Test file should be readable") assert.Nil(t, err, "Test file should be readable")
assert.FileExists(t, storageProvider.GetPath(Bucket, "source.jpg")) assert.FileExists(t, storageProvider.GetPath(Bucket, "source.jpg"))
// run pipeline steps
dest, err := pipe.Run("source.jpg", Bucket, storageProvider) dest, err := pipe.Run("source.jpg", Bucket, storageProvider)
assert.Nil(t, err) assert.Nil(t, err)
assert.FileExists(t, storageProvider.GetPath(Bucket, dest)) assert.FileExists(t, storageProvider.GetPath(Bucket, dest))

BIN
tests/files/800x500.jpg

After

Width: 800  |  Height: 500  |  Size: 66 KiB

Loading…
Cancel
Save