|
@ -5,6 +5,7 @@ import ( |
|
|
"net/http/httptest" |
|
|
"net/http/httptest" |
|
|
"testing" |
|
|
"testing" |
|
|
|
|
|
|
|
|
|
|
|
"github.com/gorilla/mux" |
|
|
"github.com/stretchr/testify/assert" |
|
|
"github.com/stretchr/testify/assert" |
|
|
) |
|
|
) |
|
|
|
|
|
|
|
@ -19,3 +20,46 @@ func TestIndexRoute(t *testing.T) { |
|
|
assert.NotNil(t, responseRecorder.Body, "Response should contain body") |
|
|
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) |
|
|
|
|
|
}) |
|
|
|
|
|
} |