@@ -272,7 +272,47 @@ class MockWatcher; end;
272272 expect { Synapse ::ConfigGenerator ::Haproxy . new ( conf ) } .
273273 to raise_error ( ArgumentError , "the `#{ value } ` option is required when `#{ key } ` is true" )
274274 end
275+ end
275276
277+ context 'when do_checks is true' do
278+ let ( :invalid_conf ) {
279+ {
280+ 'global' => [ ] ,
281+ 'defaults' => [ ] ,
282+ 'do_reloads' => false ,
283+ 'do_socket' => false ,
284+ 'do_writes' => false ,
285+ 'do_checks' => true ,
286+ }
287+ }
288+ let ( :conf_additions ) {
289+ {
290+ 'check_command' => 'haproxy -c -f /etc/haproxy/haproxy-candidate.cfg' ,
291+ 'candidate_config_file_path' => '/etc/haproxy/haproxy-candidate.cfg' ,
292+ }
293+ }
294+
295+ context 'when check parameters are not set together' do
296+ it 'raises an error' do
297+ conf_additions . each do |key , value |
298+ conf = invalid_conf . clone
299+ conf [ key ] = value
300+ expect { Synapse ::ConfigGenerator ::Haproxy . new ( conf ) } .
301+ to raise_error ( ArgumentError )
302+ end
303+ end
304+ end
305+
306+ context 'when check parameters are set together' do
307+ it 'does not raise an error' do
308+ conf = invalid_conf . clone
309+ conf_additions . each do |key , value |
310+ conf [ key ] = value
311+ end
312+
313+ expect { Synapse ::ConfigGenerator ::Haproxy . new ( conf ) } . not_to raise_error
314+ end
315+ end
276316 end
277317
278318 it 'properly defaults do_writes, do_socket, do_checks, do_reloads, use_nerve_weights' do
@@ -793,6 +833,20 @@ class MockWatcher; end;
793833 allow ( File ) . to receive ( :read ) . with ( 'candidate_config_file' ) . and_return ( 'candidate-haproxy-config' )
794834 }
795835
836+ context 'when candidate_config_file_path is not set' do
837+ before {
838+ config [ 'haproxy' ] . delete ( 'candidate_config_file_path' )
839+ config [ 'haproxy' ] [ 'do_checks' ] = false
840+ }
841+
842+ it 'still succeeds' do
843+ allow ( FileUtils ) . to receive ( :mv )
844+
845+ expect ( File ) . to receive ( :write ) . with ( 'config_file.tmp' , 'new-config' )
846+ expect { subject . write_config ( 'new-config' ) } . not_to raise_error
847+ end
848+ end
849+
796850 context 'when config changes' do
797851 it 'writes candidate config' do
798852 allow ( FileUtils ) . to receive ( :mv )
@@ -883,6 +937,7 @@ class MockWatcher; end;
883937
884938 config [ 'haproxy' ] [ 'do_checks' ] = true
885939 config [ 'haproxy' ] [ 'check_command' ] = 'haproxy_check_mock'
940+ config [ 'haproxy' ] [ 'candidate_config_file_path' ] = 'candidate-haproxy-config-file'
886941 }
887942
888943 it 'calls the supplied command' do
0 commit comments