|
@ -190,6 +190,88 @@ func TestExecuteSteps(t *testing.T) { |
|
|
os.Remove(storageProvider.GetPath(Bucket, dest)) |
|
|
os.Remove(storageProvider.GetPath(Bucket, dest)) |
|
|
}) |
|
|
}) |
|
|
|
|
|
|
|
|
|
|
|
t.Run("Image flip step is successful", func(t *testing.T) { |
|
|
|
|
|
const Bucket string = "pipeline_test_06" |
|
|
|
|
|
const Payload string = `{ |
|
|
|
|
|
"name": "example pipeline", |
|
|
|
|
|
"type": 1, |
|
|
|
|
|
"removeMetadata": false, |
|
|
|
|
|
"steps": [ |
|
|
|
|
|
{ |
|
|
|
|
|
"name": "flip image", |
|
|
|
|
|
"type": 2, |
|
|
|
|
|
"options": { |
|
|
|
|
|
"direction": "h" |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
] |
|
|
|
|
|
}` |
|
|
|
|
|
|
|
|
|
|
|
wd, _ := os.Getwd() |
|
|
|
|
|
pipe := DeserializePipelines([][]byte{[]byte(Payload)})[0] |
|
|
|
|
|
|
|
|
|
|
|
storageProvider := storage.GetFileSystemStorageProvider("test", "..") |
|
|
|
|
|
|
|
|
|
|
|
// 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, 800, imgConf.Width) |
|
|
|
|
|
assert.Equal(t, 500, imgConf.Height) |
|
|
|
|
|
|
|
|
|
|
|
// clean up
|
|
|
|
|
|
os.Remove(storageProvider.GetPath(Bucket, "source.jpg")) |
|
|
|
|
|
os.Remove(storageProvider.GetPath(Bucket, dest)) |
|
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
|
|
t.Run("Image flip step direction validation is successful", func(t *testing.T) { |
|
|
|
|
|
const Bucket string = "pipeline_test_06" |
|
|
|
|
|
const Payload string = `{ |
|
|
|
|
|
"name": "example pipeline", |
|
|
|
|
|
"type": 1, |
|
|
|
|
|
"removeMetadata": false, |
|
|
|
|
|
"steps": [ |
|
|
|
|
|
{ |
|
|
|
|
|
"name": "flip image", |
|
|
|
|
|
"type": 2, |
|
|
|
|
|
"options": { |
|
|
|
|
|
"direction": "f" |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
] |
|
|
|
|
|
}` |
|
|
|
|
|
|
|
|
|
|
|
wd, _ := os.Getwd() |
|
|
|
|
|
pipe := DeserializePipelines([][]byte{[]byte(Payload)})[0] |
|
|
|
|
|
|
|
|
|
|
|
storageProvider := storage.GetFileSystemStorageProvider("test", "..") |
|
|
|
|
|
|
|
|
|
|
|
// 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
|
|
|
|
|
|
_, err = pipe.Run("source.jpg", Bucket, storageProvider) |
|
|
|
|
|
assert.EqualError(t, err, "invalid flip direction: f") |
|
|
|
|
|
|
|
|
|
|
|
// clean up
|
|
|
|
|
|
os.Remove(storageProvider.GetPath(Bucket, "source.jpg")) |
|
|
|
|
|
}) |
|
|
|
|
|
|
|
|
t.Run("Image grayscale step is successful", func(t *testing.T) { |
|
|
t.Run("Image grayscale step is successful", func(t *testing.T) { |
|
|
const Bucket string = "pipeline_test_05" |
|
|
const Bucket string = "pipeline_test_05" |
|
|
const Payload string = `{ |
|
|
const Payload string = `{ |
|
@ -199,7 +281,7 @@ func TestExecuteSteps(t *testing.T) { |
|
|
"steps": [ |
|
|
"steps": [ |
|
|
{ |
|
|
{ |
|
|
"name": "grayscale", |
|
|
"name": "grayscale", |
|
|
"type": 2 |
|
|
|
|
|
|
|
|
"type": 3 |
|
|
} |
|
|
} |
|
|
] |
|
|
] |
|
|
}` |
|
|
}` |
|
|