Files
query-orchestration/internal/serviceconfig/database/pool_test.go
T
Jay Brown 15adaebfcd Merged in feature/serviceconfig-integration (pull request #38)
DRAFT PR : WIP working through ideas for integration

* movearound

* attempttwo

* openapi

* further sanding

* fix

* start on tests

* runthroughsingleconfig

* somechanges

* reflectissue

* removeerrs

* mostlyremovepanic

* removeenv

* noncfgtests

* go

* repo

* fix service config test

* add PWD to all

* test fix

* fix lint

* todo for later

* passingunittests

* alltests

* testlogger

* testloggername

* clean
2025-01-31 13:43:55 +00:00

76 lines
1.6 KiB
Go

package database_test
import (
"context"
"os"
"path"
"queryorchestration/internal/database/repository"
"queryorchestration/internal/serviceconfig"
"queryorchestration/internal/serviceconfig/database"
"queryorchestration/internal/test"
"testing"
"github.com/jackc/pgx/v5/pgxpool"
"github.com/stretchr/testify/assert"
)
func TestSetDBPool(t *testing.T) {
if testing.Short() {
t.Skip("Skipping long test in short mode")
}
ctx := context.Background()
t.Setenv("BASE_PATH", path.Join(os.Getenv("PWD"), "../../.."))
cfg := &serviceconfig.BaseConfig{}
_, cleanup := test.CreateDB(t, ctx, &test.CreateDatabaseConfig{
Cfg: cfg,
RunMigrations: true,
})
defer cleanup()
err := cfg.SetDBPool(ctx)
assert.NoError(t, err)
assert.NotNil(t, cfg.DBPool)
}
func TestGetDBPoolConfig(t *testing.T) {
cfg := database.BaseConfig{}
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()
assert.NoError(t, err)
assert.NotNil(t, cfg.DBPoolConfig)
}
func TestGetDBPool(t *testing.T) {
cfg := database.BaseConfig{}
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.BaseConfig{}
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)
}