This repository has been archived on 2022-08-17. You can view files and clone it, but cannot push or open issues or pull requests.
dex/storage/sql/postgres_test.go

66 lines
1.5 KiB
Go
Raw Permalink Normal View History

//go:build go1.11
// +build go1.11
package sql
import (
"os"
2019-12-06 21:19:30 +05:30
"strconv"
"testing"
)
func TestPostgresTunables(t *testing.T) {
host := os.Getenv(testPostgresEnv)
if host == "" {
t.Skipf("test environment variable %q not set, skipping", testPostgresEnv)
}
2019-12-06 21:19:30 +05:30
port := uint64(5432)
if rawPort := os.Getenv("DEX_POSTGRES_PORT"); rawPort != "" {
var err error
port, err = strconv.ParseUint(rawPort, 10, 32)
if err != nil {
t.Fatalf("invalid postgres port %q: %s", rawPort, err)
}
}
baseCfg := &Postgres{
NetworkDB: NetworkDB{
Database: getenv("DEX_POSTGRES_DATABASE", "postgres"),
User: getenv("DEX_POSTGRES_USER", "postgres"),
Password: getenv("DEX_POSTGRES_PASSWORD", "postgres"),
Host: host,
2019-12-06 21:19:30 +05:30
Port: uint16(port),
},
SSL: SSL{
Mode: pgSSLDisable, // Postgres container doesn't support SSL.
},
}
t.Run("with nothing set, uses defaults", func(t *testing.T) {
cfg := *baseCfg
c, err := cfg.open(logger)
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)
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)
}
})
}