Browse Source

Refactor pipeline tests

Roman Zipp 3 years ago
committed by Fabian Vowie
parent
commit
337e8af0e2
No known key found for this signature in database GPG Key ID: C27317C33B27C410
  1. 158
      pipelines/pipeline_test.go

158
pipelines/pipeline_test.go

@ -12,50 +12,48 @@ import (
// pipeline deserialization // pipeline deserialization
func TestImagePipelineDeserialization(t *testing.T) {
const Payload string = `{
"name": "example pipeline",
"type": 0,
"removeMetadata": false,
"steps": [
{
"name": "resize image",
"type": 0
},
{
"name": "compress image",
"type": 1
}
]
}`
func TestPipelineDeserialization(t *testing.T) {
t.Run("Image pipeline deserialization is successful", func(t *testing.T) { t.Run("Image pipeline deserialization is successful", func(t *testing.T) {
const Payload string = `{
"name": "example pipeline",
"type": 0,
"removeMetadata": false,
"steps": [
{
"name": "resize image",
"type": 0
},
{
"name": "compress image",
"type": 1
}
]
}`
values := DeserializePipelines([][]byte{[]byte(Payload)}) values := DeserializePipelines([][]byte{[]byte(Payload)})
assert.Equal(t, 1, len(values), "Output should contain one element") assert.Equal(t, 1, len(values), "Output should contain one element")
assert.Equal(t, "example pipeline", values[0].GetName()) assert.Equal(t, "example pipeline", values[0].GetName())
assert.Equal(t, Image, values[0].GetType()) assert.Equal(t, Image, values[0].GetType())
}) })
}
func TestVideoPipelineDeserialization(t *testing.T) {
const Payload string = `{
"name": "example pipeline",
"type": 1,
"removeMetadata": false,
"steps": [
{
"name": "resize image",
"type": 0
},
{
"name": "compress image",
"type": 1
}
]
}`
t.Run("Video pipelines deserialization is successful", func(t *testing.T) { t.Run("Video pipelines deserialization is successful", func(t *testing.T) {
const Payload string = `{
"name": "example pipeline",
"type": 1,
"removeMetadata": false,
"steps": [
{
"name": "resize image",
"type": 0
},
{
"name": "compress image",
"type": 1
}
]
}`
values := DeserializePipelines([][]byte{[]byte(Payload)}) values := DeserializePipelines([][]byte{[]byte(Payload)})
assert.Equal(t, 1, len(values), "Output should contain one element") assert.Equal(t, 1, len(values), "Output should contain one element")
@ -66,16 +64,16 @@ func TestVideoPipelineDeserialization(t *testing.T) {
// image pipeline steps // image pipeline steps
func TestNoSteps(t *testing.T) {
const Payload string = `{
"name": "example pipeline",
"type": 1,
"removeMetadata": false,
"steps": []
}`
const Bucket string = "pipeline_test_04"
func TestExecuteSteps(t *testing.T) {
t.Run("Pipeline executes with no steps", func(t *testing.T) {
const Bucket string = "pipeline_test_01"
const Payload string = `{
"name": "example pipeline",
"type": 1,
"removeMetadata": false,
"steps": []
}`
t.Run("Pipeline execution is successful", func(t *testing.T) {
wd, _ := os.Getwd() wd, _ := os.Getwd()
pipe := DeserializePipelines([][]byte{[]byte(Payload)})[0] pipe := DeserializePipelines([][]byte{[]byte(Payload)})[0]
@ -95,28 +93,26 @@ func TestNoSteps(t *testing.T) {
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))
}) })
}
func TestResizeImage(t *testing.T) {
const Payload string = `{
"name": "example pipeline",
"type": 1,
"removeMetadata": false,
"steps": [
{
"name": "resize image",
"type": 0,
"options": {
"width": 1280,
"height": 720,
"upscale": false
t.Run("Image resizing is successful", func(t *testing.T) {
const Bucket string = "pipeline_test_02"
const Payload string = `{
"name": "example pipeline",
"type": 1,
"removeMetadata": false,
"steps": [
{
"name": "resize image",
"type": 0,
"options": {
"width": 1280,
"height": 720,
"upscale": false
}
} }
}
]
}`
const Bucket string = "pipeline_test_01"
]
}`
t.Run("Image resizing is successful", func(t *testing.T) {
wd, _ := os.Getwd() wd, _ := os.Getwd()
pipe := DeserializePipelines([][]byte{[]byte(Payload)})[0] pipe := DeserializePipelines([][]byte{[]byte(Payload)})[0]
@ -146,26 +142,24 @@ func TestResizeImage(t *testing.T) {
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))
}) })
}
func TestRotateImage(t *testing.T) {
const Payload string = `{
"name": "example pipeline",
"type": 1,
"removeMetadata": false,
"steps": [
{
"name": "rotate image",
"type": 1,
"options": {
"angle": 90.0
t.Run("Image rotation step is successful", func(t *testing.T) {
const Bucket string = "pipeline_test_03"
const Payload string = `{
"name": "example pipeline",
"type": 1,
"removeMetadata": false,
"steps": [
{
"name": "rotate image",
"type": 1,
"options": {
"angle": 90.0
}
} }
}
]
}`
const Bucket string = "pipeline_test_03"
]
}`
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]
@ -199,7 +193,8 @@ func TestRotateImage(t *testing.T) {
// output options // output options
func TestEncodeImageWithJpegQuality(t *testing.T) {
func TestEncoding(t *testing.T) {
const Bucket string = "pipeline_test_04"
const Payload string = `{ const Payload string = `{
"name": "example pipeline", "name": "example pipeline",
"type": 1, "type": 1,
@ -219,7 +214,6 @@ func TestEncodeImageWithJpegQuality(t *testing.T) {
"quality": 50 "quality": 50
} }
}` }`
const Bucket string = "pipeline_test_02"
t.Run("Image encoding with jpeg quality is successful", func(t *testing.T) { t.Run("Image encoding with jpeg quality is successful", func(t *testing.T) {
wd, _ := os.Getwd() wd, _ := os.Getwd()

Loading…
Cancel
Save