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 authored Jan 27, 2025
1 parent c10b32b commit f7cf431
Show file tree
Hide file tree
Showing 29 changed files with 32 additions and 54 deletions.
2 changes: 1 addition & 1 deletion internal/api/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ func NewRouter(
v2Router := v2.NewRouter(
systemController,
authenticator,
debug,
version,
v2.WithTracer(routerOptions.tracer),
v2.WithBulkerFactory(routerOptions.bulkerFactory),
v2.WithBulkHandlerFactories(map[string]bulking.HandlerFactory{
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 @@ -27,7 +27,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(auth.Middleware(authenticator))
Expand Down
3 changes: 1 addition & 2 deletions internal/api/v2/controllers_accounts_add_metadata_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"net/http"
"net/http/httptest"
"net/url"
"os"
"testing"

ledgercontroller "github.com/formancehq/ledger/internal/controller/ledger"
Expand Down Expand Up @@ -72,7 +71,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")

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
3 changes: 1 addition & 2 deletions internal/api/v2/controllers_accounts_count_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"net/http"
"net/http/httptest"
"net/url"
"os"
"testing"

"errors"
Expand Down Expand Up @@ -138,7 +137,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")

req := httptest.NewRequest(http.MethodHead, "/xxx/accounts?pit="+before.Format(time.RFC3339Nano), bytes.NewBufferString(testCase.body))
rec := httptest.NewRecorder()
Expand Down
3 changes: 1 addition & 2 deletions internal/api/v2/controllers_accounts_delete_metadata_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"net/http"
"net/http/httptest"
"net/url"
"os"
"testing"

"errors"
Expand Down Expand Up @@ -72,7 +71,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")

req := httptest.NewRequest(http.MethodDelete, "/", nil)
req.URL.Path = "/ledger0/accounts/" + tc.account + "/metadata/foo"
Expand Down
3 changes: 1 addition & 2 deletions internal/api/v2/controllers_accounts_list_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"net/http"
"net/http/httptest"
"net/url"
"os"
"testing"

"errors"
Expand Down Expand Up @@ -218,7 +217,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")

req := httptest.NewRequest(http.MethodGet, "/xxx/accounts?pit="+before.Format(time.RFC3339Nano), bytes.NewBufferString(tc.body))
rec := httptest.NewRecorder()
Expand Down
3 changes: 1 addition & 2 deletions internal/api/v2/controllers_accounts_read_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"net/http"
"net/http/httptest"
"net/url"
"os"
"testing"

"github.com/formancehq/go-libs/v2/api"
Expand Down Expand Up @@ -93,7 +92,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")

req := httptest.NewRequest(http.MethodGet, "/", bytes.NewBufferString(tc.body))
req.URL.Path = "/xxx/accounts/" + tc.account
Expand Down
3 changes: 1 addition & 2 deletions internal/api/v2/controllers_balances_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"net/http"
"net/http/httptest"
"net/url"
"os"
"testing"

ledgercontroller "github.com/formancehq/ledger/internal/controller/ledger"
Expand Down Expand Up @@ -100,7 +99,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")

req := httptest.NewRequest(http.MethodGet, "/xxx/aggregate/balances?pit="+now.Format(time.RFC3339Nano), bytes.NewBufferString(testCase.body))
rec := httptest.NewRecorder()
Expand Down
3 changes: 1 addition & 2 deletions internal/api/v2/controllers_bulk_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"net/http"
"net/http/httptest"
"net/url"
"os"
"testing"

"github.com/formancehq/go-libs/v2/collectionutils"
Expand Down Expand Up @@ -485,7 +484,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")

req := httptest.NewRequest(http.MethodPost, "/xxx/_bulk", bytes.NewBufferString(testCase.body))
req.Header = testCase.headers
Expand Down
3 changes: 1 addition & 2 deletions internal/api/v2/controllers_ledgers_create_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"github.com/formancehq/ledger/internal/api/common"
"net/http"
"net/http/httptest"
"os"
"testing"

"github.com/formancehq/ledger/internal/controller/system"
Expand Down Expand Up @@ -100,7 +99,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")

name := uuid.NewString()

Expand Down
3 changes: 1 addition & 2 deletions internal/api/v2/controllers_ledgers_delete_metadata_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"encoding/json"
"net/http"
"net/http/httptest"
"os"
"testing"

"errors"
Expand Down Expand Up @@ -54,7 +53,7 @@ func TestLedgersDeleteMetadata(t *testing.T) {
Return(tc.returnErr)
}

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

req := httptest.NewRequest(http.MethodDelete, "/"+name+"/metadata/foo", nil)
req = req.WithContext(ctx)
Expand Down
3 changes: 1 addition & 2 deletions internal/api/v2/controllers_ledgers_info_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package v2
import (
"net/http"
"net/http/httptest"
"os"
"testing"

"github.com/formancehq/go-libs/v2/time"
Expand All @@ -19,7 +18,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")

migrationInfo := []migrations.Info{
{
Expand Down
3 changes: 1 addition & 2 deletions internal/api/v2/controllers_ledgers_list_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"net/http"
"net/http/httptest"
"net/url"
"os"
"testing"

"errors"
Expand Down Expand Up @@ -95,7 +94,7 @@ func TestListLedgers(t *testing.T) {
}, tc.returnErr)
}

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

req := httptest.NewRequest(http.MethodGet, "/", nil)
req = req.WithContext(ctx)
Expand Down
3 changes: 1 addition & 2 deletions internal/api/v2/controllers_ledgers_read_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package v2
import (
"net/http"
"net/http/httptest"
"os"
"testing"

ledger "github.com/formancehq/ledger/internal"
Expand All @@ -22,7 +21,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")

name := uuid.NewString()
now := time.Now()
Expand Down
3 changes: 1 addition & 2 deletions internal/api/v2/controllers_ledgers_update_metadata_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package v2
import (
"net/http"
"net/http/httptest"
"os"
"testing"

"github.com/formancehq/go-libs/v2/api"
Expand All @@ -26,7 +25,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")

req := httptest.NewRequest(http.MethodPut, "/"+name+"/metadata", api.Buffer(t, metadata))
req = req.WithContext(ctx)
Expand Down
3 changes: 1 addition & 2 deletions internal/api/v2/controllers_logs_export_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"encoding/json"
"net/http"
"net/http/httptest"
"os"
"testing"

"errors"
Expand Down Expand Up @@ -62,7 +61,7 @@ func TestLogsExport(t *testing.T) {
return nil
})

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

req := httptest.NewRequest(http.MethodPost, "/xxx/logs/export", nil)
rec := httptest.NewRecorder()
Expand Down
3 changes: 1 addition & 2 deletions internal/api/v2/controllers_logs_import_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"encoding/json"
"net/http"
"net/http/httptest"
"os"
"testing"
"time"

Expand Down Expand Up @@ -73,7 +72,7 @@ func TestLogsImport(t *testing.T) {
}
})

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

buf := bytes.NewBuffer(nil)
require.NoError(t, json.NewEncoder(buf).Encode(log))
Expand Down
3 changes: 1 addition & 2 deletions internal/api/v2/controllers_logs_list_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"net/http"
"net/http/httptest"
"net/url"
"os"
"testing"

"errors"
Expand Down Expand Up @@ -174,7 +173,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")

req := httptest.NewRequest(http.MethodGet, "/xxx/logs", bytes.NewBufferString(testCase.body))
rec := httptest.NewRecorder()
Expand Down
3 changes: 1 addition & 2 deletions internal/api/v2/controllers_stats_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package v2
import (
"net/http"
"net/http/httptest"
"os"
"testing"

"github.com/formancehq/go-libs/v2/api"
Expand All @@ -17,7 +16,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")

expectedStats := ledgercontroller.Stats{
Transactions: 10,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"net/http"
"net/http/httptest"
"net/url"
"os"
"testing"

"errors"
Expand Down Expand Up @@ -99,7 +98,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")

req := httptest.NewRequest(http.MethodPost, fmt.Sprintf("/xxx/transactions/%v/metadata", testCase.id), api.Buffer(t, testCase.body))
rec := httptest.NewRecorder()
Expand Down
3 changes: 1 addition & 2 deletions internal/api/v2/controllers_transactions_count_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"net/http"
"net/http/httptest"
"net/url"
"os"
"testing"

"errors"
Expand Down Expand Up @@ -164,7 +163,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")

req := httptest.NewRequest(http.MethodHead, "/xxx/transactions?pit="+before.Format(time.RFC3339Nano), bytes.NewBufferString(tc.body))
rec := httptest.NewRecorder()
Expand Down
3 changes: 1 addition & 2 deletions internal/api/v2/controllers_transactions_create_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"net/http"
"net/http/httptest"
"net/url"
"os"
"testing"

"github.com/formancehq/go-libs/v2/time"
Expand Down Expand Up @@ -416,7 +415,7 @@ func TestTransactionCreate(t *testing.T) {
}
}

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

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 @@ -6,7 +6,6 @@ import (
"net/http"
"net/http/httptest"
"net/url"
"os"
"testing"

"errors"
Expand Down Expand Up @@ -68,7 +67,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")

req := httptest.NewRequest(http.MethodDelete, "/ledger0/transactions/1/metadata/foo", nil)
req = req.WithContext(ctx)
Expand Down
Loading

0 comments on commit f7cf431

Please sign in to comment.