sqlserver_test

package
v0.11.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 13, 2026 License: AGPL-3.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetSQLServerConfig

func GetSQLServerConfig() neat.DBConfig

GetSQLServerConfig builds a neat.DBConfig for SQL Server from environment variables. It reads the following variables with the shown defaults:

  • SQLSERVER_HOST (default: 127.0.0.1)
  • SQLSERVER_PORT (default: 1433)
  • SQLSERVER_DATABASE (default: test)
  • SQLSERVER_USER (default: sa)
  • SQLSERVER_PASS (default: YourStrong@Passw0rd)

The returned config uses "sqlserver" as the default connection name and applies sensible connection-pool defaults (5 idle / 10 open connections, 1-hour lifetimes).

func SetupSQLServerConnection

func SetupSQLServerConnection(t *testing.T) *database.Database

SetupSQLServerConnection returns a bare SQL Server connection without creating tables or seeding data. It is intended for connection-level tests (e.g. pool settings, connection switching) that need a live database but manage their own schema.

Like SetupSQLServerTest it uses a two-step connection strategy: it first connects to "master" to create the test database if absent, then returns a connection scoped to that test database. The connection is closed automatically via t.Cleanup.

func SetupSQLServerTest

func SetupSQLServerTest(t *testing.T) *database.Database

SetupSQLServerTest sets up a fully initialised SQL Server connection for integration tests.

SQL Server containers (e.g. via Docker Compose) start with only the system databases (master, model, msdb, tempdb) present. Unlike MySQL/Postgres, they do not automatically create user databases from environment variables. This function therefore uses a two-step connection strategy:

  1. Connect to the "master" system database (which always exists) and create the test database if it does not already exist using an idempotent IF NOT EXISTS guard.
  2. Connect directly to the test database, create the required test tables, and truncate any pre-existing data so each test begins with a clean slate.

The database connection is registered with t.Cleanup so it is closed automatically when the test (or sub-test) finishes.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL