|
@ -1,10 +1,14 @@ |
|
|
package main |
|
|
package main |
|
|
|
|
|
|
|
|
import ( |
|
|
import ( |
|
|
|
|
|
"encoding/json" |
|
|
|
|
|
"fmt" |
|
|
"net/http" |
|
|
"net/http" |
|
|
"net/http/httptest" |
|
|
"net/http/httptest" |
|
|
"testing" |
|
|
"testing" |
|
|
|
|
|
|
|
|
|
|
|
"github.com/bxcodec/faker/v3" |
|
|
|
|
|
"github.com/gorilla/mux" |
|
|
"github.com/stretchr/testify/assert" |
|
|
"github.com/stretchr/testify/assert" |
|
|
) |
|
|
) |
|
|
|
|
|
|
|
@ -19,3 +23,36 @@ 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) { |
|
|
|
|
|
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{data}) |
|
|
|
|
|
|
|
|
|
|
|
request, _ := http.NewRequest("GET", "/"+data.Slug, nil) |
|
|
|
|
|
responseRecorder := httptest.NewRecorder() |
|
|
|
|
|
|
|
|
|
|
|
router.ServeHTTP(responseRecorder, request) |
|
|
|
|
|
|
|
|
|
|
|
assert.Equal(t, responseRecorder.Code, 200) |
|
|
|
|
|
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", "/"+data.Slug, nil) |
|
|
|
|
|
responseRecorder := httptest.NewRecorder() |
|
|
|
|
|
|
|
|
|
|
|
router.ServeHTTP(responseRecorder, request) |
|
|
|
|
|
|
|
|
|
|
|
assert.Equal(t, responseRecorder.Code, 404) |
|
|
|
|
|
}) |
|
|
|
|
|
} |