package main import ( "net/http" "net/http/httptest" "testing" "github.com/gorilla/mux" "github.com/stretchr/testify/assert" ) func TestIndexRoute(t *testing.T) { t.Run("Index route returns valid response", func(t *testing.T) { request := httptest.NewRequest(http.MethodGet, "/", nil) responseRecorder := httptest.NewRecorder() IndexHandler(responseRecorder, request) assert.Equal(t, responseRecorder.Code, 200, "Response code should be 200") assert.NotNil(t, responseRecorder.Body, "Response should contain body") }) } func TestEndpointRoute(t *testing.T) { // TODO: Use mock/fake for dummy pipeline data givenEndpoint := Pipeline{ Name: "example pipeline", Slug: "example", Type: 0, RemoveMetadata: false, Steps: []Step{ { Name: "resize image", Type: 0, }, { Name: "compress image", Type: 1, }, }, } t.Run("Registered pipelines are valid routes", func(t *testing.T) { router := mux.NewRouter() RegisterPipelineRoutes(router, []IPipeline{givenEndpoint}) request, _ := http.NewRequest("GET", "/"+givenEndpoint.Slug, nil) responseRecorder := httptest.NewRecorder() router.ServeHTTP(responseRecorder, request) assert.Equal(t, responseRecorder.Code, 200) }) t.Run("Unregistered pipelines return 404", func(t *testing.T) { router := mux.NewRouter() request, _ := http.NewRequest("GET", "/"+givenEndpoint.Slug, nil) responseRecorder := httptest.NewRecorder() router.ServeHTTP(responseRecorder, request) assert.Equal(t, responseRecorder.Code, 404) }) }