Files
query-orchestration/internal/serviceconfig/database/pool_test.go
T
Michael McGuinness fee71e7740 Merged in feature/postprocessing (pull request #114)
Feature/postprocessing

* tests

* passtest

* fixshorttests

* mosttests

* improvingbasedockerfile

* testspeeds

* testing

* host

* canparallel

* clean

* passfullsuite

* singlepagemax

* test

* findfeatures

* findstables

* tbls

* tablestoo

* tablestoo

* lateraltests

* tableloc

* cleanup

* inlinetable

* childids

* cleanup

* tests
2025-04-22 14:40:16 +00:00

75 lines
1.6 KiB
Go

package database_test
import (
"context"
"testing"
"queryorchestration/internal/database/repository"
"queryorchestration/internal/serviceconfig"
"queryorchestration/internal/serviceconfig/database"
"queryorchestration/internal/test"
"github.com/jackc/pgx/v5/pgxpool"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestSetDBPool(t *testing.T) {
if testing.Short() {
t.Skip("Skipping long test in short mode")
}
ctx := context.Background()
cfg := &serviceconfig.BaseConfig{}
test.SetCfgProvider(t, cfg)
net := test.DepNetwork.Get(t, ctx)
_ = test.CreateDB(t, ctx, cfg, net, &test.CreateDatabaseConfig{
RunMigrations: true,
})
err := cfg.SetDBPool(ctx)
require.NoError(t, err)
assert.NotNil(t, cfg.GetDBPool())
}
func TestGetDBPoolConfig(t *testing.T) {
cfg := database.DBConfig{}
err := cfg.SetDBPoolConfig()
assert.Error(t, err)
assert.Nil(t, cfg.DBPoolConfig)
cfg.DBName = "name"
cfg.DBHost = "host"
cfg.DBPort = 123
cfg.DBUser = "user"
cfg.DBSecret = "pass"
err = cfg.SetDBPoolConfig()
require.NoError(t, err)
assert.NotNil(t, cfg.DBPoolConfig)
}
func TestGetDBPool(t *testing.T) {
cfg := database.DBConfig{}
pool := cfg.GetDBPool()
assert.Nil(t, pool)
cfg.DBPool = &pgxpool.Pool{}
pool = cfg.GetDBPool()
assert.NotNil(t, pool)
assert.Equal(t, pool, cfg.DBPool)
}
func TestGetDBQueries(t *testing.T) {
cfg := database.DBConfig{}
queries := cfg.GetDBQueries()
assert.Nil(t, queries)
cfg.DBQueries = repository.New(&pgxpool.Pool{})
queries = cfg.GetDBQueries()
assert.NotNil(t, queries)
assert.Equal(t, queries, cfg.DBQueries)
}