registry/api/v2: checkTestRouter(): use sub-tests, t.Parallel()

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
Sebastiaan van Stijn 2023-04-30 15:38:30 +02:00
parent 2444c3282d
commit f4acd98865
No known key found for this signature in database
GPG key ID: 76698F39D527CE8C

View file

@ -29,6 +29,7 @@ type routeTestCase struct {
//
// This may go away as the application structure comes together.
func TestRouter(t *testing.T) {
t.Parallel()
tests := []routeTestCase{
{
RouteName: RouteNameBase,
@ -177,6 +178,7 @@ func TestRouter(t *testing.T) {
}
func TestRouterWithPathTraversals(t *testing.T) {
t.Parallel()
tests := []routeTestCase{
{
RouteName: RouteNameBlobUploadChunk,
@ -198,6 +200,7 @@ func TestRouterWithPathTraversals(t *testing.T) {
}
func TestRouterWithBadCharacters(t *testing.T) {
t.Parallel()
if testing.Short() {
tests := []routeTestCase{
{
@ -253,7 +256,11 @@ func checkTestRouter(t *testing.T, tests []routeTestCase, prefix string, deeplyE
server := httptest.NewServer(router)
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
route := router.GetRoute(tc.RouteName)
if route == nil {
@ -285,7 +292,7 @@ func checkTestRouter(t *testing.T, tests []routeTestCase, prefix string, deeplyE
if tc.StatusCode != http.StatusOK {
resp.Body.Close()
// We don't care about json response.
continue
return
}
dec := json.NewDecoder(resp.Body)
@ -314,6 +321,7 @@ func checkTestRouter(t *testing.T, tests []routeTestCase, prefix string, deeplyE
}
resp.Body.Close()
})
}
}