Documentation ¶
Overview ¶
Package mssql provides a Gnomock Preset for Microsoft SQL Server database
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Preset ¶
Preset creates a new Gmomock Microsoft SQL Server preset. This preset includes a mssql specific healthcheck function, default mssql image and port, and allows to optionally set up initial state. When used without any configuration, it uses "mydb" database, and "Gn0m!ck~" administrator password (user: sa). You must accept EULA to use this image (WithLicense option)
Example ¶
package main import ( "database/sql" "fmt" "github.com/orlangure/gnomock" mockmssql "github.com/orlangure/gnomock-mssql" ) func main() { queries := ` create table t(a int); insert into t (a) values (1); insert into t (a) values (2); ` query := `insert into t (a) values (3);` p := mockmssql.Preset( mockmssql.WithLicense(true), mockmssql.WithAdminPassword("Passw0rd-"), mockmssql.WithQueries(queries, query), mockmssql.WithDatabase("foobar"), ) container, err := gnomock.Start(p) defer func() { _ = gnomock.Stop(container) }() if err != nil { panic(err) } addr := container.DefaultAddress() connStr := fmt.Sprintf("sqlserver://sa:Passw0rd-@%s?database=foobar", addr) db, err := sql.Open("sqlserver", connStr) if err != nil { panic(err) } var max, avg, min, count float64 rows := db.QueryRow("select max(a), avg(a), min(a), count(a) from t") err = rows.Scan(&max, &avg, &min, &count) if err != nil { panic(err) } fmt.Println("max", 3) fmt.Println("avg", 2) fmt.Println("min", 1) fmt.Println("count", 3) }
Output: max 3 avg 2 min 1 count 3
Types ¶
type Option ¶
type Option func(*P)
Option is an optional configuration of this Gnomock preset. Use available Options to configure the container
func WithAdminPassword ¶
WithAdminPassword sets administrator password that can be used to connect (default: Gn0m!ck~)
func WithDatabase ¶
WithDatabase creates a database with the provided name in the container. If not provided, "mydb" is used by default. WithQueries, if provided, runs against the new database
func WithLicense ¶
WithLicense sets EULA acceptance state. To accept the license, use true. See https://hub.docker.com/_/microsoft-mssql-server?tab=description for more information
func WithQueries ¶
WithQueries executes the provided queries against the database created with WithDatabase, or against default "mydb" database
func WithQueriesFile ¶ added in v0.1.1
WithQueriesFile sets a file name to read initial queries from. Queries from this file are executed before any other queries provided in WithQueries
type P ¶ added in v0.1.1
type P struct { DB string `json:"db"` Password string `json:"password"` Queries []string `json:"queries"` QueriesFile string `json:"queries_file"` License bool `json:"license"` }
P is a Gnomock Preset implementation of Microsoft SQL Server database
func (*P) Image ¶ added in v0.1.1
Image returns an image that should be pulled to create this container
func (*P) Ports ¶ added in v0.1.1
func (p *P) Ports() gnomock.NamedPorts
Ports returns ports that should be used to access this container