def set_up(pg_version, es_version):
    """ Start containers """

    compose = docker_compose(pg_version, es_version)

    show_status(
        "Starting testing environment for PostgreSQL {pg_version} with Elasticsearch {es_version}..."
        .format(pg_version=pg_version, es_version=es_version))

    show_status("Stopping and Removing any old containers...")
    compose("stop")
    compose("rm", "--force")

    show_status("Building new images...")
    try:
        compose("build")
    except ErrorReturnCode as exc:
        print("Failed to build images...")
        print(exc.stdout.decode("utf-8"))
        print()
        print(exc.stderr.decode("utf-8"))
        sys.exit(1)

    show_status("Starting new containers...")
    compose("up", "-d")

    show_status("Testing environment started")
示例#2
0
def tear_down(version):
    dc = docker_compose(version)

    show_status(
        'Stopping testing environment for PostgreSQL {version}...'.format(
            version=version))

    dc('down')

    show_status('Testing environment stopped')
def main():
    """ Runs the tests """

    parser = argparse.ArgumentParser(description='Perform end to end tests.')
    parser.add_argument('version', nargs='+', help='PostgreSQL version')
    args = parser.parse_args()

    result = all(list(run_tests(version) for version in args.version))
    show_status('PASS' if result else 'FAIL', newline=True)

    sys.exit(0 if result else 1)
示例#4
0
def tear_down(pg_version, es_version):
    """ Stop containers """

    compose = docker_compose(pg_version, es_version)

    show_status(
        "Stopping testing environment for PostgreSQL {pg_version} with Elasticsearch {es_version}..."
        .format(pg_version=pg_version, es_version=es_version))

    compose("down")

    show_status("Testing environment stopped")
def tear_down(version):
    """ Stop containers """

    compose = docker_compose(version)

    show_status(
        'Stopping testing environment for PostgreSQL {version}...'.format(
            version=version))

    compose('down')

    show_status('Testing environment stopped')
示例#6
0
def main():
    """ Runs the tests """

    parser = argparse.ArgumentParser(description="Perform end to end tests.")
    parser.add_argument("--pg", nargs="+", help="PostgreSQL version")
    parser.add_argument("--es", nargs="+", help="Elasticsearch version")
    args = parser.parse_args()

    result = all(
        run_tests(pg_version, es_version) for pg_version in args.pg
        for es_version in args.es)
    show_status("PASS" if result else "FAIL", newline=True)

    sys.exit(0 if result else 1)
def perform_tests(pg_version, es_version):
    """ Run tests against a single version of PostgreSQL """

    success = True

    show_status(
        "Testing PostgreSQL {pg_version} with Elasticsearch {es_version}...".
        format(pg_version=pg_version, es_version=es_version))

    show_status("Testing read...")
    if not show_result(pg_version, es_version, "read",
                       run_sql_test("read.sql")):
        success = False

    show_status("Testing nested read...")
    if not show_result(pg_version, es_version, "nested-read",
                       run_sql_test("nested-read.sql")):
        success = False

    show_status("Testing query...")
    if not show_result(pg_version, es_version, "query",
                       run_sql_test("query.sql")):
        success = False

    return success
示例#8
0
def run_tests(version):
    show_status('Testing PostgreSQL {version}'.format(version=version),
                newline=True)

    set_up(version)
    load_fixtures()

    time.sleep(10)

    success = perform_tests(version)

    tear_down(version)

    return success
示例#9
0
def set_up(version):
    dc = docker_compose(version)

    show_status(
        'Starting testing environment for PostgreSQL {version}...'.format(
            version=version))

    show_status('Stopping and Removing any old containers...')
    dc('stop')
    dc('rm', '--force')

    show_status('Building new images...')
    dc('build')

    show_status('Starting new containers...')
    dc('up', '-d')

    show_status('Testing environment started')
示例#10
0
def run_tests(pg_version, es_version):
    """ Runs the tests """

    show_status(
        "Testing PostgreSQL {pg_version} with Elasticsearch {es_version}".
        format(pg_version=pg_version, es_version=es_version),
        newline=True,
    )

    set_up(pg_version, es_version)
    load_fixtures()

    time.sleep(10)

    success = perform_tests(pg_version, es_version)

    tear_down(pg_version, es_version)

    return success
