Documentation
¶
Overview ¶
Package dsunit - Datastore testing library.
Index ¶
- Constants
- Variables
- func ExecuteScriptFromURL(t *testing.T, url string)
- func ExpandTestProtocolAsPathIfNeeded(input string) string
- func ExpandTestProtocolAsURLIfNeeded(input string) string
- func ExpectDatasetFor(t *testing.T, datastore string, checkPolicy int, baseDirectory string, ...)
- func ExpectDatasets(t *testing.T, datastore string, checkPolicy int)
- func InitDatastoreFromURL(t *testing.T, url string)
- func ParseColumnarData(reader io.Reader, separator string) ([]string, [][]interface{})
- func ParseSQLScript(reader io.Reader) []string
- func PrepareDatastore(t *testing.T, datastore string)
- func PrepareDatastoreFor(t *testing.T, datastore string, baseDirectory string, method string)
- func SetService(service Service)
- func StartServer(port string)
- func UseRemoteTestServer(serverURL string)
- type AssertViolation
- type AssertViolations
- type Dataset
- type DatasetColumn
- type DatasetFactory
- type DatasetMapping
- type DatasetResource
- type DatasetTestManager
- type DatasetTester
- type DatasetTransformer
- type Datasets
- type DatastoreConfig
- type DatastoreDatasetProvider
- type DatastoreDatasetSnapshotManager
- type ExecuteScriptRequest
- type ExpectDatasetRequest
- type ExpectResponse
- type InitDatastoreRequest
- type PrepareDatastoreRequest
- type Response
- type Row
- type Script
- type Service
- type TableRows
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 ( //ViolationTypeInvalidRowCount 'InvalidRowCount' constant used to report rows discrepancy between expected and actual dataset table. ViolationTypeInvalidRowCount = "InvalidRowCount" //ViolationTypeMissingActualRow 'AssertionMissingActualRow' constant used to report missing actual row. ViolationTypeMissingActualRow = "AssertionMissingActualRow" //ViolationTypeRowNotEqual 'AssertionRowNotEqual; constant used to report difference in values in the expected and actual row. ViolationTypeRowNotEqual = "AssertionRowNotEqual" )
Variables ¶
var TestSchema = "test://"
TestSchema constant test:// - it is used as shortcut for the test base directory.
Functions ¶
func ExecuteScriptFromURL ¶
ExecuteScriptFromURL executes script from URL, URL should point to ExecuteScriptRequest JSON.
func ExpandTestProtocolAsPathIfNeeded ¶
ExpandTestProtocolAsPathIfNeeded extends input if it start with test:// fragment to currently test file directory
func ExpandTestProtocolAsURLIfNeeded ¶
ExpandTestProtocolAsUrlIfNeeded extends input if it start with test:// fragment to currently test file directory as file protocol
func ExpectDatasetFor ¶
func ExpectDatasetFor(t *testing.T, datastore string, checkPolicy int, baseDirectory string, method string)
ExpectDatasetFor matches all dataset files that are located in baseDirectory with method name and verifies 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 ExpectDatasets ¶
ExpectDatasets matches all dataset files that are located in the same directory as the test file with method name and verifies that all listed dataset values are present in datastore
func InitDatastoreFromURL ¶
InitDatastoreFromURL initialises datastore from URL, URL needs to point to InitDatastoreRequest JSON it register datastore, table descriptor, data mapping, and optionally recreate datastore
func ParseColumnarData ¶
func ParseSQLScript ¶
parseSQLScript parses sql script and breaks it down to submittable sql statements
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 PrepareDatastoreFor ¶
PrepareDatastoreFor 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 UseRemoteTestServer ¶
func UseRemoteTestServer(serverURL string)
UseRemoteTestServer this method changes service to run all operation remotely using passed in URL.
Types ¶
type AssertViolation ¶
type AssertViolation struct {
Datastore string
Type string
Table string
Key string
Expected string
Actual string
Source string
Path string
}
AssertViolation represents test violation.
type AssertViolations ¶
type AssertViolations interface {
Violations() []*AssertViolation
HasViolations() bool
String() string
}
AssertViolations represents a test violations.
func NewAssertViolations ¶
func NewAssertViolations(violations []*AssertViolation) AssertViolations
NewAssertViolations creates a new instance of AssertViolations
type Dataset ¶
type Dataset struct {
*dsc.TableDescriptor
Rows []*Row
}
Dataset represents test or expected dataset data values
func (*Dataset) AsMapArray ¶
AsMapArray returns array of maps
type DatasetColumn ¶
DatasetColumn represents dataset mapping column.
type DatasetFactory ¶
type DatasetFactory interface {
//Create creates a dataset from map for passed in table descriptor
Create(descriptor *dsc.TableDescriptor, dataset ...map[string]interface{}) *Dataset
//CreateFromMap crate a dataset from a map for passed in datastore and table
CreateFromMap(datastore string, table string, dataset ...map[string]interface{}) *Dataset
//CreateFromURL crate a dataset from a map for passed in datastore and table
CreateFromURL(datastore string, table string, url string) (*Dataset, error)
//CreateDatasets crate a datasets from passed in data resources
CreateDatasets(data *DatasetResource) (*Datasets, error)
}
DatasetFactory represents a dataset factory.
type DatasetMapping ¶
type DatasetMapping struct {
Table string
Columns []*DatasetColumn
Associations []*DatasetMapping
}
DatasetMapping represents a dataset mapping, mapping allow to route data defined in only one dataset to many datasets.
func (*DatasetMapping) Tables ¶
func (m *DatasetMapping) Tables() []string
type DatasetResource ¶
type DatasetTestManager ¶
type DatasetTestManager interface {
//ClearDatastore clears datastore, it takes adminDatastore and targetDatastore names.
ClearDatastore(adminDatastore string, targetDatastore string) error
//Execute executes passed in script, script defines what database it run on.
Execute(script *Script) (int, error)
//ExecuteFromUrl reads content from url and executes it on datastore
ExecuteFromURL(datastore string, url string) (int, error)
//PrepareDatastore prepare datastore datasets by adding, updating or deleting data.
// Rows will be added if they weren't present, updated if they were present, and deleted if passed in dataset has not rows defined.
PrepareDatastore(datasets *Datasets) (inserted, updated, deleted int, err error)
//ExpectDatasets verifies that passed in expected dataset data values are present in the datastore, this methods reports any violations.
ExpectDatasets(checkPolicy int, expected *Datasets) (AssertViolations, error)
//ManagerRegistry returns ManagerRegistry.
ManagerRegistry() dsc.ManagerRegistry
//ValueProviderRegistry returns macro value provider registry.
ValueProviderRegistry() toolbox.ValueProviderRegistry
//MacroEvaluator returns macro evaluator.
MacroEvaluator() *toolbox.MacroEvaluator
//DatasetFactory returns dataset factory.
DatasetFactory() DatasetFactory
//RegisterTable register table descriptor within datastore manager.
RegisterTable(datastore string, tableDescriptor *dsc.TableDescriptor)
//RegisteredTables returns all registered table for passed in datastore.
RegisteredTables(datastore string) []string
//RegisterDatasetMapping registers dataset mapping for passed in name.
//Note that dataset mapping name should never be the actual table name, as this method will create table descriptor for the mapping.
RegisterDatasetMapping(name string, mapping *DatasetMapping)
//RegisteredMapping returns all registered dataset mapping
RegisteredMapping() []string
//SafeMode enable/disable safe mode (in safe mode only datastore with test name can be dropper and recreated)
SafeMode(enable bool)
}
DatasetTestManager supervises datastore initialization, test dataset preparation, and final datastore dataset verification
func NewDatasetTestManager ¶
func NewDatasetTestManager() DatasetTestManager
NewDatasetTestManager returns a new DatasetTestManager
type DatasetTester ¶
type DatasetTester struct {
// contains filtered or unexported fields
}
DatasetTester represent a dataset tester.
func (DatasetTester) Assert ¶
func (t DatasetTester) Assert(datastore string, expected, actual *Dataset) []*AssertViolation
Assert compares expected and actual dataset, it reports and violations as result.
type DatasetTransformer ¶
type DatasetTransformer struct{}
DatasetTransformer represents a dataset transformer.
func NewDatasetTransformer ¶
func NewDatasetTransformer() *DatasetTransformer
NewDatasetTransformer returns a new NewDatasetTransformer
func (*DatasetTransformer) Transform ¶
func (dt *DatasetTransformer) Transform(datastore string, sourceDataset *Dataset, mapping *DatasetMapping, registry dsc.TableDescriptorRegistry) *Datasets
Transform routes source dataset data into mapping dataset, it uses source dataset and table descriptor registry to build resulting datasets.
type DatastoreConfig ¶
type DatastoreConfig struct {
Datastore string //name of datastore registered in manager registry
Config *dsc.Config // datastore manager config
ConfigURL string //url with Config JSON.
AdminDbName string //optional admin datastore name, needed for sql datastore to drop/create database
ClearDatastore bool //flag to reset datastore (depending on dialablable it could be either drop/create datastore for CanDrop/CanCreate dialects, or drop/create tables
Descriptors []*dsc.TableDescriptor
DatasetMapping map[string]*DatasetMapping //key represent name of dataset to be mapped
}
DatastoreConfig represets DatastoreConfig dsunit config
type DatastoreDatasetProvider ¶
func NewDatastoreDatasetProvider ¶
func NewDatastoreDatasetProvider(manager dsc.Manager) *DatastoreDatasetProvider
type DatastoreDatasetSnapshotManager ¶
type DatastoreDatasetSnapshotManager struct {
// contains filtered or unexported fields
}
func NewDatastoreDatasetSnapshotManager ¶
func NewDatastoreDatasetSnapshotManager(registry dsc.ManagerRegistry) *DatastoreDatasetSnapshotManager
type ExecuteScriptRequest ¶
type ExecuteScriptRequest struct {
Scripts []Script
}
ExecuteScriptRequest represent datastore script request.
type ExpectDatasetRequest ¶
ExpectDatasetRequest represent datastore verification request.
type ExpectResponse ¶
type ExpectResponse struct {
*Response
Violations []*AssertViolation
}
ExpectResponse represetns a dataset verification response.
type InitDatastoreRequest ¶
type InitDatastoreRequest struct {
DatastoreConfigs []DatastoreConfig
}
InitDatastoreRequest represent initialization in dsunit service datastore request.
type PrepareDatastoreRequest ¶
type PrepareDatastoreRequest struct {
Prepare []Datasets
}
PrepareDatastoreRequest represent datastore prepare request.
type Row ¶
Row represents dataset row
func (Row) ValueAsString ¶
ValueAsString returns column value as string.
type Service ¶
type Service interface {
//Init creates datastore manager and register it in manaer registry, if ClearDatastore flag is set it will drop and create datastore.
Init(request *InitDatastoreRequest) *Response
//InitFromUrl reads from url InitDatastoresRequest JSON and initializes
InitFromURL(url string) *Response
//ExecuteScripts executes script defined in the request
ExecuteScripts(request *ExecuteScriptRequest) *Response
//ExecuteScripts loads ExecuteScriptsExecuteScripts JSON from url and executes it.
ExecuteScriptsFromURL(url string) *Response
//PrepareDatastore prepares datastore for request, see DatasetTestManager#PrepareDatastore
PrepareDatastore(request *PrepareDatastoreRequest) *Response
//PrepareDatastore laods PrepareDatastoreRequest JSON from url to prepare datastore, see DatasetTestManager#PrepareDatastore
PrepareDatastoreFromURL(url string) *Response
//PrepareDatastore prepares for passed in datastore, it loads matching dataset files from based directory and method.
PrepareDatastoreFor(datastore string, baseDir string, method string) *Response
//ExpectDatasets verifies dataset data in datastore for passed in request, see DatasetTestManager#ExpectDataset
ExpectDatasets(request *ExpectDatasetRequest) *ExpectResponse
//ExpectDatasets loads ExpectDatasetRequest json from url to verify dataset, see DatasetTestManager#ExpectDataset
ExpectDatasetsFromURL(url string) *ExpectResponse
//ExpectDatasetsFor verifies datastore for passed in datastore, it loads matching dataset files from based directory and method.
ExpectDatasetsFor(datastore string, baseDir string, method string, checkPolicy int) *ExpectResponse
}
Service represents test service
func NewServiceClient ¶
NewServiceClient returns a new dsunit service client
func NewServiceLocal ¶
NewServiceLocal returns new local dsunit service, it takes test directory as argument.
Source Files
¶
- api.go
- assertion.go
- bg_query_provider.go
- bg_value_provider.go
- client.go
- common.go
- csv_parser.go
- dataset.go
- dataset_factory.go
- dataset_file_matcher.go
- dataset_testmanager.go
- dataset_transformer.go
- datastore_dataset_provider.go
- datastore_dataset_snapshot.go
- doc.go
- file_value_provider.go
- server.go
- service.go
- sql_script_parser.go
- sql_value_provider.go
- static.go