diff --git a/db/sqlc/main_test.go b/db/sqlc/main_test.go deleted file mode 100644 index 0ec0b5d..0000000 --- a/db/sqlc/main_test.go +++ /dev/null @@ -1,27 +0,0 @@ -package db - -import ( - "context" - "log" - "os" - "testing" - - "github.com/jackc/pgx/v5/pgxpool" -) - -var testStore Store - -func TestMain(m *testing.M) { - config, err := util.LoadConfig("../..") - if err != nil { - log.Fatal("cannot load config:", err) - } - - connPool, err := pgxpool.New(context.Background(), config.DBSource) - if err != nil { - log.Fatal("cannot connect to db:", err) - } - - testStore = NewStore(connPool) - os.Exit(m.Run()) -} diff --git a/db/sqlc/transfer_test.go b/db/sqlc/transfer_test.go deleted file mode 100644 index a976d05..0000000 --- a/db/sqlc/transfer_test.go +++ /dev/null @@ -1,79 +0,0 @@ -package db - -import ( - "context" - "testing" - "time" - - "github.com/stretchr/testify/require" - "github.com/techschool/simplebank/util" -) - -func createRandomTransfer(t *testing.T, account1, account2 Account) Transfer { - arg := CreateTransferParams{ - FromAccountID: account1.ID, - ToAccountID: account2.ID, - Amount: util.RandomMoney(), - } - - transfer, err := testStore.CreateTransfer(context.Background(), arg) - require.NoError(t, err) - require.NotEmpty(t, transfer) - - require.Equal(t, arg.FromAccountID, transfer.FromAccountID) - require.Equal(t, arg.ToAccountID, transfer.ToAccountID) - require.Equal(t, arg.Amount, transfer.Amount) - - require.NotZero(t, transfer.ID) - require.NotZero(t, transfer.CreatedAt) - - return transfer -} - -func TestCreateTransfer(t *testing.T) { - account1 := createRandomAccount(t) - account2 := createRandomAccount(t) - createRandomTransfer(t, account1, account2) -} - -func TestGetTransfer(t *testing.T) { - account1 := createRandomAccount(t) - account2 := createRandomAccount(t) - transfer1 := createRandomTransfer(t, account1, account2) - - transfer2, err := testStore.GetTransfer(context.Background(), transfer1.ID) - require.NoError(t, err) - require.NotEmpty(t, transfer2) - - require.Equal(t, transfer1.ID, transfer2.ID) - require.Equal(t, transfer1.FromAccountID, transfer2.FromAccountID) - require.Equal(t, transfer1.ToAccountID, transfer2.ToAccountID) - require.Equal(t, transfer1.Amount, transfer2.Amount) - require.WithinDuration(t, transfer1.CreatedAt, transfer2.CreatedAt, time.Second) -} - -func TestListTransfer(t *testing.T) { - account1 := createRandomAccount(t) - account2 := createRandomAccount(t) - - for i := 0; i < 5; i++ { - createRandomTransfer(t, account1, account2) - createRandomTransfer(t, account2, account1) - } - - arg := ListTransfersParams{ - FromAccountID: account1.ID, - ToAccountID: account1.ID, - Limit: 5, - Offset: 5, - } - - transfers, err := testStore.ListTransfers(context.Background(), arg) - require.NoError(t, err) - require.Len(t, transfers, 5) - - for _, transfer := range transfers { - require.NotEmpty(t, transfer) - require.True(t, transfer.FromAccountID == account1.ID || transfer.ToAccountID == account1.ID) - } -}