From 7be1c12cd0fc3af55e83efe731cdb751c7234fae Mon Sep 17 00:00:00 2001 From: Roman Zipp Date: Thu, 20 Jan 2022 18:01:44 +0100 Subject: [PATCH] Refactor pipeline tests --- pipelines/pipeline_test.go | 158 ++++++++++++++++++------------------- 1 file changed, 76 insertions(+), 82 deletions(-) diff --git a/pipelines/pipeline_test.go b/pipelines/pipeline_test.go index feb9343..4619445 100644 --- a/pipelines/pipeline_test.go +++ b/pipelines/pipeline_test.go @@ -12,50 +12,48 @@ import ( // 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) { + 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)}) assert.Equal(t, 1, len(values), "Output should contain one element") assert.Equal(t, "example pipeline", values[0].GetName()) 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) { + 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)}) assert.Equal(t, 1, len(values), "Output should contain one element") @@ -66,16 +64,16 @@ func TestVideoPipelineDeserialization(t *testing.T) { // 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() 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, 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() 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, 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() pipe := DeserializePipelines([][]byte{[]byte(Payload)})[0] @@ -199,7 +193,8 @@ func TestRotateImage(t *testing.T) { // output options -func TestEncodeImageWithJpegQuality(t *testing.T) { +func TestEncoding(t *testing.T) { + const Bucket string = "pipeline_test_04" const Payload string = `{ "name": "example pipeline", "type": 1, @@ -219,7 +214,6 @@ func TestEncodeImageWithJpegQuality(t *testing.T) { "quality": 50 } }` - const Bucket string = "pipeline_test_02" t.Run("Image encoding with jpeg quality is successful", func(t *testing.T) { wd, _ := os.Getwd()