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.

106 lines
2.4 KiB

  1. package main
  2. import (
  3. "github.com/stretchr/testify/assert"
  4. "testing"
  5. )
  6. func TestImagePipelineDeserialization(t *testing.T) {
  7. const Payload string = `{
  8. "name": "example pipeline",
  9. "type": 0,
  10. "removeMetadata": false,
  11. "steps": [
  12. {
  13. "name": "resize image",
  14. "type": 0
  15. },
  16. {
  17. "name": "compress image",
  18. "type": 1
  19. }
  20. ]
  21. }`
  22. t.Run("Image pipeline deserialization is successful", func(t *testing.T) {
  23. values := DeserializePipelines([][]byte{[]byte(Payload)})
  24. assert.Equal(t, 1, len(values), "Output should contain one element")
  25. assert.Equal(t, "example pipeline", values[0].GetName())
  26. assert.Equal(t, Image, values[0].GetType())
  27. })
  28. }
  29. func TestVideoPipelineDeserialization(t *testing.T) {
  30. const Payload string = `{
  31. "name": "example pipeline",
  32. "type": 1,
  33. "removeMetadata": false,
  34. "steps": [
  35. {
  36. "name": "resize image",
  37. "type": 0
  38. },
  39. {
  40. "name": "compress image",
  41. "type": 1
  42. }
  43. ]
  44. }`
  45. t.Run("Video pipelines deserialization is successful", func(t *testing.T) {
  46. values := DeserializePipelines([][]byte{[]byte(Payload)})
  47. assert.Equal(t, 1, len(values), "Output should contain one element")
  48. assert.Equal(t, "example pipeline", values[0].GetName())
  49. assert.Equal(t, Video, values[0].GetType())
  50. })
  51. }
  52. func TestTranslateStep(t *testing.T) {
  53. const Payload string = `{
  54. "name": "example pipeline",
  55. "type": 1,
  56. "removeMetadata": false,
  57. "steps": [
  58. {
  59. "name": "resize image",
  60. "type": 0
  61. }
  62. ]
  63. }`
  64. t.Run("step type deserialization is successful", func(t *testing.T) {
  65. values := DeserializePipelines([][]byte{[]byte(Payload)})
  66. pipeline := values[0]
  67. steps := pipeline.GetSteps()
  68. assert.Equal(t, 1, len(steps), "Output steps should contain one element")
  69. assert.Equal(t, "resize image", steps[0].GetName())
  70. assert.Equal(t, TypeResizeImageStep, steps[0].GetType())
  71. })
  72. }
  73. func TestInvalidStepType(t *testing.T) {
  74. const Payload string = `{
  75. "name": "example pipeline",
  76. "type": 1,
  77. "removeMetadata": false,
  78. "steps": [
  79. {
  80. "name": "resize image",
  81. "type": 0
  82. }
  83. ]
  84. }`
  85. t.Run("Video pipelines deserialization is successful", func(t *testing.T) {
  86. values := DeserializePipelines([][]byte{[]byte(Payload)})
  87. pipeline := values[0]
  88. steps := pipeline.GetSteps()
  89. assert.Equal(t, 1, len(steps), "Output steps should contain one element")
  90. assert.Equal(t, "resize image", steps[0].GetName())
  91. assert.Equal(t, TypeResizeImageStep, steps[0].GetType())
  92. })
  93. }