registry/api/v2: checkTestRouter(): use sub-tests, t.Parallel()
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
parent
2444c3282d
commit
f4acd98865
1 changed files with 62 additions and 54 deletions
|
@ -29,6 +29,7 @@ type routeTestCase struct {
|
||||||
//
|
//
|
||||||
// This may go away as the application structure comes together.
|
// This may go away as the application structure comes together.
|
||||||
func TestRouter(t *testing.T) {
|
func TestRouter(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
tests := []routeTestCase{
|
tests := []routeTestCase{
|
||||||
{
|
{
|
||||||
RouteName: RouteNameBase,
|
RouteName: RouteNameBase,
|
||||||
|
@ -177,6 +178,7 @@ func TestRouter(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestRouterWithPathTraversals(t *testing.T) {
|
func TestRouterWithPathTraversals(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
tests := []routeTestCase{
|
tests := []routeTestCase{
|
||||||
{
|
{
|
||||||
RouteName: RouteNameBlobUploadChunk,
|
RouteName: RouteNameBlobUploadChunk,
|
||||||
|
@ -198,6 +200,7 @@ func TestRouterWithPathTraversals(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestRouterWithBadCharacters(t *testing.T) {
|
func TestRouterWithBadCharacters(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
if testing.Short() {
|
if testing.Short() {
|
||||||
tests := []routeTestCase{
|
tests := []routeTestCase{
|
||||||
{
|
{
|
||||||
|
@ -253,7 +256,11 @@ func checkTestRouter(t *testing.T, tests []routeTestCase, prefix string, deeplyE
|
||||||
server := httptest.NewServer(router)
|
server := httptest.NewServer(router)
|
||||||
|
|
||||||
for _, tc := range tests {
|
for _, tc := range tests {
|
||||||
tc.RequestURI = strings.TrimSuffix(prefix, "/") + tc.RequestURI
|
tc := tc
|
||||||
|
requestURI := strings.TrimSuffix(prefix, "/") + tc.RequestURI
|
||||||
|
t.Run("("+tc.RouteName+")"+requestURI, func(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
|
tc.RequestURI = requestURI
|
||||||
// Register the endpoint
|
// Register the endpoint
|
||||||
route := router.GetRoute(tc.RouteName)
|
route := router.GetRoute(tc.RouteName)
|
||||||
if route == nil {
|
if route == nil {
|
||||||
|
@ -285,7 +292,7 @@ func checkTestRouter(t *testing.T, tests []routeTestCase, prefix string, deeplyE
|
||||||
if tc.StatusCode != http.StatusOK {
|
if tc.StatusCode != http.StatusOK {
|
||||||
resp.Body.Close()
|
resp.Body.Close()
|
||||||
// We don't care about json response.
|
// We don't care about json response.
|
||||||
continue
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
dec := json.NewDecoder(resp.Body)
|
dec := json.NewDecoder(resp.Body)
|
||||||
|
@ -314,6 +321,7 @@ func checkTestRouter(t *testing.T, tests []routeTestCase, prefix string, deeplyE
|
||||||
}
|
}
|
||||||
|
|
||||||
resp.Body.Close()
|
resp.Body.Close()
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue