package pipelines import ( "testing" "github.com/stretchr/testify/assert" ) func TestTranslateStep(t *testing.T) { const Payload string = `{ "name": "example pipeline", "type": 1, "removeMetadata": false, "steps": [ { "name": "resize image", "type": 0, "options": {} } ] }` 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()) translated, err := steps[0].GetExecutable() assert.Equal(t, nil, err) assert.IsType(t, ResizeImageStep{}, translated) }) } func TestInvalidStepType(t *testing.T) { const Payload string = `{ "name": "example pipeline", "type": 1, "removeMetadata": false, "steps": [ { "name": "resize image", "type": 99999, "options": {} } ] }` 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, StepType(99999), steps[0].GetType()) translated, err := steps[0].GetExecutable() assert.EqualError(t, err, "invalid type") assert.Nil(t, translated) }) }