|
|
@ -5,25 +5,25 @@ import ( |
|
|
|
"testing" |
|
|
|
) |
|
|
|
|
|
|
|
const ValidImagePayload string = `{ |
|
|
|
"name": "example pipeline", |
|
|
|
"type": 0, |
|
|
|
"removeMetadata": false, |
|
|
|
"steps": [ |
|
|
|
{ |
|
|
|
"name": "resize image", |
|
|
|
"type": 0 |
|
|
|
}, |
|
|
|
{ |
|
|
|
"name": "compress image", |
|
|
|
"type": 1 |
|
|
|
} |
|
|
|
] |
|
|
|
}` |
|
|
|
|
|
|
|
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 |
|
|
|
} |
|
|
|
] |
|
|
|
}` |
|
|
|
|
|
|
|
t.Run("Image pipeline deserialization is successful", func(t *testing.T) { |
|
|
|
values := DeserializePipelines([][]byte{[]byte(ValidImagePayload)}) |
|
|
|
values := DeserializePipelines([][]byte{[]byte(Payload)}) |
|
|
|
|
|
|
|
assert.Equal(t, 1, len(values), "Output should contain one element") |
|
|
|
assert.Equal(t, "example pipeline", values[0].GetName()) |
|
|
@ -31,28 +31,76 @@ func TestImagePipelineDeserialization(t *testing.T) { |
|
|
|
}) |
|
|
|
} |
|
|
|
|
|
|
|
const ValidVideoPayload string = `{ |
|
|
|
"name": "example pipeline", |
|
|
|
"type": 1, |
|
|
|
"removeMetadata": false, |
|
|
|
"steps": [ |
|
|
|
{ |
|
|
|
"name": "resize image", |
|
|
|
"type": 0 |
|
|
|
}, |
|
|
|
{ |
|
|
|
"name": "compress image", |
|
|
|
"type": 1 |
|
|
|
} |
|
|
|
] |
|
|
|
}` |
|
|
|
|
|
|
|
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) { |
|
|
|
values := DeserializePipelines([][]byte{[]byte(ValidVideoPayload)}) |
|
|
|
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, Video, values[0].GetType()) |
|
|
|
}) |
|
|
|
} |
|
|
|
|
|
|
|
func TestTranslateStep(t *testing.T) { |
|
|
|
const Payload string = `{ |
|
|
|
"name": "example pipeline", |
|
|
|
"type": 1, |
|
|
|
"removeMetadata": false, |
|
|
|
"steps": [ |
|
|
|
{ |
|
|
|
"name": "resize image", |
|
|
|
"type": 0 |
|
|
|
} |
|
|
|
] |
|
|
|
}` |
|
|
|
|
|
|
|
t.Run("step type deserialization is successful", func(t *testing.T) { |
|
|
|
values := DeserializePipelines([][]byte{[]byte(Payload)}) |
|
|
|
pipeline := values[0] |
|
|
|
steps := pipeline.GetSteps() |
|
|
|
|
|
|
|
assert.Equal(t, 1, len(steps), "Output steps should contain one element") |
|
|
|
assert.Equal(t, "resize image", steps[0].GetName()) |
|
|
|
assert.Equal(t, TypeResizeImageStep, steps[0].GetType()) |
|
|
|
}) |
|
|
|
} |
|
|
|
|
|
|
|
func TestInvalidStepType(t *testing.T) { |
|
|
|
const Payload string = `{ |
|
|
|
"name": "example pipeline", |
|
|
|
"type": 1, |
|
|
|
"removeMetadata": false, |
|
|
|
"steps": [ |
|
|
|
{ |
|
|
|
"name": "resize image", |
|
|
|
"type": 0 |
|
|
|
} |
|
|
|
] |
|
|
|
}` |
|
|
|
|
|
|
|
t.Run("Video pipelines deserialization is successful", func(t *testing.T) { |
|
|
|
values := DeserializePipelines([][]byte{[]byte(Payload)}) |
|
|
|
pipeline := values[0] |
|
|
|
steps := pipeline.GetSteps() |
|
|
|
|
|
|
|
assert.Equal(t, 1, len(steps), "Output steps should contain one element") |
|
|
|
assert.Equal(t, "resize image", steps[0].GetName()) |
|
|
|
assert.Equal(t, TypeResizeImageStep, steps[0].GetType()) |
|
|
|
}) |
|
|
|
} |