|
|
@ -2,10 +2,12 @@ package main |
|
|
|
|
|
|
|
import ( |
|
|
|
"encoding/json" |
|
|
|
"fmt" |
|
|
|
"net/http" |
|
|
|
"net/http/httptest" |
|
|
|
"testing" |
|
|
|
|
|
|
|
"github.com/bxcodec/faker/v3" |
|
|
|
"github.com/gorilla/mux" |
|
|
|
"github.com/stretchr/testify/assert" |
|
|
|
) |
|
|
@ -23,42 +25,30 @@ func TestIndexRoute(t *testing.T) { |
|
|
|
} |
|
|
|
|
|
|
|
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, |
|
|
|
}, |
|
|
|
}, |
|
|
|
data := Pipeline{} |
|
|
|
err := faker.FakeData(&data) |
|
|
|
if err != nil { |
|
|
|
fmt.Println(err) |
|
|
|
} |
|
|
|
|
|
|
|
t.Run("Registered pipelines are valid routes", func(t *testing.T) { |
|
|
|
router := mux.NewRouter() |
|
|
|
RegisterPipelineRoutes(router, []IPipeline{givenEndpoint}) |
|
|
|
RegisterPipelineRoutes(router, []IPipeline{data}) |
|
|
|
|
|
|
|
request, _ := http.NewRequest("GET", "/"+givenEndpoint.Slug, nil) |
|
|
|
request, _ := http.NewRequest("GET", "/"+data.Slug, nil) |
|
|
|
responseRecorder := httptest.NewRecorder() |
|
|
|
|
|
|
|
router.ServeHTTP(responseRecorder, request) |
|
|
|
|
|
|
|
assert.Equal(t, responseRecorder.Code, 200) |
|
|
|
body, _ := json.Marshal(givenEndpoint) |
|
|
|
body, _ := json.Marshal(data) |
|
|
|
assert.JSONEq(t, string(body), responseRecorder.Body.String()) |
|
|
|
}) |
|
|
|
|
|
|
|
t.Run("Unregistered pipelines return 404", func(t *testing.T) { |
|
|
|
router := mux.NewRouter() |
|
|
|
|
|
|
|
request, _ := http.NewRequest("GET", "/"+givenEndpoint.Slug, nil) |
|
|
|
request, _ := http.NewRequest("GET", "/"+data.Slug, nil) |
|
|
|
responseRecorder := httptest.NewRecorder() |
|
|
|
|
|
|
|
router.ServeHTTP(responseRecorder, request) |
|
|
|