Anego

 view release on metacpan or  search on metacpan

t/basic.t  view on Meta::CPAN

    schema_class => 'MyApp::Schema',
}
__CONFIG__

my $config_file = File::Spec->catfile($repo->work_tree, qw/ .anego.pl /);
spew($config_file, $config);

subtest 'status subcommand' => sub {
    $Anego::Config::CONFIG = undef;

    my ($stdout, $stderr) = capture {
        Anego::CLI::Status->run();
    };

    like $stdout, qr!RDBMS:\s+SQLite!;
    like $stdout, qr!Database:\s+:memory:!;
    like $stdout, qr!Schema class:\s+MyApp::Schema\s+\(lib/MyApp/Schema\.pm\)!;

    like $stdout, qr!initial commit!;
    like $stdout, qr!second commit!;
};

subtest 'diff / migrate subcommand (latest)' => sub {
    $Anego::Config::CONFIG = undef;

    subtest 'diff (1)' => sub {
        my ($stdout, $stderr) = capture {
            Anego::CLI::Diff->run();
        };

        is $stdout, <<__DDL__;

BEGIN;

CREATE TABLE user (
  id INTEGER PRIMARY KEY NOT NULL,
  name VARCHAR(255) NOT NULL,
  created_at DATETIME NOT NULL,
  updated_at DATETIME NOT NULL
);


COMMIT;

__DDL__
        is $stderr, '';
    };

    subtest 'migrate (1)' => sub {
        my ($stdout, $stderr) = capture {
            Anego::CLI::Migrate->run();
        };

        is $stdout, "Migrated\n";
        is $stderr, '';
    };

    subtest 'diff (2)' => sub {
        my ($stdout, $stderr) = capture {
            Anego::CLI::Diff->run();
        };

        is $stdout, '';
        is $stderr, "target schema == database schema, should no differences\n";
    };

    subtest 'migrate (2)' => sub {
        my ($stdout, $stderr) = capture {
            Anego::CLI::Migrate->run();
        };

        is $stdout, '';
        is $stderr, "target schema == database schema, should no differences\n";
    };
};

subtest 'diff / migrate subcommand (revision)' => sub {
    $Anego::Config::CONFIG = undef;

    subtest 'diff (1)' => sub {
        my ($stdout, $stderr) = capture {
            Anego::CLI::Diff->run(qw/ revision HEAD^ /);
        };

        is $stdout, <<__DDL__;

BEGIN;

CREATE TABLE user (
  id INTEGER PRIMARY KEY NOT NULL,
  name VARCHAR(255) NOT NULL
);


COMMIT;

__DDL__
        is $stderr, '';
    };

    subtest 'migrate (1)' => sub {
        my ($stdout, $stderr) = capture {
            Anego::CLI::Migrate->run(qw/ revision HEAD^ /);
        };

        is $stdout, "Migrated\n";
        is $stderr, '';
    };

    subtest 'diff (2)' => sub {
        my ($stdout, $stderr) = capture {
            Anego::CLI::Diff->run(qw/ revision HEAD^ /);
        };

        is $stdout, '';
        is $stderr, "target schema == database schema, should no differences\n";
    };

    subtest 'migrate (2)' => sub {
        my ($stdout, $stderr) = capture {
            Anego::CLI::Migrate->run(qw/ revision HEAD^ /);
        };

        is $stdout, '';
        is $stderr, "target schema == database schema, should no differences\n";
    };
};

sub spew {
    my ($path, $content) = @_;

    open my $fh, '>', $path or die "$!";
    print $fh $content;
    close $fh;
}



( run in 0.519 second using v1.01-cache-2.11-cpan-49f99fa48dc )