Skip to content

Commit

Permalink
Refactoring: remove not found endpoints
Browse files Browse the repository at this point in the history
  • Loading branch information
aopoltorzhicky committed Jun 9, 2024
1 parent e516bcb commit 65b07a8
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 9 deletions.
7 changes: 3 additions & 4 deletions cmd/api/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -455,14 +455,13 @@ func initHandlers(ctx context.Context, e *echo.Echo, cfg Config, db postgres.Sto
return key == os.Getenv("API_AUTH_KEY"), nil
},
})
auth.Use(keyMiddleware)

rollupAuthHandler := handler.NewRollupAuthHandler(db.Rollup, db.Address, db.Namespace, db.Transactable)
rollup := auth.Group("/rollup")
{
rollup.POST("/new", rollupAuthHandler.Create)
rollup.PATCH("/:id", rollupAuthHandler.Update)
rollup.DELETE("/:id", rollupAuthHandler.Delete)
rollup.POST("/new", rollupAuthHandler.Create, keyMiddleware)
rollup.PATCH("/:id", rollupAuthHandler.Update, keyMiddleware)
rollup.DELETE("/:id", rollupAuthHandler.Delete, keyMiddleware)
}
}

Expand Down
22 changes: 17 additions & 5 deletions cmd/api/routes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package main
import (
"context"
"fmt"
"strings"
"testing"

"github.com/celenium-io/celestia-indexer/internal/storage/postgres"
Expand All @@ -21,7 +22,6 @@ func TestRoutes(t *testing.T) {
"/v1/rollup/:id/stats/:name/:timeframe GET": {},
"/v1/stats/histogram/:table/:function/:timeframe GET": {},
"/v1/gas/estimate_for_pfb GET": {},
"/v1/auth/rollup/* echo_route_not_found": {},
"/v1/tx/count GET": {},
"/v1/namespace/:id/:version/rollups GET": {},
"/v1/namespace_by_hash/:hash/:height GET": {},
Expand All @@ -33,7 +33,6 @@ func TestRoutes(t *testing.T) {
"/v1/search GET": {},
"/v1/stats/staking/series/:id/:name/:timeframe GET": {},
"/v1/rollup/:id GET": {},
"/v1/auth/rollup echo_route_not_found": {},
"/v1/auth/rollup/new POST": {},
"/v1/address/:hash GET": {},
"/v1/address/:hash/txs GET": {},
Expand All @@ -42,7 +41,6 @@ func TestRoutes(t *testing.T) {
"/v1/tx GET": {},
"/v1/namespace/:id/:version/blobs GET": {},
"/v1/rollup/:id/namespaces GET": {},
"/v1/auth/* echo_route_not_found": {},
"/v1/block GET": {},
"/v1/tx/:hash/namespace GET": {},
"/v1/tx/:hash/blobs/count GET": {},
Expand All @@ -57,7 +55,6 @@ func TestRoutes(t *testing.T) {
"/v1/namespace/active GET": {},
"/v1/namespace_by_hash/:hash GET": {},
"/v1/vesting/:id/periods GET": {},
"/v1/auth echo_route_not_found": {},
"/v1/constants GET": {},
"/v1/address GET": {},
"/v1/block/:height/blobs GET": {},
Expand Down Expand Up @@ -132,6 +129,21 @@ func TestRoutes(t *testing.T) {
for _, route := range e.Routes() {
key := fmt.Sprintf("%s %s", route.Path, route.Method)
_, ok := expectedRoutes[key]
require.True(t, ok, key)
require.True(t, ok, "routes in expected", key)
}

for key := range expectedRoutes {
parts := strings.Split(key, " ")
method := parts[1]
path := parts[0]

var found bool
for _, route := range e.Routes() {
if route.Path == path && route.Method == method {
found = true
break
}
}
require.True(t, found, "expected in routes", key)
}
}

0 comments on commit 65b07a8

Please sign in to comment.