2022-03-26 12:52:25 +00:00
|
|
|
package pgfixture_test
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"testing"
|
|
|
|
|
2024-06-05 17:36:34 +00:00
|
|
|
"github.com/jackc/pgx/v5"
|
2022-03-26 12:52:25 +00:00
|
|
|
"github.com/stretchr/testify/require"
|
2022-04-17 15:28:33 +00:00
|
|
|
|
2024-06-05 17:36:34 +00:00
|
|
|
"gitlab.com/slon/shad-go/pgfixture"
|
2022-03-26 12:52:25 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestLocalPostgres(t *testing.T) {
|
|
|
|
dsn := pgfixture.Start(t)
|
|
|
|
ctx := context.Background()
|
|
|
|
|
|
|
|
conn, err := pgx.Connect(ctx, dsn)
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.NoError(t, conn.Ping(ctx))
|
|
|
|
|
|
|
|
_, err = conn.Exec(ctx, `CREATE TABLE users (id SERIAL PRIMARY KEY, name TEXT);`)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
_, err = conn.Exec(ctx, `INSERT INTO users (name) VALUES ($1);`, "Fedor")
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
row := conn.QueryRow(ctx, `SELECT id, name FROM users LIMIT 1;`)
|
|
|
|
|
|
|
|
var id int
|
|
|
|
var name string
|
|
|
|
|
|
|
|
require.NoError(t, row.Scan(&id, &name))
|
|
|
|
require.Equal(t, 1, id)
|
|
|
|
require.Equal(t, name, "Fedor")
|
|
|
|
}
|