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.

80 lines
1.5 KiB

  1. package pipelines
  2. import (
  3. "github.com/stretchr/testify/assert"
  4. "testing"
  5. )
  6. func TestDeserializeOptionsResizeImage(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. "options": {
  16. "width": 1280,
  17. "height": 720,
  18. "upscale": false
  19. }
  20. }
  21. ]
  22. }`
  23. t.Run("Image pipeline deserialization is successful", func(t *testing.T) {
  24. values := DeserializePipelines([][]byte{[]byte(Payload)})
  25. _, err := values[0].GetSteps()[0].Translate()
  26. assert.Equal(t, nil, err)
  27. })
  28. }
  29. func TestDeserializeOptionsCompressImage(t *testing.T) {
  30. const Payload string = `{
  31. "name": "example pipeline",
  32. "type": 0,
  33. "removeMetadata": false,
  34. "steps": [
  35. {
  36. "name": "compress image",
  37. "type": 1,
  38. "options": {
  39. "quality": 80
  40. }
  41. }
  42. ]
  43. }`
  44. t.Run("Image pipeline deserialization is successful", func(t *testing.T) {
  45. values := DeserializePipelines([][]byte{[]byte(Payload)})
  46. _, err := values[0].GetSteps()[0].Translate()
  47. assert.Equal(t, nil, err)
  48. })
  49. }
  50. func TestDeserializeMissingOptions(t *testing.T) {
  51. const Payload string = `{
  52. "name": "example pipeline",
  53. "type": 0,
  54. "removeMetadata": false,
  55. "steps": [
  56. {
  57. "name": "resize image",
  58. "type": 0
  59. }
  60. ]
  61. }`
  62. t.Run("Image pipeline deserialization is successful", func(t *testing.T) {
  63. values := DeserializePipelines([][]byte{[]byte(Payload)})
  64. _, err := values[0].GetSteps()[0].Translate()
  65. assert.EqualError(t, err, "unexpected end of JSON input")
  66. })
  67. }