CivicSpleen / ambry

A comprehensive data package manager
BSD 2-Clause "Simplified" License
4 stars 5 forks source link

Testing Database Management, Take 3 #170

Open ericbusboom opened 8 years ago

ericbusboom commented 8 years ago

Testing database management is getting complicated and brittle, so it's probably worth actually designing it, rather than letting it evolve.

Requirements

There are only a few scenarios that differ between Sqlite and Postgres, so most of the testing should be done on Sqlite, with only the different scenarios being tested on Postgres.

Common Initial Conditions

At the start of a test, one of these conditions should be true:

For postgres, the test should be able to drop and re-create the test database.

Cached library.

A common test need is to have existing bundles in a library. Currently, these bundles are rebuild for every test, or sometimes, for every test class. It would be better to have the tests construct a prototype library, and then copy it into place.

/tmp test structure

The test library can always be in /tmp. It never gets really large. The test tree should look like:

/tmp
    ambry-tests
        proto
        library

At the start of a test, the /tmp/ambry-tests/library directory is and reconstructed. If the test database is sqlite, and a pre-build library is required, it is copied from the proto. If the proto does not exist, it is created.

Configuration

The test configuration requires:

The Sqlite tests don't require a DSN, because it will always be 'library.db' in the root of the library filesystem.

These configuration can be set in a few ways:

Tests must refuse to run if neither of these configs exist

Config file.

Add a new section of the config file, just for test:

test:
    postgres: < postgres dsn>
    filesystem: <filesystem_path>

This won't be part of the ambry.run config, it's just an extra section only for test.

Env Vars

If AMBRY_TEST_ROOT is not set, and there is no test section in the config file, the test setup will immediately fail.

Per test setup

The test class can have set these class-level vars to affect setup. ( Maybe also create class decorators to set them nicely )

ericbusboom commented 8 years ago

@nmb10, could you have a look at this and let me know what you think. Add to any requirements you can think of.