Skip to content

Commit

Permalink
fix: GET /_info breaking change (#666)
Browse files Browse the repository at this point in the history
  • Loading branch information
gfyrag committed Jan 27, 2025
1 parent b0c5ea5 commit 95c8317
Show file tree
Hide file tree
Showing 29 changed files with 32 additions and 27 deletions.
1 change: 1 addition & 0 deletions internal/api/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ func NewRouter(
v2Router := v2.NewRouter(
systemController,
authenticator,
version,
debug,
v2.WithTracer(routerOptions.tracer),
v2.WithMiddlewares(commonMiddlewares...),
Expand Down
2 changes: 1 addition & 1 deletion internal/api/v1/controllers_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ type LedgerStorage struct {
Ledgers []string `json:"ledgers"`
}

func getInfo(systemController system.Controller, version string) func(w http.ResponseWriter, r *http.Request) {
func GetInfo(systemController system.Controller, version string) func(w http.ResponseWriter, r *http.Request) {
return func(w http.ResponseWriter, r *http.Request) {

ledgerNames := make([]string, 0)
Expand Down
2 changes: 1 addition & 1 deletion internal/api/v1/routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func NewRouter(

router := chi.NewMux()

router.Get("/_info", getInfo(systemController, version))
router.Get("/_info", GetInfo(systemController, version))

router.Group(func(router chi.Router) {
router.Use(routerOptions.middlewares...)
Expand Down
2 changes: 1 addition & 1 deletion internal/api/v2/controllers_accounts_add_metadata_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ func TestAccountsAddMetadata(t *testing.T) {
Return(&ledger.Log{}, nil)
}

router := NewRouter(systemController, auth.NewNoAuth(), os.Getenv("DEBUG") == "true")
router := NewRouter(systemController, auth.NewNoAuth(), "develop", os.Getenv("DEBUG") == "true")

req := httptest.NewRequest(http.MethodPost, "/", api.Buffer(t, testCase.body))
// httptest.NewRequest check for invalid urls while we want to test invalid urls
Expand Down
2 changes: 1 addition & 1 deletion internal/api/v2/controllers_accounts_count_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ func TestAccountsCount(t *testing.T) {
Return(10, testCase.returnErr)
}

router := NewRouter(systemController, auth.NewNoAuth(), os.Getenv("DEBUG") == "true")
router := NewRouter(systemController, auth.NewNoAuth(), "develop", os.Getenv("DEBUG") == "true")

req := httptest.NewRequest(http.MethodHead, "/xxx/accounts?pit="+before.Format(time.RFC3339Nano), bytes.NewBufferString(testCase.body))
rec := httptest.NewRecorder()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ func TestAccountsDeleteMetadata(t *testing.T) {
Return(&ledger.Log{}, tc.returnErr)
}

router := NewRouter(systemController, auth.NewNoAuth(), os.Getenv("DEBUG") == "true")
router := NewRouter(systemController, auth.NewNoAuth(), "develop", os.Getenv("DEBUG") == "true")

req := httptest.NewRequest(http.MethodDelete, "/", nil)
req.URL.Path = "/ledger0/accounts/" + tc.account + "/metadata/foo"
Expand Down
2 changes: 1 addition & 1 deletion internal/api/v2/controllers_accounts_list_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ func TestAccountsList(t *testing.T) {
Return(&expectedCursor, tc.returnErr)
}

router := NewRouter(systemController, auth.NewNoAuth(), os.Getenv("DEBUG") == "true")
router := NewRouter(systemController, auth.NewNoAuth(), "develop", os.Getenv("DEBUG") == "true")

req := httptest.NewRequest(http.MethodGet, "/xxx/accounts?pit="+before.Format(time.RFC3339Nano), bytes.NewBufferString(tc.body))
rec := httptest.NewRecorder()
Expand Down
2 changes: 1 addition & 1 deletion internal/api/v2/controllers_accounts_read_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ func TestAccountsRead(t *testing.T) {
Return(&ledger.Account{}, tc.returnErr)
}

router := NewRouter(systemController, auth.NewNoAuth(), os.Getenv("DEBUG") == "true")
router := NewRouter(systemController, auth.NewNoAuth(), "develop", os.Getenv("DEBUG") == "true")

req := httptest.NewRequest(http.MethodGet, "/", bytes.NewBufferString(tc.body))
req.URL.Path = "/xxx/accounts/" + tc.account
Expand Down
2 changes: 1 addition & 1 deletion internal/api/v2/controllers_balances_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ func TestBalancesAggregates(t *testing.T) {
GetAggregatedBalances(gomock.Any(), testCase.expectQuery).
Return(expectedBalances, nil)

router := NewRouter(systemController, auth.NewNoAuth(), os.Getenv("DEBUG") == "true")
router := NewRouter(systemController, auth.NewNoAuth(), "develop", os.Getenv("DEBUG") == "true")

req := httptest.NewRequest(http.MethodGet, "/xxx/aggregate/balances?pit="+now.Format(time.RFC3339Nano), bytes.NewBufferString(testCase.body))
rec := httptest.NewRecorder()
Expand Down
2 changes: 1 addition & 1 deletion internal/api/v2/controllers_bulk_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -485,7 +485,7 @@ func TestBulk(t *testing.T) {
systemController, ledgerController := newTestingSystemController(t, true)
testCase.expectations(ledgerController)

router := NewRouter(systemController, auth.NewNoAuth(), os.Getenv("DEBUG") == "true")
router := NewRouter(systemController, auth.NewNoAuth(), "develop", os.Getenv("DEBUG") == "true")

req := httptest.NewRequest(http.MethodPost, "/xxx/_bulk", bytes.NewBufferString(testCase.body))
req.Header = testCase.headers
Expand Down
2 changes: 1 addition & 1 deletion internal/api/v2/controllers_ledgers_create_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ func TestLedgersCreate(t *testing.T) {
t.Parallel()

systemController, _ := newTestingSystemController(t, false)
router := NewRouter(systemController, auth.NewNoAuth(), os.Getenv("DEBUG") == "true")
router := NewRouter(systemController, auth.NewNoAuth(), "develop", os.Getenv("DEBUG") == "true")

name := uuid.NewString()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func TestLedgersDeleteMetadata(t *testing.T) {
Return(tc.returnErr)
}

router := NewRouter(systemController, auth.NewNoAuth(), os.Getenv("DEBUG") == "true")
router := NewRouter(systemController, auth.NewNoAuth(), "develop", os.Getenv("DEBUG") == "true")

req := httptest.NewRequest(http.MethodDelete, "/"+name+"/metadata/foo", nil)
req = req.WithContext(ctx)
Expand Down
2 changes: 1 addition & 1 deletion internal/api/v2/controllers_ledgers_info_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func TestLedgersInfo(t *testing.T) {
t.Parallel()

systemController, ledgerController := newTestingSystemController(t, false)
router := NewRouter(systemController, auth.NewNoAuth(), os.Getenv("DEBUG") == "true")
router := NewRouter(systemController, auth.NewNoAuth(), "develop", os.Getenv("DEBUG") == "true")

migrationInfo := []migrations.Info{
{
Expand Down
2 changes: 1 addition & 1 deletion internal/api/v2/controllers_ledgers_list_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ func TestListLedgers(t *testing.T) {
}, tc.returnErr)
}

router := NewRouter(systemController, auth.NewNoAuth(), os.Getenv("DEBUG") == "true")
router := NewRouter(systemController, auth.NewNoAuth(), "develop", os.Getenv("DEBUG") == "true")

req := httptest.NewRequest(http.MethodGet, "/", nil)
req = req.WithContext(ctx)
Expand Down
2 changes: 1 addition & 1 deletion internal/api/v2/controllers_ledgers_read_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ func TestLedgersRead(t *testing.T) {
t.Parallel()

systemController, _ := newTestingSystemController(t, false)
router := NewRouter(systemController, auth.NewNoAuth(), os.Getenv("DEBUG") == "true")
router := NewRouter(systemController, auth.NewNoAuth(), "develop", os.Getenv("DEBUG") == "true")

name := uuid.NewString()
now := time.Now()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func TestLedgersUpdateMetadata(t *testing.T) {
UpdateLedgerMetadata(gomock.Any(), name, metadata).
Return(nil)

router := NewRouter(systemController, auth.NewNoAuth(), os.Getenv("DEBUG") == "true")
router := NewRouter(systemController, auth.NewNoAuth(), "develop", os.Getenv("DEBUG") == "true")

req := httptest.NewRequest(http.MethodPut, "/"+name+"/metadata", api.Buffer(t, metadata))
req = req.WithContext(ctx)
Expand Down
2 changes: 1 addition & 1 deletion internal/api/v2/controllers_logs_export_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func TestLogsExport(t *testing.T) {
return nil
})

router := NewRouter(systemController, auth.NewNoAuth(), os.Getenv("DEBUG") == "true")
router := NewRouter(systemController, auth.NewNoAuth(), "develop", os.Getenv("DEBUG") == "true")

req := httptest.NewRequest(http.MethodPost, "/xxx/logs/export", nil)
rec := httptest.NewRecorder()
Expand Down
2 changes: 1 addition & 1 deletion internal/api/v2/controllers_logs_import_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ func TestLogsImport(t *testing.T) {
}
})

router := NewRouter(systemController, auth.NewNoAuth(), os.Getenv("DEBUG") == "true")
router := NewRouter(systemController, auth.NewNoAuth(), "develop", os.Getenv("DEBUG") == "true")

buf := bytes.NewBuffer(nil)
require.NoError(t, json.NewEncoder(buf).Encode(log))
Expand Down
2 changes: 1 addition & 1 deletion internal/api/v2/controllers_logs_list_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ func TestGetLogs(t *testing.T) {
Return(&expectedCursor, testCase.returnErr)
}

router := NewRouter(systemController, auth.NewNoAuth(), os.Getenv("DEBUG") == "true")
router := NewRouter(systemController, auth.NewNoAuth(), "develop", os.Getenv("DEBUG") == "true")

req := httptest.NewRequest(http.MethodGet, "/xxx/logs", bytes.NewBufferString(testCase.body))
rec := httptest.NewRecorder()
Expand Down
2 changes: 1 addition & 1 deletion internal/api/v2/controllers_stats_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ func TestStats(t *testing.T) {
t.Parallel()

systemController, ledgerController := newTestingSystemController(t, true)
router := NewRouter(systemController, auth.NewNoAuth(), os.Getenv("DEBUG") == "true")
router := NewRouter(systemController, auth.NewNoAuth(), "develop", os.Getenv("DEBUG") == "true")

expectedStats := ledgercontroller.Stats{
Transactions: 10,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ func TestTransactionsAddMetadata(t *testing.T) {
Return(nil, testCase.returnErr)
}

router := NewRouter(systemController, auth.NewNoAuth(), os.Getenv("DEBUG") == "true")
router := NewRouter(systemController, auth.NewNoAuth(), "develop", os.Getenv("DEBUG") == "true")

req := httptest.NewRequest(http.MethodPost, fmt.Sprintf("/xxx/transactions/%v/metadata", testCase.id), api.Buffer(t, testCase.body))
rec := httptest.NewRecorder()
Expand Down
2 changes: 1 addition & 1 deletion internal/api/v2/controllers_transactions_count_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ func TestTransactionsCount(t *testing.T) {
Return(10, tc.returnErr)
}

router := NewRouter(systemController, auth.NewNoAuth(), os.Getenv("DEBUG") == "true")
router := NewRouter(systemController, auth.NewNoAuth(), "develop", os.Getenv("DEBUG") == "true")

req := httptest.NewRequest(http.MethodHead, "/xxx/transactions?pit="+before.Format(time.RFC3339Nano), bytes.NewBufferString(tc.body))
rec := httptest.NewRecorder()
Expand Down
2 changes: 1 addition & 1 deletion internal/api/v2/controllers_transactions_create_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,7 @@ func TestTransactionCreate(t *testing.T) {
}
}

router := NewRouter(systemController, auth.NewNoAuth(), os.Getenv("DEBUG") == "true")
router := NewRouter(systemController, auth.NewNoAuth(), "develop", os.Getenv("DEBUG") == "true")

req := httptest.NewRequest(http.MethodPost, "/xxx/transactions", api.Buffer(t, testCase.payload))
rec := httptest.NewRecorder()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ func TestTransactionsDeleteMetadata(t *testing.T) {
Return(&ledger.Log{}, tc.returnErr)
}

router := NewRouter(systemController, auth.NewNoAuth(), os.Getenv("DEBUG") == "true")
router := NewRouter(systemController, auth.NewNoAuth(), "develop", os.Getenv("DEBUG") == "true")

req := httptest.NewRequest(http.MethodDelete, "/ledger0/transactions/1/metadata/foo", nil)
req = req.WithContext(ctx)
Expand Down
2 changes: 1 addition & 1 deletion internal/api/v2/controllers_transactions_list_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ func TestTransactionsList(t *testing.T) {
Return(&expectedCursor, nil)
}

router := NewRouter(systemController, auth.NewNoAuth(), os.Getenv("DEBUG") == "true")
router := NewRouter(systemController, auth.NewNoAuth(), "develop", os.Getenv("DEBUG") == "true")

req := httptest.NewRequest(http.MethodGet, "/xxx/transactions", bytes.NewBufferString(testCase.body))
rec := httptest.NewRecorder()
Expand Down
2 changes: 1 addition & 1 deletion internal/api/v2/controllers_transactions_read_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func TestTransactionsRead(t *testing.T) {
GetTransaction(gomock.Any(), q).
Return(&tx, nil)

router := NewRouter(systemController, auth.NewNoAuth(), os.Getenv("DEBUG") == "true")
router := NewRouter(systemController, auth.NewNoAuth(), "develop", os.Getenv("DEBUG") == "true")

req := httptest.NewRequest(http.MethodGet, "/xxx/transactions/0?pit="+now.Format(time.RFC3339Nano), nil)
rec := httptest.NewRecorder()
Expand Down
2 changes: 1 addition & 1 deletion internal/api/v2/controllers_transactions_revert_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ func TestTransactionsRevert(t *testing.T) {
RevertTransaction: tc.returnTx,
}, tc.returnErr)

router := NewRouter(systemController, auth.NewNoAuth(), os.Getenv("DEBUG") == "true")
router := NewRouter(systemController, auth.NewNoAuth(), "develop", os.Getenv("DEBUG") == "true")

req := httptest.NewRequest(http.MethodPost, "/xxx/transactions/0/revert", nil)
if tc.queryParams != nil {
Expand Down
2 changes: 1 addition & 1 deletion internal/api/v2/controllers_volumes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ func TestGetVolumes(t *testing.T) {
Return(&expectedCursor, nil)
}

router := NewRouter(systemController, auth.NewNoAuth(), os.Getenv("DEBUG") == "true")
router := NewRouter(systemController, auth.NewNoAuth(), "develop", os.Getenv("DEBUG") == "true")

req := httptest.NewRequest(http.MethodGet, "/xxx/volumes?endTime="+before.Format(time.RFC3339Nano), bytes.NewBufferString(testCase.body))
rec := httptest.NewRecorder()
Expand Down
4 changes: 4 additions & 0 deletions internal/api/v2/routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package v2
import (
"github.com/formancehq/go-libs/v2/bun/bunpaginate"
"github.com/formancehq/ledger/internal/api/bulking"
v1 "github.com/formancehq/ledger/internal/api/v1"
nooptracer "go.opentelemetry.io/otel/trace/noop"
"net/http"

Expand All @@ -21,6 +22,7 @@ import (
func NewRouter(
systemController system.Controller,
authenticator auth.Authenticator,
version string,
debug bool,
opts ...RouterOption,
) chi.Router {
Expand All @@ -36,6 +38,8 @@ func NewRouter(
router.Use(auth.Middleware(authenticator))
router.Use(service.OTLPMiddleware("ledger", debug))

router.Get("/_info", v1.GetInfo(systemController, version))

router.Get("/", listLedgers(systemController, routerOptions.paginationConfig))
router.Route("/{ledger}", func(router chi.Router) {
router.Use(func(handler http.Handler) http.Handler {
Expand Down

0 comments on commit 95c8317

Please sign in to comment.