@@ -54,8 +54,6 @@ isa_ok my $ch = $CLASS->new(sqitch => $sqitch, target => $target), $CLASS;
5454is $ch -> key, ' clickhouse' , ' Key should be "clickhouse"' ;
5555is $ch -> name, ' ClickHouse' , ' Name should be "ClickHouse"' ;
5656
57- my $client = ' clickhouse-client' . (App::Sqitch::ISWIN ? ' .exe' : ' ' );
58- is $ch -> client, $client , ' client should default to clickhouse' ;
5957is $ch -> registry, ' sqitch' , ' registry default should be "sqitch"' ;
6058my $sqitch_uri = $uri -> clone;
6159$sqitch_uri -> dbname(' sqitch' );
@@ -65,44 +63,81 @@ is $ch->_dsn, 'dbi:ODBC:DSN=sqitch', 'DSN should use DBD::ODBC with registry dat
6563is $ch -> registry_destination, ' db:clickhouse:sqitch' ,
6664 ' registry_destination should be the same as registry_uri' ;
6765
66+
67+ # Test the client.
68+ my $mock_sqitch = Test::MockModule-> new(' App::Sqitch' );
6869my @std_opts = (
6970 ' --progress' => ' off' ,
7071 ' --progress-table' => ' off' ,
7172 ' --disable_suggestion' ,
7273);
7374
74- my $mock_sqitch = Test::MockModule-> new(' App::Sqitch' );
75- my $warning ;
76- $mock_sqitch -> mock(warn => sub { shift ; $warning = [@_ ] });
77- $ch -> uri-> dbname(' ' );
78- is_deeply [$ch -> cli], [$client , @std_opts ],
79- ' clickhouse command should be std opts-only' ;
80- is_deeply $warning , [__x
81- ' Database name missing in URI "{uri}"' ,
82- uri => $ch -> uri
83- ], ' Should have emitted a warning for no database name' ;
84-
85- isa_ok $ch = $CLASS -> new(sqitch => $sqitch , target => $target ), $CLASS ;
86- ok $ch -> set_variables(foo => ' baz' , whu => ' hi there' , yo => ' stellar' ),
87- ' Set some variables' ;
88- is_deeply [$ch -> cli], [
89- $client ,
90- ' --param_foo' => ' baz' ,
91- ' --param_whu' => ' hi there' ,
92- ' --param_yo' => ' stellar' ,
93- @std_opts ,
94- ], ' Variables should be passed to psql via --set' ;
75+ # #############################################################################
76+ NO_CLI: {
77+ # Make sure we get an error when it can't find the client.
78+ my $mock_fs = Test::MockModule-> new(' File::Spec' );
79+ $mock_fs -> mock(path => sub { ' t' , ' bin' });
80+ throws_ok {
81+ $CLASS -> new( sqitch => $sqitch , target => $target )-> client
82+ } ' App::Sqitch::X' , ' Should get an error when cannot find CLI' ;
83+ is $@ -> ident, ' clickhouse' , " Ident for missing CLI should be 'clickhouse'" ;
84+ is $@ -> message, __x(
85+ ' Unable to locate {cli} client; set "engine.{eng}.client" via sqitch config' ,
86+ cli => ' clickhouse' ,
87+ eng => ' clickhouse' ,
88+ ), " Message for missing CLI should be correct" ;
89+ }
9590
96- $mock_sqitch -> unmock_all;
91+ # #############################################################################
92+ CLI: {
93+ my @client ;
94+ if (my $cli = try { $ch -> client }) {
95+ like $cli , qr /\A clickhouse(?:-client)?(?:\. exe)?\z / ,
96+ ' client should default clickhouse or clickhouse-client' ;
97+ @client = $cli =~ / -client/ ? ($cli ) : ($cli , ' client' );
98+ } else {
99+ # No client found, explicitly set it to `clickhouse`.
100+ @client = ((' clickhouse' . (App::Sqitch::ISWIN ? ' .exe' : ' ' )), ' client' );
101+ $config -> update( ' engine.clickhouse.client' => $client [0]);
102+ }
97103
98- $target = App::Sqitch::Target-> new(
99- sqitch => $sqitch ,
100- uri => URI::db-> new(' db:clickhouse:' ),
101- );
102- isa_ok $ch = $CLASS -> new(
103- sqitch => $sqitch ,
104- target => $target ,
105- ), $CLASS ;
104+ my $warning ;
105+ $mock_sqitch -> mock(warn => sub { shift ; $warning = [@_ ] });
106+ $ch -> uri-> dbname(' ' );
107+ is_deeply [$ch -> cli], [@client , @std_opts ],
108+ ' clickhouse command should be std opts-only' ;
109+ is_deeply $warning , [__x
110+ ' Database name missing in URI "{uri}"' ,
111+ uri => $ch -> uri
112+ ], ' Should have emitted a warning for no database name' ;
113+
114+ isa_ok $ch = $CLASS -> new(sqitch => $sqitch , target => $target ), $CLASS ;
115+ ok $ch -> set_variables(foo => ' baz' , whu => ' hi there' , yo => ' stellar' ),
116+ ' Set some variables' ;
117+ is_deeply [$ch -> cli], [
118+ @client ,
119+ ' --param_foo' => ' baz' ,
120+ ' --param_whu' => ' hi there' ,
121+ ' --param_yo' => ' stellar' ,
122+ @std_opts ,
123+ ], ' Variables should be passed to psql via --set' ;
124+
125+ # Try alternate spelling of client.
126+ my $mock = Test::MockModule-> new($CLASS );
127+ if (@client == 1) {
128+ push @client => ' client' ;
129+ } else {
130+ $client [0] =~ s / clickhouse/ clickhouse-client/ ;
131+ pop @client ;
132+ }
133+ $mock -> mock(client => $client [0]);
134+
135+ isa_ok $ch = $CLASS -> new(sqitch => $sqitch , target => $target ), $CLASS ;
136+ is_deeply [$ch -> cli], [ @client , @std_opts ],
137+ ' Alternate spelling of client should be returned' ;
138+
139+ $mock_sqitch -> unmock_all;
140+ }
106141
107142# #############################################################################
108143# Make sure config and environment variables are read.
@@ -971,7 +1006,7 @@ DBIEngineTest->run(
9711006 say ' # Connected to ClickHouse ' . $self -> _capture(' --query' => ' SELECT version()' );
9721007 1;
9731008 },
974- engine_err_regex => qr /^Error while processing query / ,
1009+ engine_err_regex => qr /Syntax error: failed at position 8 / ,
9751010 init_error => __x(
9761011 ' Sqitch database {database} already initialized' ,
9771012 database => $reg2 ,
0 commit comments