|
@ -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)) |
|
|