test

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jan 20, 2021 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MockK8sName      = "281cb030-9d56-48fa-b433-57237c9e1188"
	MockOutputUser   = "testuser"
	MockOutputPass   = "testpass"
	MockOutputDbName = "mydbtest281cb030" // DbNamePrefix + the first 8 chars of MockK8sName

	// Testing stored procedure-specific values
	DbNamePrefix   = "mydbtest"
	LeftTrimLength = "8"

	// TODO: Check that stored procedure is idempotent, i.e. it returns the correct username and password depending on
	// the k8sName, and not always the same
	CreateSp = `create proc sp_create (@` + opInputK8sName + ` varchar(max), @` + opOutputUser +
		` varchar(max) OUTPUT, @` + opOutputPass + ` varchar(max) OUTPUT, @` + opOutputDbName + ` varchar(max) OUTPUT)
					as
					declare @sql varchar(max)
					declare @tempDbName varchar(max)	
					set @tempDbName=CONCAT('` + DbNamePrefix + `', (SELECT LEFT(CONVERT(varchar(255), @k8sName),` + LeftTrimLength + `)))
					IF COUNT((DB_ID(@tempDbName))) = 0 
						BEGIN
							set @sql = CONCAT('create database ',@tempDbName)
							exec (@sql)
						END
					select @username='` + MockOutputUser + `',@password='` + MockOutputPass + `',@dbName='` + MockOutputDbName + `'`

	DeleteSp = `create proc sp_delete (@` + opInputK8sName + ` varchar(max))
					as
					declare @sql varchar(max)
					declare @dbname varchar(255)
					set @dbname=CONCAT('` + DbNamePrefix + `', (SELECT LEFT(CONVERT(varchar(255), @k8sName),8)))
					IF COUNT((DB_ID(@dbname))) > 0 
						BEGIN
							set @sql = CONCAT('drop database ',@dbname)
							exec (@sql)
						END`
)
View Source
const (
	SqlServerDriver = "sqlserver"
)

Variables

This section is empty.

Functions

func FormatContainerTeardownError

func FormatContainerTeardownError(err error) error

func FormatDockerContainerError

func FormatDockerContainerError(err error) error

func FormatDockerPoolError

func FormatDockerPoolError(err error) error

func FormatSqlServerContainerSetupError

func FormatSqlServerContainerSetupError(err error) error

func GetMockEndpoints

func GetMockEndpoints(dsnSlice []database.Dsn) []database.Endpoint

func GetMockOps

func GetMockOps() map[string]database.Operation

func GetRootProjectPath

func GetRootProjectPath() (string, error)

GetRootProjectPath is a utility function which gets the root project path based on the location of the main.go file. Do not move main.go in a place other than the root project path.

func GetTestdataFolderPath

func GetTestdataFolderPath() (string, error)

func GetUnexportedField

func GetUnexportedField(field reflect.Value) interface{}

func RunSqlServerContainer

func RunSqlServerContainer(dockerPool *dockertest.Pool) (database.Dsn, *sql.DB, *dockertest.Resource, error)

RunSqlServerContainer creates a new docker container running on dockerPool.

func SetupSingleSqlServerContainer

func SetupSingleSqlServerContainer() (database.Dsn, *sql.DB, *dockertest.Resource, error)

SetupSingleSqlServerContainer provisions a single sql server container

func TeardownContainer

func TeardownContainer(resource *dockertest.Resource) error

TeardownContainer purges a container and linked volumes from docker.

Types

This section is empty.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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