Skip to content

Commit

Permalink
feat: optimize e2e tests
Browse files Browse the repository at this point in the history
  • Loading branch information
gfyrag committed Oct 23, 2024
1 parent d7dd78c commit ca4e639
Show file tree
Hide file tree
Showing 17 changed files with 43 additions and 32 deletions.
3 changes: 1 addition & 2 deletions test/e2e/api_accounts_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"fmt"
"github.com/formancehq/go-libs/v2/logging"
. "github.com/formancehq/go-libs/v2/testing/api"
"github.com/formancehq/go-libs/v2/testing/platform/pgtesting"
. "github.com/formancehq/ledger/pkg/testserver"
"github.com/formancehq/stack/ledger/client/models/components"
"github.com/formancehq/stack/ledger/client/models/operations"
Expand All @@ -23,7 +22,7 @@ import (

var _ = Context("Ledger accounts list API tests", func() {
var (
db = pgtesting.UsePostgresDatabase(pgServer)
db = UseTemplatedDatabase()
ctx = logging.TestingContext()
)

Expand Down
3 changes: 1 addition & 2 deletions test/e2e/api_accounts_metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ package test_suite

import (
"github.com/formancehq/go-libs/v2/logging"
"github.com/formancehq/go-libs/v2/testing/platform/pgtesting"
ledgerevents "github.com/formancehq/ledger/pkg/events"
. "github.com/formancehq/ledger/pkg/testserver"
"github.com/formancehq/stack/ledger/client/models/components"
Expand All @@ -16,7 +15,7 @@ import (

var _ = Context("Ledger accounts list API tests", func() {
var (
db = pgtesting.UsePostgresDatabase(pgServer)
db = UseTemplatedDatabase()
ctx = logging.TestingContext()
)

Expand Down
3 changes: 1 addition & 2 deletions test/e2e/api_balances_aggregated.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ package test_suite
import (
"github.com/formancehq/go-libs/v2/logging"
"github.com/formancehq/go-libs/v2/pointer"
"github.com/formancehq/go-libs/v2/testing/platform/pgtesting"
. "github.com/formancehq/ledger/pkg/testserver"
"github.com/formancehq/stack/ledger/client/models/components"
"github.com/formancehq/stack/ledger/client/models/operations"
Expand All @@ -18,7 +17,7 @@ import (

var _ = Context("Ledger engine tests", func() {
var (
db = pgtesting.UsePostgresDatabase(pgServer)
db = UseTemplatedDatabase()
ctx = logging.TestingContext()
)

Expand Down
3 changes: 1 addition & 2 deletions test/e2e/api_bulk.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ package test_suite
import (
"github.com/formancehq/go-libs/v2/logging"
. "github.com/formancehq/go-libs/v2/testing/api"
"github.com/formancehq/go-libs/v2/testing/platform/pgtesting"
. "github.com/formancehq/ledger/pkg/testserver"
"github.com/formancehq/stack/ledger/client/models/components"
"github.com/formancehq/stack/ledger/client/models/operations"
Expand All @@ -19,7 +18,7 @@ import (

var _ = Context("Ledger engine tests", func() {
var (
db = pgtesting.UsePostgresDatabase(pgServer)
db = UseTemplatedDatabase()
ctx = logging.TestingContext()
bulkMaxSize = 5
)
Expand Down
3 changes: 1 addition & 2 deletions test/e2e/api_ledgers_create_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"github.com/formancehq/go-libs/v2/logging"
"github.com/formancehq/go-libs/v2/pointer"
. "github.com/formancehq/go-libs/v2/testing/api"
"github.com/formancehq/go-libs/v2/testing/platform/pgtesting"
ledger "github.com/formancehq/ledger/internal"
. "github.com/formancehq/ledger/pkg/testserver"
"github.com/formancehq/stack/ledger/client/models/components"
Expand All @@ -18,7 +17,7 @@ import (

var _ = Context("Ledger engine tests", func() {
var (
db = pgtesting.UsePostgresDatabase(pgServer)
db = UseTemplatedDatabase()
ctx = logging.TestingContext()
)

Expand Down
3 changes: 1 addition & 2 deletions test/e2e/api_ledgers_import_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (

"github.com/formancehq/go-libs/v2/logging"
"github.com/formancehq/go-libs/v2/pointer"
"github.com/formancehq/go-libs/v2/testing/platform/pgtesting"
ledger "github.com/formancehq/ledger/internal"
. "github.com/formancehq/ledger/pkg/testserver"
"github.com/formancehq/stack/ledger/client/models/components"
Expand All @@ -22,7 +21,7 @@ import (

var _ = Context("Ledger engine tests", func() {
var (
db = pgtesting.UsePostgresDatabase(pgServer)
db = UseTemplatedDatabase()
ctx = logging.TestingContext()
)

Expand Down
3 changes: 1 addition & 2 deletions test/e2e/api_ledgers_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ package test_suite
import (
"fmt"
"github.com/formancehq/go-libs/v2/logging"
"github.com/formancehq/go-libs/v2/testing/platform/pgtesting"
. "github.com/formancehq/ledger/pkg/testserver"
"github.com/formancehq/stack/ledger/client/models/operations"
. "github.com/onsi/ginkgo/v2"
Expand All @@ -14,7 +13,7 @@ import (

var _ = Context("Ledger engine tests", func() {
var (
db = pgtesting.UsePostgresDatabase(pgServer)
db = UseTemplatedDatabase()
ctx = logging.TestingContext()
)

Expand Down
3 changes: 1 addition & 2 deletions test/e2e/api_ledgers_metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ package test_suite

import (
"github.com/formancehq/go-libs/v2/logging"
"github.com/formancehq/go-libs/v2/testing/platform/pgtesting"
. "github.com/formancehq/ledger/pkg/testserver"
"github.com/formancehq/stack/ledger/client/models/operations"
. "github.com/onsi/ginkgo/v2"
Expand All @@ -13,7 +12,7 @@ import (

var _ = Context("Ledger engine tests", func() {
var (
db = pgtesting.UsePostgresDatabase(pgServer)
db = UseTemplatedDatabase()
ctx = logging.TestingContext()
)

Expand Down
3 changes: 1 addition & 2 deletions test/e2e/api_logs_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"fmt"
"github.com/formancehq/go-libs/v2/logging"
"github.com/formancehq/go-libs/v2/pointer"
"github.com/formancehq/go-libs/v2/testing/platform/pgtesting"
. "github.com/formancehq/ledger/pkg/testserver"
"github.com/formancehq/stack/ledger/client/models/components"
"github.com/formancehq/stack/ledger/client/models/operations"
Expand All @@ -19,7 +18,7 @@ import (

var _ = Context("Ledger logs list API tests", func() {
var (
db = pgtesting.UsePostgresDatabase(pgServer)
db = UseTemplatedDatabase()
ctx = logging.TestingContext()
)

Expand Down
3 changes: 1 addition & 2 deletions test/e2e/api_transactions_create.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ package test_suite
import (
"github.com/formancehq/go-libs/v2/logging"
. "github.com/formancehq/go-libs/v2/testing/api"
"github.com/formancehq/go-libs/v2/testing/platform/pgtesting"
ledger "github.com/formancehq/ledger/internal"
"github.com/formancehq/ledger/internal/bus"
. "github.com/formancehq/ledger/pkg/testserver"
Expand All @@ -24,7 +23,7 @@ import (

var _ = Context("Ledger accounts list API tests", func() {
var (
db = pgtesting.UsePostgresDatabase(pgServer)
db = UseTemplatedDatabase()
ctx = logging.TestingContext()
)

Expand Down
3 changes: 1 addition & 2 deletions test/e2e/api_transactions_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"github.com/formancehq/go-libs/v2/bun/bunpaginate"
"github.com/formancehq/go-libs/v2/logging"
. "github.com/formancehq/go-libs/v2/testing/api"
"github.com/formancehq/go-libs/v2/testing/platform/pgtesting"
. "github.com/formancehq/ledger/pkg/testserver"
"github.com/formancehq/stack/ledger/client/models/components"
"github.com/formancehq/stack/ledger/client/models/operations"
Expand All @@ -23,7 +22,7 @@ import (

var _ = Context("Ledger transactions list API tests", func() {
var (
db = pgtesting.UsePostgresDatabase(pgServer)
db = UseTemplatedDatabase()
ctx = logging.TestingContext()
)

Expand Down
3 changes: 1 addition & 2 deletions test/e2e/api_transactions_metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ package test_suite
import (
"github.com/formancehq/go-libs/v2/logging"
. "github.com/formancehq/go-libs/v2/testing/api"
"github.com/formancehq/go-libs/v2/testing/platform/pgtesting"
. "github.com/formancehq/ledger/pkg/testserver"
"github.com/formancehq/stack/ledger/client/models/components"
"github.com/formancehq/stack/ledger/client/models/operations"
Expand All @@ -18,7 +17,7 @@ import (

var _ = Context("Ledger accounts list API tests", func() {
var (
db = pgtesting.UsePostgresDatabase(pgServer)
db = UseTemplatedDatabase()
ctx = logging.TestingContext()
)

Expand Down
3 changes: 1 addition & 2 deletions test/e2e/api_transactions_revert.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ package test_suite
import (
"github.com/formancehq/go-libs/v2/logging"
. "github.com/formancehq/go-libs/v2/testing/api"
"github.com/formancehq/go-libs/v2/testing/platform/pgtesting"
. "github.com/formancehq/ledger/pkg/testserver"
"github.com/formancehq/stack/ledger/client/models/components"
"github.com/formancehq/stack/ledger/client/models/operations"
Expand All @@ -22,7 +21,7 @@ import (

var _ = Context("Ledger accounts list API tests", func() {
var (
db = pgtesting.UsePostgresDatabase(pgServer)
db = UseTemplatedDatabase()
ctx = logging.TestingContext()
)

Expand Down
3 changes: 1 addition & 2 deletions test/e2e/api_volumes.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ package test_suite
import (
"github.com/formancehq/go-libs/v2/logging"
"github.com/formancehq/go-libs/v2/pointer"
"github.com/formancehq/go-libs/v2/testing/platform/pgtesting"
. "github.com/formancehq/ledger/pkg/testserver"
"github.com/formancehq/stack/ledger/client/models/components"
"github.com/formancehq/stack/ledger/client/models/operations"
Expand All @@ -28,7 +27,7 @@ var now = time.Now()

var _ = Context("Ledger accounts list API tests", func() {
var (
db = pgtesting.UsePostgresDatabase(pgServer)
db = UseTemplatedDatabase()
ctx = logging.TestingContext()
)

Expand Down
3 changes: 1 addition & 2 deletions test/e2e/lifecycle_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"database/sql"
"github.com/formancehq/go-libs/v2/logging"
"github.com/formancehq/go-libs/v2/pointer"
"github.com/formancehq/go-libs/v2/testing/platform/pgtesting"
"github.com/formancehq/go-libs/v2/time"
ledgerevents "github.com/formancehq/ledger/pkg/events"
. "github.com/formancehq/ledger/pkg/testserver"
Expand All @@ -22,7 +21,7 @@ import (

var _ = Context("Ledger application lifecycle tests", func() {
var (
db = pgtesting.UsePostgresDatabase(pgServer)
db = UseTemplatedDatabase()
ctx = logging.TestingContext()
)

Expand Down
27 changes: 27 additions & 0 deletions test/e2e/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,15 @@
package test_suite

import (
"context"
"encoding/json"
"github.com/formancehq/go-libs/v2/bun/bunconnect"
"github.com/formancehq/go-libs/v2/testing/platform/natstesting"
ledger "github.com/formancehq/ledger/internal"
"github.com/formancehq/ledger/internal/storage/bucket"
"github.com/formancehq/ledger/internal/storage/driver"
"github.com/stretchr/testify/require"
"go.opentelemetry.io/otel/trace/noop"
"os"
"testing"

Expand All @@ -27,6 +34,8 @@ var (
natsServer = NewDeferred[*natstesting.NatsServer]()
debug = os.Getenv("DEBUG") == "true"
logger = logging.NewDefaultLogger(GinkgoWriter, debug, false)

DBTemplate = "template1"
)

type ParallelExecutionContext struct {
Expand All @@ -47,6 +56,20 @@ var _ = SynchronizedBeforeSuite(func() []byte {
WithPGCrypto(),
)
By("Postgres address: " + ret.GetDSN())

db, err := bunconnect.OpenSQLDB(context.Background(), bunconnect.ConnectionOptions{
DatabaseSourceName: ret.GetDatabaseDSN(DBTemplate),
})
require.NoError(GinkgoT(), err)

err = driver.Migrate(context.Background(), db)
require.NoError(GinkgoT(), err)

// Initialize the _default bucket on the default database
// This way, we will be able to clone this database to speed up the tests
err = bucket.Migrate(context.Background(), noop.Tracer{}, db, ledger.DefaultBucket)
require.NoError(GinkgoT(), err)

return ret
})
natsServer.LoadAsync(func() *natstesting.NatsServer {
Expand Down Expand Up @@ -81,3 +104,7 @@ var _ = SynchronizedBeforeSuite(func() []byte {
pgServer.SetValue(pec.PostgresServer)
natsServer.SetValue(pec.NatsServer)
})

func UseTemplatedDatabase() *Deferred[*Database] {
return UsePostgresDatabase(pgServer, CreateWithTemplate(DBTemplate))
}
3 changes: 1 addition & 2 deletions test/e2e/v1_api_balances.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"fmt"
"github.com/formancehq/go-libs/v2/logging"
"github.com/formancehq/go-libs/v2/pointer"
"github.com/formancehq/go-libs/v2/testing/platform/pgtesting"
. "github.com/formancehq/ledger/pkg/testserver"
"github.com/formancehq/stack/ledger/client/models/components"
"github.com/formancehq/stack/ledger/client/models/operations"
Expand All @@ -19,7 +18,7 @@ import (

var _ = Context("Ledger accounts list API tests", func() {
var (
db = pgtesting.UsePostgresDatabase(pgServer)
db = UseTemplatedDatabase()
ctx = logging.TestingContext()
)

Expand Down

0 comments on commit ca4e639

Please sign in to comment.