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.

65 lines
1.5 KiB

  1. package main
  2. import (
  3. "net/http"
  4. "net/http/httptest"
  5. "testing"
  6. "github.com/gorilla/mux"
  7. "github.com/stretchr/testify/assert"
  8. )
  9. func TestIndexRoute(t *testing.T) {
  10. t.Run("Index route returns valid response", func(t *testing.T) {
  11. request := httptest.NewRequest(http.MethodGet, "/", nil)
  12. responseRecorder := httptest.NewRecorder()
  13. IndexHandler(responseRecorder, request)
  14. assert.Equal(t, responseRecorder.Code, 200, "Response code should be 200")
  15. assert.NotNil(t, responseRecorder.Body, "Response should contain body")
  16. })
  17. }
  18. func TestEndpointRoute(t *testing.T) {
  19. // TODO: Use mock/fake for dummy pipeline data
  20. givenEndpoint := Pipeline{
  21. Name: "example pipeline",
  22. Slug: "example",
  23. Type: 0,
  24. RemoveMetadata: false,
  25. Steps: []Step{
  26. {
  27. Name: "resize image",
  28. Type: 0,
  29. },
  30. {
  31. Name: "compress image",
  32. Type: 1,
  33. },
  34. },
  35. }
  36. t.Run("Registered pipelines are valid routes", func(t *testing.T) {
  37. router := mux.NewRouter()
  38. RegisterPipelineRoutes(router, []IPipeline{givenEndpoint})
  39. request, _ := http.NewRequest("GET", "/"+givenEndpoint.Slug, nil)
  40. responseRecorder := httptest.NewRecorder()
  41. router.ServeHTTP(responseRecorder, request)
  42. assert.Equal(t, responseRecorder.Code, 200)
  43. })
  44. t.Run("Unregistered pipelines return 404", func(t *testing.T) {
  45. router := mux.NewRouter()
  46. request, _ := http.NewRequest("GET", "/"+givenEndpoint.Slug, nil)
  47. responseRecorder := httptest.NewRecorder()
  48. router.ServeHTTP(responseRecorder, request)
  49. assert.Equal(t, responseRecorder.Code, 404)
  50. })
  51. }