NAME
CDTest - Small-scale DBIC test module
SYNOPSIS
use lib qw(t/lib);
use CDTest;
use Test2::Bundle::More;
my $schema = CDTest->init_schema;
DESCRIPTION
This module provides a test DBIC schema in a real SQLite DB. Much of this was stolen and stripped down from DBICTest in DBIC's test platform.
METHODS
init_schema
my $schema = CDTest->init_schema(
# Defaults
no_connect => 0,
no_deploy => 0,
no_preclean => 0,
no_populate => 0,
);
my $schema = CDTest->init_schema(
mass_populate => 100,
);
This method creates a new, empty, in-memory SQLite database and then creates a new, empty database. If CDTEST_DSN, CDTEST_DBUSER, and CDTEST_DBPASS are specified, it will use that database instead. Make sure the database doesn't have any useful data in it.
This method will call "deploy_schema" by default, unless the no_deploy flag is set.
It will also call "clean_schema" by default, unless the no_preclean flag is set, or the SQLite in-memory DB is used (which is the default).
Also, by default, this method will call "populate_schema", unless the no_deploy or no_populate flags are set.
If mass_populate or CDTEST_MASS_POPULATE is set, "mass_populate_schema" will be called instead, with the number of batches specified.
dbms_name
my $dbms_name = CDTest->dbms_name;
Acquires the driver name without connecting to anything.
deploy_schema
CDTest->deploy_schema( $schema );
Deploys the sqlite.sql schema into the SQLite DB.
clean_schema
CDTest->clean_schema( $schema );
Drops all of the tables in the schema.
populate_schema
CDTest->populate_schema( $schema );
After you deploy your schema, you can use this method to populate the tables with test data.
mass_populate_schema
CDTest->mass_populate_schema( $schema, $batches );
Populate the schema with massive amounts of data, mostly as duplicates of different rows.
The $batches are measured in thousands of artists. In other words, one batch is:
1000 artists
~2500 CDs
~20000 tracks
Just 10 batches takes up quite a bit of space (around 100MB of memory in the SQLite in-memory DB), and takes around 30 seconds to populate.