721ca8a6e6
Dockerfile in Test * dockerfile * network * const
72 lines
1.5 KiB
Go
72 lines
1.5 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.SkipNow()
|
|
}
|
|
ctx := context.Background()
|
|
|
|
cfg := &serviceconfig.BaseConfig{}
|
|
net := test.GetNetwork(t, ctx)
|
|
_ = test.CreateDB(t, ctx, cfg, net, &test.CreateDatabaseConfig{})
|
|
|
|
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)
|
|
}
|