Micro-service for file storage and processing written in Go
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

64 lines
1.5 KiB

  1. package pipelines
  2. import (
  3. "github.com/stretchr/testify/assert"
  4. "testing"
  5. )
  6. func TestTranslateStep(t *testing.T) {
  7. const Payload string = `{
  8. "name": "example pipeline",
  9. "type": 1,
  10. "removeMetadata": false,
  11. "steps": [
  12. {
  13. "name": "resize image",
  14. "type": 0,
  15. "options": {}
  16. }
  17. ]
  18. }`
  19. t.Run("step type deserialization is successful", func(t *testing.T) {
  20. values := DeserializePipelines([][]byte{[]byte(Payload)})
  21. pipeline := values[0]
  22. steps := pipeline.GetSteps()
  23. assert.Equal(t, 1, len(steps), "Output steps should contain one element")
  24. assert.Equal(t, "resize image", steps[0].GetName())
  25. assert.Equal(t, TypeResizeImageStep, steps[0].GetType())
  26. translated, err := steps[0].Translate()
  27. assert.Equal(t, nil, err)
  28. assert.IsType(t, ResizeImageStep{}, translated)
  29. })
  30. }
  31. func TestInvalidStepType(t *testing.T) {
  32. const Payload string = `{
  33. "name": "example pipeline",
  34. "type": 1,
  35. "removeMetadata": false,
  36. "steps": [
  37. {
  38. "name": "resize image",
  39. "type": 99999,
  40. "options": {}
  41. }
  42. ]
  43. }`
  44. t.Run("Video pipelines deserialization is successful", func(t *testing.T) {
  45. values := DeserializePipelines([][]byte{[]byte(Payload)})
  46. pipeline := values[0]
  47. steps := pipeline.GetSteps()
  48. assert.Equal(t, 1, len(steps), "Output steps should contain one element")
  49. assert.Equal(t, "resize image", steps[0].GetName())
  50. assert.Equal(t, StepType(99999), steps[0].GetType())
  51. translated, err := steps[0].Translate()
  52. assert.EqualError(t, err, "invalid type")
  53. assert.Nil(t, translated)
  54. })
  55. }