-
Notifications
You must be signed in to change notification settings - Fork 101
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Sync with stack repository => 56c8bf3d78050d8dd20f20e84e03a0748…
…876aac5
- Loading branch information
Showing
8 changed files
with
1,519 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
package storage_test | ||
|
||
import ( | ||
"database/sql" | ||
"os" | ||
"path/filepath" | ||
"testing" | ||
|
||
"github.com/formancehq/ledger/internal/storage/driver" | ||
"github.com/formancehq/ledger/internal/storage/ledgerstore" | ||
"github.com/formancehq/ledger/internal/storage/systemstore" | ||
"github.com/formancehq/stack/libs/go-libs/bun/bunconnect" | ||
"github.com/formancehq/stack/libs/go-libs/logging" | ||
"github.com/formancehq/stack/libs/go-libs/pgtesting" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestMigrateLedgerV1(t *testing.T) { | ||
require.NoError(t, pgtesting.CreatePostgresServer()) | ||
t.Cleanup(func() { | ||
require.NoError(t, pgtesting.DestroyPostgresServer()) | ||
}) | ||
|
||
db, err := sql.Open("postgres", pgtesting.Server().GetDSN()) | ||
require.NoError(t, err) | ||
|
||
data, err := os.ReadFile(filepath.Join("testdata", "v1-dump.sql")) | ||
require.NoError(t, err) | ||
|
||
_, err = db.Exec(string(data)) | ||
require.NoError(t, err) | ||
|
||
ctx := logging.TestingContext() | ||
|
||
d := driver.New(bunconnect.ConnectionOptions{ | ||
DatabaseSourceName: pgtesting.Server().GetDSN(), | ||
Debug: testing.Verbose(), | ||
Writer: os.Stdout, | ||
}) | ||
require.NoError(t, d.Initialize(ctx)) | ||
|
||
ledgers, err := d.GetSystemStore().ListLedgers(ctx, systemstore.ListLedgersQuery{}) | ||
require.NoError(t, err) | ||
|
||
for _, ledger := range ledgers.Data { | ||
require.NotEmpty(t, ledger.Bucket) | ||
require.Equal(t, ledger.Name, ledger.Bucket) | ||
|
||
bucket, err := d.OpenBucket(ledger.Bucket) | ||
require.NoError(t, err) | ||
require.NoError(t, bucket.Migrate(ctx)) | ||
|
||
store, err := bucket.GetLedgerStore(ledger.Name) | ||
require.NoError(t, err) | ||
|
||
txs, err := store.GetTransactions(ctx, ledgerstore.NewGetTransactionsQuery(ledgerstore.PaginatedQueryOptions[ledgerstore.PITFilterWithVolumes]{})) | ||
require.NoError(t, err) | ||
require.NotEmpty(t, txs) | ||
|
||
accounts, err := store.GetAccountsWithVolumes(ctx, ledgerstore.NewGetAccountsQuery(ledgerstore.PaginatedQueryOptions[ledgerstore.PITFilterWithVolumes]{})) | ||
require.NoError(t, err) | ||
require.NotEmpty(t, accounts) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,27 @@ | ||
package collectionutils | ||
|
||
import "fmt" | ||
|
||
func Keys[K comparable, V any](m map[K]V) []K { | ||
ret := make([]K, 0) | ||
for k := range m { | ||
ret = append(ret, k) | ||
} | ||
return ret | ||
} | ||
|
||
func ConvertMap[K comparable, FROM any, TO any](m map[K]FROM, mapper func(v FROM) TO) map[K]TO { | ||
ret := make(map[K]TO) | ||
for k, from := range m { | ||
ret[k] = mapper(from) | ||
} | ||
return ret | ||
} | ||
|
||
func ToAny[V any](v V) any { | ||
return v | ||
} | ||
|
||
func ToFmtString[V any](v any) string { | ||
return fmt.Sprint(v) | ||
} |
Oops, something went wrong.