Created
April 24, 2014 05:51
-
-
Save ken39arg/11242963 to your computer and use it in GitHub Desktop.
Test::PostgreSQLを確実に起動する
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| use common::sense; | |
| use Test::PostgreSQL; | |
| use Path::Class; | |
| # おそらくOSとかによってTest::PostgreSQLの期待するpostgersql.confの設定と違うため | |
| # 環境によって起動がクソ遅くなる | |
| # configを弄った方がいいのでauto_startはoff | |
| my $psql = Test::PostgreSQL->new( auto_start => 0 ); | |
| # ログメッセージを確実にenglishにする | |
| # 日本語になると起動チェックで100秒以上loopする | |
| # https://metacpan.org/source/TJC/Test-PostgreSQL-0.10/lib/Test/PostgreSQL.pm#L171 | |
| $psql->initdb_args( $psql->initdb_args . " --lc-messages=C" ); | |
| # 自前でsetup ( initdb ) | |
| $psql->setup; | |
| # ostgresql.confを書き換える | |
| dir( $psql->base_dir )->recurse( callback => sub { | |
| my $file = shift; | |
| return unless $file =~ /postgresql.conf$/; | |
| # 全部自分で指定した方が良いと思うが最低限logを標準出力に出さなくてはいけない | |
| # logがpg_log/等にはかれるとTest::PostgreSQLは起動の成功を知ることができなくなる | |
| # https://metacpan.org/source/TJC/Test-PostgreSQL-0.10/lib/Test/PostgreSQL.pm#L165 | |
| my $config = $file->slurp; | |
| $config =~ s/^log/#log/gm; # log関連の設定をoff | |
| my $writer = $file->openw; | |
| $writer->print( $config ); | |
| $writer->close; | |
| }); | |
| # start (postmaster) | |
| $psql->start; | |
| say $psql->dsn; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment