73fdf4f75b
- adapted TestUnmarshalConfig to ensure the fields are read in - added a test to see that at least MaxOpenConns works: - this is only exposed through (*db).Stats() in go 1.11, so this test has a build tag - the other two configurables can't be read back, so we've got to trust that the mechanism works given the one instance that's tested.. Signed-off-by: Stephan Renatus <srenatus@chef.io>
48 lines
1.3 KiB
Go
48 lines
1.3 KiB
Go
// +build go1.11
|
|
|
|
package sql
|
|
|
|
import (
|
|
"os"
|
|
"testing"
|
|
)
|
|
|
|
func TestPostgresTunables(t *testing.T) {
|
|
host := os.Getenv(testPostgresEnv)
|
|
if host == "" {
|
|
t.Skipf("test environment variable %q not set, skipping", testPostgresEnv)
|
|
}
|
|
baseCfg := &Postgres{
|
|
Database: getenv("DEX_POSTGRES_DATABASE", "postgres"),
|
|
User: getenv("DEX_POSTGRES_USER", "postgres"),
|
|
Password: getenv("DEX_POSTGRES_PASSWORD", "postgres"),
|
|
Host: host,
|
|
SSL: PostgresSSL{
|
|
Mode: sslDisable, // Postgres container doesn't support SSL.
|
|
}}
|
|
|
|
t.Run("with nothing set, uses defaults", func(t *testing.T) {
|
|
cfg := *baseCfg
|
|
c, err := cfg.open(logger, cfg.createDataSourceName())
|
|
if err != nil {
|
|
t.Fatalf("error opening connector: %s", err.Error())
|
|
}
|
|
defer c.db.Close()
|
|
if m := c.db.Stats().MaxOpenConnections; m != 5 {
|
|
t.Errorf("expected MaxOpenConnections to have its default (5), got %d", m)
|
|
}
|
|
})
|
|
|
|
t.Run("with something set, uses that", func(t *testing.T) {
|
|
cfg := *baseCfg
|
|
cfg.MaxOpenConns = 101
|
|
c, err := cfg.open(logger, cfg.createDataSourceName())
|
|
if err != nil {
|
|
t.Fatalf("error opening connector: %s", err.Error())
|
|
}
|
|
defer c.db.Close()
|
|
if m := c.db.Stats().MaxOpenConnections; m != 101 {
|
|
t.Errorf("expected MaxOpenConnections to be set to 101, got %d", m)
|
|
}
|
|
})
|
|
}
|