Documentation ¶
Overview ¶
Package dsunit - Datastore testing library.
Index ¶
- Constants
- Variables
- func AddTableMapping(t *testing.T, request *MappingRequest) bool
- func AddTableMappingFromURL(t *testing.T, URL string) bool
- func Expect(t *testing.T, request *ExpectRequest) bool
- func ExpectDatasets(t *testing.T, datastore string, checkPolicy int) bool
- func ExpectFor(t *testing.T, datastore string, checkPolicy int, baseDirectory string, ...) bool
- func ExpectFromURL(t *testing.T, URL string) bool
- func ExpectWithURL(t *testing.T, checkPolicy int, URL string, datastore string, ...) bool
- func GetDatastoreDialect(datastore string, registry dsc.ManagerRegistry) dsc.DatastoreDialect
- func Init(t *testing.T, request *InitRequest) bool
- func InitFromURL(t *testing.T, URL string) bool
- func Ping(t *testing.T, datastore string, timeoutMs int) bool
- func PopulateWithURL(t *testing.T, URL string, datastore string, datasets ...*Dataset) bool
- func Prepare(t *testing.T, request *PrepareRequest) bool
- func PrepareDatastore(t *testing.T, datastore string) bool
- func PrepareFor(t *testing.T, datastore string, baseDirectory string, method string) bool
- func PrepareFromURL(t *testing.T, URL string) bool
- func Recreate(t *testing.T, request *RecreateRequest) bool
- func RecreateDatastore(adminDatastore, targetDatastore string, registry dsc.ManagerRegistry) error
- func RecreateFromURL(t *testing.T, URL string) bool
- func Register(t *testing.T, request *RegisterRequest) bool
- func RegisterFromURL(t *testing.T, URL string) bool
- func RunSQL(t *testing.T, request *RunSQLRequest) bool
- func RunSQLFromURL(t *testing.T, URL string) bool
- func RunScript(t *testing.T, request *RunScriptRequest) bool
- func RunScriptFromURL(t *testing.T, URL string) bool
- func StartServer(port string)
- func UseRemoteTestServer(endpoint string)
- type BaseResponse
- type CheckSchemaRequest
- type CheckSchemaResponse
- type CompareRequest
- type CompareResponse
- type DatafileInfo
- type Dataset
- type DatasetResource
- type DatasetValidation
- type DatastoreDatasets
- type DatastoreSQL
- type DumpRequest
- type DumpResponse
- type ExpectRequest
- type ExpectResponse
- type FreezeRequest
- type FreezeResponse
- type InitRequest
- type InitResponse
- type Mapper
- type Mapping
- type MappingColumn
- type MappingRequest
- type MappingResponse
- type MappingTable
- type ModificationInfo
- type Obfuscation
- type ObfuscationMethod
- type PingRequest
- type PingResponse
- type PrepareRequest
- type PrepareResponse
- type QueryRequest
- type QueryResponse
- type Record
- func (r *Record) AsMap() map[string]interface{}
- func (r *Record) Columns() []string
- func (r *Record) HasColumn(column string) bool
- func (r *Record) IsEmpty() bool
- func (r *Record) SetValue(column string, value interface{})
- func (r *Record) String() string
- func (r *Record) Value(column string) interface{}
- func (r Record) ValueAsString(column string) string
- type Records
- func (r *Records) Autoincrement() bool
- func (r *Records) Columns() []string
- func (r *Records) Expand(context toolbox.Context, includeDirectives bool) (result []interface{}, err error)
- func (r *Records) FromQuery() (string, string)
- func (r *Records) ShouldDeleteAll() bool
- func (r *Records) UniqueKeys() []string
- type RecreateRequest
- type RecreateResponse
- type RegisterRequest
- type RegisterResponse
- type RunSQLRequest
- type RunSQLResponse
- type RunScriptRequest
- type SchemaTableCheck
- type SchemaTarget
- type SequenceRequest
- type SequenceResponse
- type Service
- type Tester
Constants ¶
const ( //FullTableDatasetCheckPolicy policy will drive comparison of all actual datastore data FullTableDatasetCheckPolicy = 0 //SnapshotDatasetCheckPolicy policy will drive comparison of subset of actual datastore data that is is listed in expected dataset SnapshotDatasetCheckPolicy = 1 )
const ( AutoincrementDirective = "@autoincrement@" FromQueryDirective = "@fromQuery@" FromQueryAliasDirective = "@fromQueryAlias@" )
const ( ObfuscationMethodReplace = "replace" ObfuscationMethodShuffle = "shuffle" ObfuscationMethodDictionary = "dictionary" ObfuscationMethodCipher = "cipher" )
const StatusOk = "ok"
StatusOk represents ok status
Variables ¶
var LogF = fmt.Printf
var SubstitutionMapKey = (*data.Map)(nil)
SubstitutionMapKey if provided in context, it will be used to substitute/expand dataset
Functions ¶
func AddTableMapping ¶ added in v0.1.1
func AddTableMapping(t *testing.T, request *MappingRequest) bool
AddTableMapping Add table mapping
func AddTableMappingFromURL ¶ added in v0.1.1
AddTableMappingFromURL Add table mapping, JSON request is fetched from URL
func Expect ¶ added in v0.1.1
func Expect(t *testing.T, request *ExpectRequest) bool
Expect Verify datastore with supplied expected datasets
func ExpectDatasets ¶
ExpectDatasets matches all dataset files that are located in the same directory as the test file with method name to verify that all listed dataset values are present in datastore
func ExpectFor ¶ added in v0.1.1
func ExpectFor(t *testing.T, datastore string, checkPolicy int, baseDirectory string, method string) bool
ExpectFor matches all dataset files that are located in baseDirectory with method name to verify that all listed dataset values are present in datastore Note the matchable dataset files in the base directory have the following naming:
<lower_underscore method name>_expect_<table>.[json|csv] To prepare expected dataset table: 'users' and 'permissions' for test method ReadAll you would have you create the following files in the baseDirectory read_all_expect_users.json read_all_expect_permissions.json
func ExpectFromURL ¶ added in v0.1.1
ExpectFromURL Verify datastore with supplied expected datasets, JSON request is fetched from URL
func ExpectWithURL ¶ added in v0.10.11
func ExpectWithURL(t *testing.T, checkPolicy int, URL string, datastore string, datasets ...*Dataset) bool
ExpectWithURL Verify datastore with supplied expected datasets, JSON requests are fetched from files in directory
func GetDatastoreDialect ¶ added in v0.1.1
func GetDatastoreDialect(datastore string, registry dsc.ManagerRegistry) dsc.DatastoreDialect
GetDatastoreDialect return GetDatastoreDialect for supplied datastore and registry.
func Init ¶ added in v0.1.1
func Init(t *testing.T, request *InitRequest) bool
Init datastore, (register, recreated, run sql, add mapping)
func InitFromURL ¶ added in v0.1.1
InitFromURL Init datastore, (register, recreated, run sql, add mapping), JSON request is fetched from URL
func PopulateWithURL ¶ added in v0.10.11
PopulateWithURL Populate database with datasets, JSON requests are fetched from files in directory
func Prepare ¶ added in v0.1.1
func Prepare(t *testing.T, request *PrepareRequest) bool
Prepare Populate database with datasets
func PrepareDatastore ¶
PrepareDatastore matches all dataset files that are in the same location as a test file, with the same test file prefix, followed by lowe camel case test name.
func PrepareFor ¶ added in v0.1.1
PrepareFor matches all dataset files that are located in baseDirectory with method name and populate datastore with all listed dataset Note the matchable dataset files in the base directory have the following naming:
<lower_underscore method name>_populate_<table>.[json|csv] To prepare dataset to populate datastore table: 'users' and 'permissions' for test method ReadAll you would have you create the following files in the baseDirectory read_all_prepare_travelers2.json read_all_populate_permissions.json
func PrepareFromURL ¶ added in v0.1.1
PrepareFromURL Populate database with datasets, JSON request is fetched from URL
func Recreate ¶ added in v0.1.1
func Recreate(t *testing.T, request *RecreateRequest) bool
Recreate recreates datastore
func RecreateDatastore ¶ added in v0.1.1
func RecreateDatastore(adminDatastore, targetDatastore string, registry dsc.ManagerRegistry) error
RecreateDatastore recreates target datastore from supplied admin datastore and registry
func RecreateFromURL ¶ added in v0.1.1
RecreateFromURL Recreate recreates datastore, JSON request is fetched from URL
func Register ¶ added in v0.1.1
func Register(t *testing.T, request *RegisterRequest) bool
Register registers new datastore connection
func RegisterFromURL ¶ added in v0.1.1
RegisterFromURL Register registers new datastore connection, JSON request is fetched from URL
func RunSQL ¶ added in v0.1.1
func RunSQL(t *testing.T, request *RunSQLRequest) bool
RunSQL runs supplied SQL
func RunSQLFromURL ¶ added in v0.1.1
RunSQLFromURL RunSQL runs supplied SQL, JSON request is fetched from URL
func RunScript ¶ added in v0.1.1
func RunScript(t *testing.T, request *RunScriptRequest) bool
RunScript runs supplied SQL scripts
func RunScriptFromURL ¶ added in v0.1.1
RunScriptFromURL RunScript runs supplied SQL scripts, JSON request is fetched from URL
func UseRemoteTestServer ¶
func UseRemoteTestServer(endpoint string)
UseRemoteTestServer enables remove testing mode
Types ¶
type BaseResponse ¶ added in v0.1.1
BaseResponse represent base response.
func NewBaseOkResponse ¶ added in v0.1.1
func NewBaseOkResponse() *BaseResponse
func NewBaseResponse ¶ added in v0.1.1
func NewBaseResponse(status, message string) *BaseResponse
func (BaseResponse) Error ¶ added in v0.1.1
func (r BaseResponse) Error() error
func (*BaseResponse) SetError ¶ added in v0.1.1
func (r *BaseResponse) SetError(err error)
type CheckSchemaRequest ¶ added in v0.10.0
type CheckSchemaRequest struct { Source *SchemaTarget Dest *SchemaTarget Tables []string CheckNullables bool CheckPrimaryKeys bool }
CheckSchemaRequest represents schema check request
type CheckSchemaResponse ¶ added in v0.10.0
type CheckSchemaResponse struct { *BaseResponse Tables []*SchemaTableCheck *assertly.Validation }
CheckSchemaResponse represents schema check response
func NewCheckSchemaResponse ¶ added in v0.10.0
func NewCheckSchemaResponse() *CheckSchemaResponse
NewCheckSchemaResponse returns new check schema response
type CompareRequest ¶ added in v0.4.1
type CompareRequest struct { Source1 *DatastoreSQL Source2 *DatastoreSQL Directives map[string]interface{} Ignore []string // columns to ignore OmitEmpty bool MaxRowDiscrepancy int //max discrepant rows }
CompareRequest represent compare request
func (*CompareRequest) ApplyDirective ¶ added in v0.4.1
func (r *CompareRequest) ApplyDirective(record map[string]interface{})
func (CompareRequest) IndexBy ¶ added in v0.4.1
func (r CompareRequest) IndexBy() []string
IndexBy returns index by directive if specified
func (*CompareRequest) Init ¶ added in v0.10.0
func (r *CompareRequest) Init() error
type CompareResponse ¶ added in v0.4.1
type CompareResponse struct { *BaseResponse Dataset1Count int Dataset2Count int MatchedRows int *assertly.Validation }
CompareResponse represents compare response
type DatafileInfo ¶ added in v0.1.1
DatafileInfo represent data file
func NewDatafileInfo ¶ added in v0.1.1
func NewDatafileInfo(filename, prefix, postfix string) *DatafileInfo
NewDatafileInfo returns new datafile info if supplied filedinfo matches prefix, postfix
type Dataset ¶
Records represent data records
func NewDataset ¶ added in v0.1.1
NewDataset creates a new dataset for supplied table and records.
type DatasetResource ¶
type DatasetResource struct { *url.Resource ` description:"data file location, csv, json, ndjson formats are supported"` *DatastoreDatasets `required:"true" description:"datastore datasets"` Prefix string ` description:"location data file prefix"` //apply prefix Postfix string ` description:"location data file postgix"` //apply suffix // contains filtered or unexported fields }
DatasetResource represents a dataset resource
func NewDatasetResource ¶ added in v0.1.1
func NewDatasetResource(datastore string, URL, prefix, postfix string, datasets ...*Dataset) *DatasetResource
func (*DatasetResource) Init ¶ added in v0.1.1
func (r *DatasetResource) Init() error
func (*DatasetResource) Load ¶ added in v0.1.1
func (r *DatasetResource) Load() (err error)
Loads dataset from specified resource or data map
type DatasetValidation ¶ added in v0.1.1
type DatasetValidation struct { Dataset string *assertly.Validation Expected interface{} Actual interface{} }
ExpectRequest represents data validation
type DatastoreDatasets ¶ added in v0.1.1
type DatastoreDatasets struct { Datastore string `required:"true" description:"register datastore"` Datasets []*Dataset `description:"collection of dataset per table"` Data map[string][]map[string]interface{} `description:"map, where each pair represent table name and records (backwad compatiblity)"` }
DatastoreDatasets represents a collection of datastore datasets
type DatastoreSQL ¶ added in v0.4.1
type DumpRequest ¶ added in v0.2.0
type DumpRequest struct { Datastore string `description:"registered datastore i.e. db1"` Tables []string `description:"tables, all if empty"` DestURL string `description:"represent dataset destination"` Target string `description:"target vendor, use only if different than source"` /* mapping url content should represents a map between source and dest data (all data type should be upper case) type i.e { "INT": "BIGINT", "INTEGER": "BIGINT", "NUMERIC": "DECIMAL(7,2)", "FLOAT": "DECIMAL(7,2)", "VARCHAR": "VARCHAR(255)", "STRING": "VARCHAR(255)", "CHAR": "VARCHAR(255)", "DATE": "DATE", "TIMESTAMP": "TIMESTAMP", }, */ MappingURL string `description:"if target driver is used - you can provide data type mapping"` }
DumpRequest represent a request to create a database schema
func NewDumpRequestFromURL ¶ added in v0.6.2
func NewDumpRequestFromURL(URL string) (*DumpRequest, error)
NewDumpRequestFromURL create a request from url
type DumpResponse ¶ added in v0.2.0
type DumpResponse struct { *BaseResponse Count int DestURL string }
DumpResponse represents a dump response
type ExpectRequest ¶ added in v0.1.1
type ExpectRequest struct { *DatasetResource CheckPolicy int `required:"true" description:"0 - FullTableDatasetCheckPolicy, 1 - SnapshotDatasetCheckPolicy"` }
ExpectRequest represents verification datastore request
func NewExpectRequest ¶ added in v0.1.1
func NewExpectRequest(checkPolicy int, resource *DatasetResource) *ExpectRequest
NewExpectRequest creates a new prepare request
func NewExpectRequestFromURL ¶ added in v0.1.1
func NewExpectRequestFromURL(URL string) (*ExpectRequest, error)
NewExpectRequestFromURL create a request from URL
func (*ExpectRequest) Validate ¶ added in v0.1.1
func (r *ExpectRequest) Validate() error
Validate checks if request is valid
type ExpectResponse ¶
type ExpectResponse struct { *BaseResponse Validation []*DatasetValidation PassedCount int FailedCount int }
ExpectResponse represents verification response
type FreezeRequest ¶ added in v0.1.1
type FreezeRequest struct { Datastore string `description:"registered datastore i.e. db1"` SQL string `description:"dataset SQL soruce"` DestURL string `description:"represent dataset destination"` OmitEmpty bool `description:"flag to skip empty attributes"` Ignore []string `description:"path to ignore i.e. request.postbody"` Replace map[string]string `description:"key of path with corresponding replacement value"` LocationTimezone string `description:"convert time to specified timezone i.e UTC"` Override map[string]string `description:"overrides column with supplied values"` ASCII []string `description:"column values to be ascii sanitized"` RelativeDate []string `description:"transform date to date expr"` Obfuscation []Obfuscation `description:"obfuscation rules"` Reset bool `description:"add extra empty record to truncate before inserting"` TimeFormat string `description:"java/ios based time format"` TimeLayout string `description:"golang based time layout"` }
FreezeRequest represent a request to create a data set from datastore for provided SQL and target path
func (*FreezeRequest) Init ¶ added in v0.2.1
func (r *FreezeRequest) Init() error
type FreezeResponse ¶ added in v0.1.1
type FreezeResponse struct { *BaseResponse Count int DestURL string }
FreezeResponse response
type InitRequest ¶ added in v0.1.1
type InitRequest struct { Datastore string Recreate bool *RegisterRequest Admin *RegisterRequest *MappingRequest *RunScriptRequest }
InitRequest represents datastore init request, it actual aggregates, registraction, recreation, mapping and run script request
func NewInitRequest ¶ added in v0.1.1
func NewInitRequest(datastore string, recreate bool, register, admin *RegisterRequest, mapping *MappingRequest, script *RunScriptRequest) *InitRequest
NewInitRequest creates a new database init request
func NewInitRequestFromURL ¶ added in v0.1.1
func NewInitRequestFromURL(URL string) (*InitRequest, error)
NewInitRequestFromURL create a request from URL
func (*InitRequest) Init ¶ added in v0.1.1
func (r *InitRequest) Init() (err error)
func (*InitRequest) Validate ¶ added in v0.1.1
func (r *InitRequest) Validate() error
type InitResponse ¶ added in v0.1.1
type InitResponse struct { *BaseResponse Tables []string }
InitResponse represent init datastore response
type Mapping ¶ added in v0.1.1
type Mapping struct { *url.Resource *MappingTable Name string `required:"true" description:"mapping name (i.e view name)"` }
Mapping represents mapping
type MappingColumn ¶ added in v0.1.1
type MappingColumn struct { Name string `required:"true" description:"column name"` DefaultValue string FromColumn string `description:"if specified it defined value source for this column"` Required bool `description:"table record will be mapped if values for all required columns are present"` Unique bool `description:"flag key/s that are unique"` }
MappingColumn represents column with its source definition.
type MappingRequest ¶ added in v0.1.1
type MappingRequest struct {
Mappings []*Mapping `required:"true" description:"virtual table mapping"`
}
MappingRequest represnet a mapping request
func NewMappingRequest ¶ added in v0.1.1
func NewMappingRequest(mappings ...*Mapping) *MappingRequest
NewMappingRequest creates new mapping request
func NewMappingRequestFromURL ¶ added in v0.1.1
func NewMappingRequestFromURL(URL string) (*MappingRequest, error)
NewMappingRequestFromURL create a request from URL
func (*MappingRequest) Init ¶ added in v0.1.1
func (r *MappingRequest) Init() (err error)
Init init request
func (*MappingRequest) Validate ¶ added in v0.1.1
func (r *MappingRequest) Validate() error
type MappingResponse ¶ added in v0.1.1
type MappingResponse struct { *BaseResponse Tables []string }
MappingResponse represents mapping response
type MappingTable ¶ added in v0.1.1
type MappingTable struct { Table string `required:"true"` Columns []*MappingColumn `required:"true"` Associations []*MappingTable }
MappingTable represents a table mapping, mapping allow to route data defined in only one table to many tables.
type ModificationInfo ¶ added in v0.1.1
type ModificationInfo struct { Subject string Method string `description:"modification method determined by presence of primary key: load - insert, persist: insert or update"` Deleted int Modified int Added int }
ModificationInfo represents a modification info
type Obfuscation ¶ added in v0.10.11
type Obfuscation struct { Columns []string Method ObfuscationMethod DictionaryURL string Dictionary []string Key *kms.Key IDKey string Template string }
func (*Obfuscation) Init ¶ added in v0.10.11
func (o *Obfuscation) Init(ctx context.Context)
type ObfuscationMethod ¶ added in v0.10.11
type ObfuscationMethod string
type PingRequest ¶ added in v0.7.0
PingRequest represents ping request
type PingResponse ¶ added in v0.7.0
type PingResponse struct {
*BaseResponse
}
PingResponse represents a ping response
type PrepareRequest ¶ added in v0.1.1
type PrepareRequest struct { Expand bool `description:"substitute $ expression with content of context.state"` *DatasetResource `required:"true" description:"datasets resource"` }
PrepareRequest represents a request to populate datastore with data resource
func NewPrepareRequest ¶ added in v0.1.1
func NewPrepareRequest(resource *DatasetResource) *PrepareRequest
NewPrepareRequest creates a new prepare request
func NewPrepareRequestFromURL ¶ added in v0.1.1
func NewPrepareRequestFromURL(URL string) (*PrepareRequest, error)
NewPrepareRequestFromURL create a request from URL
func (*PrepareRequest) Validate ¶ added in v0.1.1
func (r *PrepareRequest) Validate() error
Validate checks if request is valid
type PrepareResponse ¶ added in v0.1.1
type PrepareResponse struct { *BaseResponse Expand bool `description:"substitute $ expression with content of context.state"` Modification map[string]*ModificationInfo `description:"modification info by subject"` }
PrepareResponse represents a prepare response
type QueryRequest ¶ added in v0.1.1
type QueryRequest struct { Datastore string SQL string IgnoreError bool Expect []map[string]interface{} `description:"if specified validation would take place"` }
QueryRequest represents get sequences request
func NewQueryRequest ¶ added in v0.1.1
func NewQueryRequest(datastore, SQL string) *QueryRequest
type QueryResponse ¶ added in v0.1.1
type QueryResponse struct { *BaseResponse Records Records *assertly.Validation }
QueryResponse represents get sequences response
type Record ¶ added in v0.1.1
type Record map[string]interface{}
func (*Record) HasColumn ¶ added in v0.1.1
HasColumn returns true if this row has passed in column value.
func (Record) ValueAsString ¶ added in v0.1.1
ValueAsString returns column value as string.
type Records ¶ added in v0.1.1
type Records []map[string]interface{}
Records represents table records
func (*Records) Autoincrement ¶ added in v0.1.1
PrimaryKey returns primary key directive if matched in the following order: @Autoincrement@, @IndexBy@
func (*Records) Expand ¶ added in v0.1.1
func (r *Records) Expand(context toolbox.Context, includeDirectives bool) (result []interface{}, err error)
Records returns non empty records //directive a filtered out
func (*Records) ShouldDeleteAll ¶ added in v0.1.1
ShouldDeleteAll checks if dataset contains empty record (indicator to delete all)
func (*Records) UniqueKeys ¶ added in v0.1.1
UniqueKeys returns value for unique key directive, it test keys in the following order: @Autoincrement@, @IndexBy@
type RecreateRequest ¶ added in v0.1.1
type RecreateRequest struct { Datastore string `` /* 157-byte string literal not displayed */ AdminDatastore string `description:"database used to run DDL"` }
RecreateRequest represent recreate datastore request
func NewRecreateRequest ¶ added in v0.1.1
func NewRecreateRequest(datastore, adminDatastore string) *RecreateRequest
NewRecreateRequest create new recreate request
func NewRecreateRequestFromURL ¶ added in v0.1.1
func NewRecreateRequestFromURL(URL string) (*RecreateRequest, error)
NewRecreateRequestFromURL create a request from URL
type RecreateResponse ¶ added in v0.1.1
type RecreateResponse struct {
*BaseResponse
}
RecreateResponse represents recreate datastore response
type RegisterRequest ¶ added in v0.1.1
type RegisterRequest struct { Datastore string `required:"true" description:"datastore name"` Config *dsc.Config `description:"datastore config"` ConfigURL string `description:"datastore config URL"` Tables []*dsc.TableDescriptor `description:"optional table descriptors"` PingRequest `json:",inline" yaml:",inline"` Ping bool `description:"flag to wait for database get online"` }
RegisterRequest represent register request
func NewRegisterRequest ¶ added in v0.1.1
func NewRegisterRequest(datastore string, config *dsc.Config, tables ...*dsc.TableDescriptor) *RegisterRequest
NewRegisterRequest create new register request
func NewRegisterRequestFromURL ¶ added in v0.1.1
func NewRegisterRequestFromURL(URL string) (*RegisterRequest, error)
func (*RegisterRequest) Init ¶ added in v0.1.1
func (r *RegisterRequest) Init() (err error)
func (*RegisterRequest) Validate ¶ added in v0.1.1
func (r *RegisterRequest) Validate() error
type RegisterResponse ¶ added in v0.1.1
type RegisterResponse struct {
*BaseResponse
}
RegisterResponse represents register response
type RunSQLRequest ¶ added in v0.1.1
type RunSQLRequest struct { Datastore string `required:"true" description:"registered datastore name"` Expand bool `description:"substitute $ expression with content of context.state"` SQL []string }
RunSQLRequest represents run SQL request
func NewRunSQLRequest ¶ added in v0.1.1
func NewRunSQLRequest(datastore string, SQL ...string) *RunSQLRequest
NewRunSQLRequest creates new run SQL request
func NewRunSQLRequestFromURL ¶ added in v0.1.1
func NewRunSQLRequestFromURL(URL string) (*RunSQLRequest, error)
NewRunSQLRequestFromURL create a request from URL
type RunSQLResponse ¶ added in v0.1.1
type RunSQLResponse struct { *BaseResponse RowsAffected int }
RunSQLRequest represents run SQL response
type RunScriptRequest ¶ added in v0.1.1
type RunScriptRequest struct { Datastore string `required:"true" description:"registered datastore name"` Expand bool `description:"substitute $ expression with content of context.state"` Scripts []*dsurl.Resource }
RunScriptRequest represents run SQL Script request
func NewRunScriptRequest ¶ added in v0.1.1
func NewRunScriptRequest(datastore string, scripts ...*dsurl.Resource) *RunScriptRequest
NewRunScriptRequest creates new run script request
func NewRunScriptRequestFromURL ¶ added in v0.1.1
func NewRunScriptRequestFromURL(URL string) (*RunScriptRequest, error)
NewRunScriptRequestFromURL create a request from URL
type SchemaTableCheck ¶ added in v0.10.0
type SchemaTableCheck struct { Table string *assertly.Validation }
type SchemaTarget ¶ added in v0.10.0
type SequenceRequest ¶ added in v0.1.1
SequenceRequest represents get sequences request
func NewSequenceRequest ¶ added in v0.1.1
func NewSequenceRequest(datastore string, tables ...string) *SequenceRequest
type SequenceResponse ¶ added in v0.1.1
type SequenceResponse struct { *BaseResponse Sequences map[string]int }
SequenceResponse represents get sequences response
type Service ¶
type Service interface { //registry returns registry of registered database managers Registry() dsc.ManagerRegistry //Register registers new datastore connection Register(request *RegisterRequest) *RegisterResponse //Recreate remove and creates datastore Recreate(request *RecreateRequest) *RecreateResponse //RunSQL runs supplied SQL RunSQL(request *RunSQLRequest) *RunSQLResponse //RunScript runs supplied SQL scripts RunScript(request *RunScriptRequest) *RunSQLResponse //Add table mapping AddTableMapping(request *MappingRequest) *MappingResponse //Init datastore, (register, recreated, run sql, add mapping) Init(request *InitRequest) *InitResponse //Populate database with datasets Prepare(request *PrepareRequest) *PrepareResponse //Verify datastore with supplied expected datasets Expect(request *ExpectRequest) *ExpectResponse //Query returns query from database Query(request *QueryRequest) *QueryResponse //Sequence returns sequence for supplied tables Sequence(request *SequenceRequest) *SequenceResponse //Freeze creates a dataset from existing database/datastore (reverse engineering test setup/verification) Freeze(request *FreezeRequest) *FreezeResponse //Dump creates a database schema from existing database for supplied tables, datastore Dump(request *DumpRequest) *DumpResponse //Compare compares data produces by specified SQLs Compare(request *CompareRequest) *CompareResponse //CheckSchema checks source and dest schema CheckSchema(request *CheckSchemaRequest) *CheckSchemaResponse //Ping waits until if database is online or error Ping(request *PingRequest) *PingResponse SetContext(context toolbox.Context) }
Service represents test service
func NewServiceClient ¶
NewServiceClient returns a new dsunit service client
type Tester ¶ added in v0.1.1
type Tester interface { // Register registers new datastore connection Register(t *testing.T, request *RegisterRequest) bool // RegisterFromURL registers new datastore connection, JSON request is fetched from URL RegisterFromURL(t *testing.T, URL string) bool // Recreate recreates datastore Recreate(t *testing.T, request *RecreateRequest) bool // RecreateFromURL recreates datastore, JSON request is fetched from URL RecreateFromURL(t *testing.T, URL string) bool // RunSQL runs supplied SQL RunSQL(t *testing.T, request *RunSQLRequest) bool // RunSQLFromURL runs supplied SQL, JSON request is fetched from URL RunSQLFromURL(t *testing.T, URL string) bool // RunScript runs supplied SQL scripts RunScript(t *testing.T, request *RunScriptRequest) bool // RunScriptFromURL runs supplied SQL scripts, JSON request is fetched from URL RunScriptFromURL(t *testing.T, URL string) bool // AddTableMapping adds table mapping AddTableMapping(t *testing.T, request *MappingRequest) bool // AddTableMappingFromURL adds table mapping, JSON request is fetched from URL AddTableMappingFromURL(t *testing.T, URL string) bool //Init inits datastore, (register, recreated, run sql, add mapping) Init(t *testing.T, request *InitRequest) bool // InitFromURL inits datastore, (register, recreated, run sql, add mapping), JSON request is fetched from URL InitFromURL(t *testing.T, URL string) bool // Prepare populates database with datasets Prepare(t *testing.T, request *PrepareRequest) bool // PrepareFromURL populates database with datasets, JSON request is fetched from URL PrepareFromURL(t *testing.T, URL string) bool // PopulateWithURL populates database with datasets, JSON requests are fetched from files in directory PopulateWithURL(t *testing.T, URL string, datastore string, datasets ...*Dataset) bool //PrepareDatastore matches all dataset files that are in the same location as a test file, with the same test file prefix, followed by lowe camel case test name. PrepareDatastore(t *testing.T, datastore string) bool // PrepareFor matches all dataset files that are located in baseDirectory with method name and // populate datastore with all listed dataset // Note the matchable dataset files in the base directory have the following naming: // // <lower_underscore method name>_populate_<table>.[json|csv] // To prepare dataset to populate datastore table: 'users' and 'permissions' for test method ReadAll you would // have you create the following files in the baseDirectory // // read_all_prepare_travelers2.json // read_all_populate_permissions.json // PrepareFor(t *testing.T, datastore string, baseDirectory string, method string) bool // Expect verifies datastore with supplied expected datasets Expect(t *testing.T, request *ExpectRequest) bool // ExpectFromURL verifies datastore with supplied expected datasets, JSON request is fetched from URL ExpectFromURL(t *testing.T, URL string) bool // ExpectWithURL verifies datastore with supplied expected datasets, JSON requests are fetched from files in directory ExpectWithURL(t *testing.T, checkPolicy int, URL string, datastore string, datasets ...*Dataset) bool // ExpectDatasets matches all dataset files that are located in the same directory as the test file with method name to // verify that all listed dataset values are present in datastore ExpectDatasets(t *testing.T, datastore string, checkPolicy int) bool // ExpectFor matches all dataset files that are located in baseDirectory with method name to // verify that all listed dataset values are present in datastore // Note the matchable dataset files in the base directory have the following naming: // // <lower_underscore method name>_expect_<table>.[json|csv] // To prepare expected dataset table: 'users' and 'permissions' for test method ReadAll you would // have you create the following files in the baseDirectory // // read_all_expect_users.json // read_all_expect_permissions.json // ExpectFor(t *testing.T, datastore string, checkPolicy int, baseDirectory string, method string) bool // Ping waits until database is online or error Ping(t *testing.T, datastore string, timeoutMs int) bool }
func NewRemoveTester ¶ added in v0.1.1
NewRemoveTester creates a new remove tester