App-Sqitch

 view release on metacpan or  search on metacpan

t/config.t  view on Meta::CPAN

    ok $cmd = $CLASS->new({
        sqitch  => $sqitch,
        context => 'user',
        action  => 'get',
    }), 'Create another user config get command';
    ok !-f $cmd->file, 'There should be no user config file';
    throws_ok { $cmd->execute('core.engine') } 'App::Sqitch::X',
        'Should fail when no user config file';
    is $@->ident, 'config', 'Error ident should be "config"';
    is $@->message, '', 'Error Message should be empty';
    is $@->exitval, 1, 'Error exitval should be 1';

    ok $cmd = $CLASS->new({
        sqitch  => $sqitch,
        context => 'local',
        action  => 'get',
    }), 'Create another local config get command';
    ok !-f $cmd->file, 'There should be no local config file';
    throws_ok { $cmd->execute('core.engine') } 'App::Sqitch::X',
        'Should fail when no local config file';
    is $@->ident, 'config', 'Error ident should be "config"';
    is $@->message, '', 'Error Message should be empty';
    is $@->exitval, 1, 'Error exitval should be 1';
}

##############################################################################
# Test list().
$config = TestConfig->from(
    system => file(qw(t sqitch.conf)),
    user   => file(qw(t user.conf)),
    local  => file(qw(t local.conf)),
);
$sqitch = App::Sqitch->new(config => $config);
ok $cmd = $CLASS->new({
    sqitch  => $sqitch,
    action  => 'list',
}), 'Create config list command';
ok $cmd->execute, 'Execute the list action';
is_deeply \@emit, [[
    'bundle.dest_dir=_build/sql
bundle.from=gamma
bundle.tags_only=true
core.engine=pg
core.extension=ddl
core.pager=less -r
core.top_dir=migrations
core.uri=https://github.com/sqitchers/sqitch/
engine.firebird.client=/opt/firebird/bin/isql
engine.firebird.registry=meta
engine.mysql.client=/opt/local/mysql/bin/mysql
engine.mysql.registry=meta
engine.mysql.variables.prefix=foo_
engine.pg.client=/opt/local/pgsql/bin/psql
engine.pg.registry=meta
engine.pg.target=mydb
engine.sqlite.client=/opt/local/bin/sqlite3
engine.sqlite.registry=meta
engine.sqlite.target=devdb
foo.BAR.baz=hello
foo.BAR.yep
guess.Yes.No.calico=false
guess.Yes.No.red=true
revert.count=2
revert.revision=1.1
revert.to=gamma
target.devdb.uri=db:sqlite:
target.mydb.plan_file=t/plans/dependencies.plan
target.mydb.uri=db:pg:mydb
user.email=michael@example.com
user.name=Michael Stonebraker
'
]], 'Should have emitted the merged config';
@emit = ();

CONTEXT: {
    $config = TestConfig->from(system => file qw(t sqitch.conf) );
    $sqitch = App::Sqitch->new(config => $config);
    ok $cmd = $CLASS->new({
        sqitch  => $sqitch,
        context => 'system',
        action  => 'list',
    }), 'Create system config list command';
    ok $cmd->execute, 'List the system config';
    is_deeply \@emit, [[
        'bundle.dest_dir=_build/sql
bundle.from=gamma
bundle.tags_only=true
core.engine=pg
core.extension=ddl
core.pager=less -r
core.top_dir=migrations
core.uri=https://github.com/sqitchers/sqitch/
engine.pg.client=/usr/local/pgsql/bin/psql
foo.BAR.baz=hello
foo.BAR.yep
guess.Yes.No.calico=false
guess.Yes.No.red=true
revert.count=2
revert.revision=1.1
revert.to=gamma
'
    ]], 'Should have emitted the system config list';
    @emit = ();

    $config = TestConfig->from(
        system => file(qw(t sqitch.conf)),
        user   => file(qw(t user.conf)),
    );
    $sqitch = App::Sqitch->new(config => $config);
    ok $cmd = $CLASS->new({
        sqitch  => $sqitch,
        context => 'user',
        action  => 'list',
    }), 'Create user config list command';
    ok $cmd->execute, 'List the user config';
    is_deeply \@emit, [[
        'engine.firebird.client=/opt/firebird/bin/isql
engine.firebird.registry=meta
engine.mysql.client=/opt/local/mysql/bin/mysql
engine.mysql.registry=meta
engine.mysql.variables.prefix=foo_
engine.pg.client=/opt/local/pgsql/bin/psql
engine.pg.registry=meta
engine.pg.target=db:pg://postgres@localhost/thingies
engine.sqlite.client=/opt/local/bin/sqlite3
engine.sqlite.registry=meta
engine.sqlite.target=db:sqlite:my.db
user.email=michael@example.com
user.name=Michael Stonebraker
'
    ]],  'Should only have emitted the user config list';
    @emit = ();

    $config = TestConfig->from(
        system => file(qw(t sqitch.conf)),
        user   => file(qw(t user.conf)),
        local  => file(qw(t local.conf)),
    );
    $sqitch = App::Sqitch->new(config => $config);
    ok $cmd = $CLASS->new({
        sqitch  => $sqitch,
        context => 'local',
        action  => 'list',
    }), 'Create local config list command';
    ok $cmd->execute, 'List the local config';
    is_deeply \@emit, [[
        'core.engine=pg
engine.pg.target=mydb
engine.sqlite.target=devdb
target.devdb.uri=db:sqlite:
target.mydb.plan_file=t/plans/dependencies.plan
target.mydb.uri=db:pg:mydb
'
    ]],  'Should only have emitted the local config list';
    @emit = ();
}



( run in 1.473 second using v1.01-cache-2.11-cpan-13bb782fe5a )