Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,15 @@ var riExchangeReservationIntegrationFiles = []string{
"store_postgres_ri_exchange_reservation_integration_test.go",
"store_postgres_ri_exchange_approved_reservation_integration_test.go",
filepath.Join("..", "server", "handler_ri_exchange_reservation_integration_test.go"),
"store_postgres_auto_purchase_stamps_integration_test.go",
"store_postgres_ladder_arming_integration_test.go",
}

// TestRIExchangeReservationIntegrationTestsAreNotEnvGated guards #724. These
// TestRIExchangeReservationIntegrationTestsAreNotEnvGated guards #724 and #202. These
// tests used to read RI_EXCHANGE_TEST_DATABASE_URL and t.Skip when it was
// unset, which CI never set, so the spend-limiting path ran nowhere. They now
// unset (the auto-purchase stamp and ladder arming tests, #202, did the same
// with their own variables), which CI never set, so the spend-limiting path
// ran nowhere. They now
// get their database from testhelpers.RequirePostgresContainer, which decides
// on its own whether Docker is missing. Any os.Getenv or direct skip in these
// files would bring back a way to run them without running them.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,37 +5,22 @@ package config

import (
"context"
"net/url"
"os"
"strings"
"testing"
"time"

"github.com/LeanerCloud/cloud-commitments-platform/internal/database/postgres/migrations"
"github.com/jackc/pgx/v5/pgxpool"
"github.com/LeanerCloud/cloud-commitments-platform/internal/database/postgres/testhelpers"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

// TestPostgresStoreDB_AutoPurchaseStamps_FreshMigrateAndRIWritePreserve runs
// against a dedicated database named r1a_* (AUTO_PURCHASE_STAMPS_TEST_DATABASE_URL):
// against a fresh database from the shared test container:
// a fresh migrate leaves the kill switch OFF with NULL stamps, and the RI-exchange
// style whole-config read-modify-write keeps the stamps instead of wiping them.
func TestPostgresStoreDB_AutoPurchaseStamps_FreshMigrateAndRIWritePreserve(t *testing.T) {
dsn := os.Getenv("AUTO_PURCHASE_STAMPS_TEST_DATABASE_URL")
if dsn == "" {
t.Skip("set AUTO_PURCHASE_STAMPS_TEST_DATABASE_URL to a dedicated r1a_* test database")
}
parsed, err := url.Parse(dsn)
require.NoError(t, err)
require.True(t, strings.HasPrefix(strings.TrimPrefix(parsed.Path, "/"), "r1a_"), "database must be dedicated to R1a verification")

ctx, cancel := context.WithTimeout(context.Background(), time.Minute)
defer cancel()
pool, err := pgxpool.New(ctx, dsn)
require.NoError(t, err)
defer pool.Close()
require.NoError(t, migrations.RunMigrations(ctx, pool, getTestMigrationsPath(), "", ""))
pool := testhelpers.RequireMigratedDatabase(ctx, t, getTestMigrationsPath()).DB
store := &PostgresStore{db: pool}

cfg, err := store.GetGlobalConfig(ctx)
Expand Down Expand Up @@ -79,20 +64,9 @@ func TestPostgresStoreDB_AutoPurchaseStamps_FreshMigrateAndRIWritePreserve(t *te
// same cents the gate compared (B1: 1.005 used to store as 1.01 while the gate
// saw 1.00), and that caps it rejects include the half-cent inputs.
func TestPostgresStoreDB_StepCapStoredEqualsCompared(t *testing.T) {
dsn := os.Getenv("AUTO_PURCHASE_STAMPS_TEST_DATABASE_URL")
if dsn == "" {
t.Skip("set AUTO_PURCHASE_STAMPS_TEST_DATABASE_URL to a dedicated r1a_* test database")
}
parsed, err := url.Parse(dsn)
require.NoError(t, err)
require.True(t, strings.HasPrefix(strings.TrimPrefix(parsed.Path, "/"), "r1a_"), "database must be dedicated to R1a verification")

ctx, cancel := context.WithTimeout(context.Background(), 2*time.Minute)
defer cancel()
pool, err := pgxpool.New(ctx, dsn)
require.NoError(t, err)
defer pool.Close()
require.NoError(t, migrations.RunMigrations(ctx, pool, getTestMigrationsPath(), "", ""))
pool := testhelpers.RequireMigratedDatabase(ctx, t, getTestMigrationsPath()).DB
store := &PostgresStore{db: pool}

plan := &PurchasePlan{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,38 +5,23 @@ package config

import (
"context"
"net/url"
"os"
"strings"
"testing"
"time"

"github.com/LeanerCloud/cloud-commitments-platform/internal/database/postgres/migrations"
"github.com/jackc/pgx/v5/pgxpool"
"github.com/LeanerCloud/cloud-commitments-platform/internal/database/postgres/testhelpers"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

// TestPostgresStoreDB_LadderArming runs against a dedicated database named pr2_*
// (LADDER_ARMING_TEST_DATABASE_URL): a fresh migrate leaves both ladder switches
// TestPostgresStoreDB_LadderArming runs against a fresh database from the
// shared test container: a fresh migrate leaves both ladder switches
// OFF with NULL stamps, the stamps survive a whole-config write from another
// path, and every cap LadderCapMicros accepts is stored as the same micro-dollars
// it compared (NUMERIC(20,6)).
func TestPostgresStoreDB_LadderArming(t *testing.T) {
dsn := os.Getenv("LADDER_ARMING_TEST_DATABASE_URL")
if dsn == "" {
t.Skip("set LADDER_ARMING_TEST_DATABASE_URL to a dedicated pr2_* test database")
}
parsed, err := url.Parse(dsn)
require.NoError(t, err)
require.True(t, strings.HasPrefix(strings.TrimPrefix(parsed.Path, "/"), "pr2_"), "database must be dedicated to PR2 verification")

ctx, cancel := context.WithTimeout(context.Background(), 2*time.Minute)
defer cancel()
pool, err := pgxpool.New(ctx, dsn)
require.NoError(t, err)
defer pool.Close()
require.NoError(t, migrations.RunMigrations(ctx, pool, getTestMigrationsPath(), "", ""))
pool := testhelpers.RequireMigratedDatabase(ctx, t, getTestMigrationsPath()).DB
store := &PostgresStore{db: pool}

cfg, err := store.GetGlobalConfig(ctx)
Expand Down
Loading