示例#11
0
def set_up(pg_version, es_version):
    """ Start containers """

    compose = docker_compose(pg_version, es_version)

    show_status(
        "Starting testing environment for PostgreSQL {pg_version} with Elasticsearch {es_version}..."
        .format(pg_version=pg_version, es_version=es_version))

    show_status("Stopping and Removing any old containers...")
    compose("stop")
    compose("rm", "--force")

    show_status("Building new images...")
    compose("build")

    show_status("Starting new containers...")
    compose("up", "-d")

    show_status("Testing environment started")
def perform_tests(version):
    success = True

    show_status('Testing PostgreSQL {version}...'.format(version=version))

    show_status('Testing read...')
    if not show_result(version, 'read', run_sql_test('read.sql')):
        success = False

    show_status('Testing query...')
    if not show_result(version, 'query', run_sql_test('query.sql')):
        success = False

    return success
def load_fixtures():
    """ Load fixtures into PostgreSQL and Elastic Search """

    show_status('Loading fixtures')

    show_status('Waiting for PostgreSQL...')
    wait_for(pg_is_available)

    show_status('Loading PostgreSQL schema...')
    load_sql_file('schema.sql')

    show_status('Loading PostgreSQL data...')
    load_sql_file('data.sql')

    show_status('Waiting for Elastic Search...')
    wait_for(es_is_available)

    show_status('Loading Elastic Search data...')
    load_json_file('data.json')
def perform_tests(pg_version, es_version):
    """ Run tests against a single version of PostgreSQL """

    success = True

    show_status(
        "Testing PostgreSQL {pg_version} with Elasticsearch {es_version}...".
        format(pg_version=pg_version, es_version=es_version))

    show_status("Testing read...")
    if not show_result(pg_version, es_version, "read",
                       run_sql_test("read.sql")):
        success = False

    show_status("Testing nested read...")
    if not show_result(pg_version, es_version, "nested-read",
                       run_sql_test("nested-read.sql")):
        success = False

    show_status("Testing sorted read...")
    if not show_result(pg_version, es_version, "sorted-read",
                       run_sql_test("sorted-read.sql")):
        success = False

    show_status("Testing query...")
    if not show_result(pg_version, es_version, "query",
                       run_sql_test("query.sql")):
        success = False

    show_status("Testing json query...")
    data, error = run_sql_test("json-query.sql")
    if not show_result(pg_version, es_version, "json-query",
                       (data == "Portal Chess", error)):
        success = False

    show_status("Testing insert returning id...")
    data, error = run_sql_test("insert-return-id.sql")
    if not show_result(pg_version, es_version, "insert returning id",
                       (data == "1", error)):
        success = False

    show_status("Testing insert returning row...")
    data, error = run_sql_test("insert-return-row.sql")
    if not show_result(
            pg_version,
            es_version,
            "insert returning row",
        (data
         == "2 | Test insert returning title | test insert returning body",
         error),
    ):
        success = False

    show_status("Testing insert waiting for refresh...")
    data, error = run_sql_test("insert-wait_for.sql")
    if not show_result(
            pg_version,
            es_version,
            "insert waiting for refresh",
        (data == "3 | Test insert wait for title | test insert wait for body",
         error),
    ):
        success = False

    show_status("Testing delete returning row...")
    data, error = run_sql_test("delete-return-row.sql")
    if not show_result(
            pg_version,
            es_version,
            "delete returning row",
        (data == "39357158 | Momo Thomas", error),
    ):
        success = False

    return success
示例#15
0
from lib.load_fixtures import load_fixtures
from lib.test import perform_tests
from lib.tools import show_status


def run_tests(version):
    show_status('Testing PostgreSQL {version}'.format(version=version),
                newline=True)

    set_up(version)
    load_fixtures()

    time.sleep(10)

    success = perform_tests(version)

    tear_down(version)

    return success


if __name__ == "__main__":
    parser = argparse.ArgumentParser(description='Perform end to end tests.')
    parser.add_argument('version', nargs='+', help='PostgreSQL version')
    args = parser.parse_args()

    result = all(list(run_tests(version) for version in args.version))
    show_status('PASS' if result else 'FAIL', newline=True)

    sys.exit(0 if result else 1)
def load_fixtures():
    """ Load fixtures into PostgreSQL and Elastic Search """

    show_status("Loading fixtures")

    show_status("Waiting for PostgreSQL...")
    wait_for(pg_is_available)

    show_status("Loading PostgreSQL schema...")
    load_sql_file("schema.sql")

    show_status("Loading PostgreSQL data...")
    load_sql_file("data.sql")

    show_status("Waiting for Elastic Search...")
    wait_for(es_is_available)

    show_status("Loading Elastic Search data...")
    load_json_file("data.json")
    load_json_file("nested-data.json")