diff --git a/pipelines/pipeline_test.go b/pipelines/pipeline_test.go index 1619122..feb9343 100644 --- a/pipelines/pipeline_test.go +++ b/pipelines/pipeline_test.go @@ -2,6 +2,7 @@ package pipelines import ( "github.com/geplauder/lithium/storage" + "image" "os" "path/filepath" "testing" @@ -121,14 +122,26 @@ func TestResizeImage(t *testing.T) { storageProvider := storage.GetFileSystemStorageProvider("test", "..") + // copy test file to storage bucket _, err := storageProvider.StoreExisting(Bucket, "source.jpg", filepath.Join(wd, "../tests/files/900x900.jpg")) assert.Nil(t, err, "Test file should be readable") assert.FileExists(t, storageProvider.GetPath(Bucket, "source.jpg")) + // run pipeline steps dest, err := pipe.Run("source.jpg", Bucket, storageProvider) assert.Nil(t, err) 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 os.Remove(storageProvider.GetPath(Bucket, "source.jpg")) os.Remove(storageProvider.GetPath(Bucket, dest)) @@ -152,20 +165,32 @@ func TestRotateImage(t *testing.T) { }` 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() pipe := DeserializePipelines([][]byte{[]byte(Payload)})[0] 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.FileExists(t, storageProvider.GetPath(Bucket, "source.jpg")) + // run pipeline steps dest, err := pipe.Run("source.jpg", Bucket, storageProvider) assert.Nil(t, err) 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 os.Remove(storageProvider.GetPath(Bucket, "source.jpg")) os.Remove(storageProvider.GetPath(Bucket, dest)) @@ -202,10 +227,12 @@ func TestEncodeImageWithJpegQuality(t *testing.T) { storageProvider := storage.GetFileSystemStorageProvider("test", "..") + // copy test file to storage bucket _, err := storageProvider.StoreExisting(Bucket, "source.jpg", filepath.Join(wd, "../tests/files/900x900.jpg")) assert.Nil(t, err, "Test file should be readable") assert.FileExists(t, storageProvider.GetPath(Bucket, "source.jpg")) + // run pipeline steps dest, err := pipe.Run("source.jpg", Bucket, storageProvider) assert.Nil(t, err) assert.FileExists(t, storageProvider.GetPath(Bucket, dest)) diff --git a/tests/files/800x500.jpg b/tests/files/800x500.jpg new file mode 100644 index 0000000..365935d Binary files /dev/null and b/tests/files/800x500.jpg differ