46 lines
651 B
Go
46 lines
651 B
Go
|
package main
|
||
|
|
||
|
import (
|
||
|
"context"
|
||
|
"fmt"
|
||
|
"testing"
|
||
|
|
||
|
"github.com/jackc/pgx/v5/pgxpool"
|
||
|
)
|
||
|
|
||
|
func TestDB(t *testing.T) {
|
||
|
ctx := context.Background()
|
||
|
|
||
|
//prep
|
||
|
pool, err := pgxpool.New(
|
||
|
ctx,
|
||
|
fmt.Sprintf(
|
||
|
"user=%s password=%s database=%s host=%s port=%d sslmode=%s ",
|
||
|
"bottin",
|
||
|
"bottin",
|
||
|
"bottin",
|
||
|
"localhost",
|
||
|
5432,
|
||
|
"prefer", //TODO change to "require"
|
||
|
))
|
||
|
if err != nil {
|
||
|
t.Error(err)
|
||
|
return
|
||
|
}
|
||
|
defer pool.Close()
|
||
|
|
||
|
db := &PostgresClient{
|
||
|
Ctx: ctx,
|
||
|
Pool: pool,
|
||
|
}
|
||
|
|
||
|
//exec
|
||
|
|
||
|
t.Run("create or replace schema",
|
||
|
func(t *testing.T) {
|
||
|
if err := db.CreateOrReplaceSchema(); err != nil {
|
||
|
t.Error(err)
|
||
|
}
|
||
|
})
|
||
|
}
|