2024-06-06 01:40:56 -04:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"fmt"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/jackc/pgx/v5/pgxpool"
|
2024-06-06 17:01:16 -04:00
|
|
|
"github.com/spf13/viper"
|
2024-06-06 01:40:56 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestDB(t *testing.T) {
|
2024-06-06 17:01:16 -04:00
|
|
|
cfg := DefaultConfig()
|
|
|
|
cfg.DB.Password = viper.GetString(ViperDBPassword)
|
|
|
|
|
2024-06-06 01:40:56 -04:00
|
|
|
ctx := context.Background()
|
|
|
|
|
|
|
|
//prep
|
|
|
|
pool, err := pgxpool.New(
|
|
|
|
ctx,
|
|
|
|
fmt.Sprintf(
|
|
|
|
"user=%s password=%s database=%s host=%s port=%d sslmode=%s ",
|
2024-06-06 17:01:16 -04:00
|
|
|
cfg.DB.User,
|
|
|
|
cfg.DB.Password,
|
|
|
|
cfg.DB.Database,
|
|
|
|
cfg.DB.Host,
|
|
|
|
cfg.DB.Port,
|
|
|
|
cfg.DB.SSLMode,
|
2024-06-06 01:40:56 -04:00
|
|
|
))
|
|
|
|
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)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|