Browse Source
Add deserialization for pipelines
feature/add-pipeline-loading
Fabian Vowie
3 years ago
No known key found for this signature in database
GPG Key ID: C27317C33B27C410
2 changed files with
45 additions and
0 deletions
-
pipeline.go
-
pipeline_test.go
|
|
@ -1,5 +1,7 @@ |
|
|
|
package main |
|
|
|
|
|
|
|
import "encoding/json" |
|
|
|
|
|
|
|
type PipelineType int |
|
|
|
type PipelineStepType int |
|
|
|
|
|
|
@ -26,3 +28,14 @@ type Step struct { |
|
|
|
Type PipelineStepType |
|
|
|
} |
|
|
|
|
|
|
|
func DeserializePipelines(pipelines []string) []Pipeline { |
|
|
|
values := make([]Pipeline, len(pipelines)) |
|
|
|
|
|
|
|
for index, pipeline := range pipelines { |
|
|
|
var deserializedObject Pipeline |
|
|
|
json.Unmarshal([]byte(pipeline), &deserializedObject) |
|
|
|
values[index] = deserializedObject |
|
|
|
} |
|
|
|
|
|
|
|
return values |
|
|
|
} |
|
|
@ -0,0 +1,32 @@ |
|
|
|
package main |
|
|
|
|
|
|
|
import ( |
|
|
|
"testing" |
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert" |
|
|
|
) |
|
|
|
|
|
|
|
const ValidPayload 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("Pipelines deserialization is successful", func(t *testing.T) { |
|
|
|
values := DeserializePipelines([]string{ValidPayload}) |
|
|
|
|
|
|
|
assert.Equal(t, 1, len(values), "Output should contain one element") |
|
|
|
assert.Equal(t, "example pipeline", values[0].Name) |
|
|
|
}) |
|
|
|
} |