399399 let ( :ilm_rollover_alias ) { "the_cat_in_the_hat" }
400400 let ( :index ) { ilm_rollover_alias }
401401 let ( :expected_index ) { index }
402- let ( :template_name ) { "custom" }
403402 let ( :settings ) { super . merge ( "ilm_policy" => ilm_policy_name ,
404403 "template" => template ,
405- "template_name" => template_name ,
406404 "ilm_rollover_alias" => ilm_rollover_alias ) }
407405
408406
419417 put_policy ( @es , ilm_policy_name , policy )
420418 end
421419
420+ it_behaves_like 'an ILM enabled Logstash'
421+
422422 it 'should create the rollover alias' do
423423 expect ( @es . indices . exists_alias ( index : ilm_rollover_alias ) ) . to be_falsey
424424 subject . register
442442 it 'should write the ILM settings into the template' do
443443 subject . register
444444 sleep ( 1 )
445- expect ( @es . indices . get_template ( name : template_name ) [ template_name ] [ "index_patterns" ] ) . to eq ( [ "#{ ilm_rollover_alias } -*" ] )
446- expect ( @es . indices . get_template ( name : template_name ) [ template_name ] [ "settings" ] [ 'index' ] [ 'lifecycle' ] [ 'name' ] ) . to eq ( ilm_policy_name )
447- expect ( @es . indices . get_template ( name : template_name ) [ template_name ] [ "settings" ] [ 'index' ] [ 'lifecycle' ] [ 'rollover_alias' ] ) . to eq ( ilm_rollover_alias )
445+ expect ( @es . indices . get_template ( name : ilm_rollover_alias ) [ ilm_rollover_alias ] [ "index_patterns" ] ) . to eq ( [ "#{ ilm_rollover_alias } -*" ] )
446+ expect ( @es . indices . get_template ( name : ilm_rollover_alias ) [ ilm_rollover_alias ] [ "settings" ] [ 'index' ] [ 'lifecycle' ] [ 'name' ] ) . to eq ( ilm_policy_name )
447+ expect ( @es . indices . get_template ( name : ilm_rollover_alias ) [ ilm_rollover_alias ] [ "settings" ] [ 'index' ] [ 'lifecycle' ] [ 'rollover_alias' ] ) . to eq ( ilm_rollover_alias )
448+ end
449+
450+ context 'with a different template_name' do
451+ let ( :template_name ) { "custom_template_name" }
452+ let ( :settings ) { super . merge ( 'template_name' => template_name ) }
453+
454+ it_behaves_like 'an ILM enabled Logstash'
455+
456+ it 'should write the ILM settings into the template' do
457+ subject . register
458+ sleep ( 1 )
459+ expect ( @es . indices . get_template ( name : template_name ) [ template_name ] [ "index_patterns" ] ) . to eq ( [ "#{ ilm_rollover_alias } -*" ] )
460+ expect ( @es . indices . get_template ( name : template_name ) [ template_name ] [ "settings" ] [ 'index' ] [ 'lifecycle' ] [ 'name' ] ) . to eq ( ilm_policy_name )
461+ expect ( @es . indices . get_template ( name : template_name ) [ template_name ] [ "settings" ] [ 'index' ] [ 'lifecycle' ] [ 'rollover_alias' ] ) . to eq ( ilm_rollover_alias )
462+ end
448463 end
449464
450- it_behaves_like 'an ILM enabled Logstash'
451465 end
452466 end
453467
467481 expect { get_policy ( @es , LogStash ::Outputs ::ElasticSearch ::DEFAULT_POLICY ) } . to raise_error ( Elasticsearch ::Transport ::Transport ::Errors ::NotFound )
468482 end
469483
470- it 'should write the ILM settings into the template' do
484+ it 'should not write the ILM settings into the template' do
471485 subject . register
472486 sleep ( 1 )
473487 expect ( @es . indices . get_template ( name : "logstash" ) [ "logstash" ] [ "index_patterns" ] ) . to eq ( [ "logstash-*" ] )
474488 expect ( @es . indices . get_template ( name : "logstash" ) [ "logstash" ] [ "settings" ] [ 'index' ] [ 'lifecycle' ] ) . to be_nil
475-
476489 end
477490
478-
479491 context 'with an existing policy that will roll over' do
480492 let ( :policy ) { small_max_doc_policy }
481493 let ( :ilm_policy_name ) { "3_docs" }
482494 let ( :settings ) { super . merge ( "ilm_policy" => ilm_policy_name ) }
483495
484- it 'should index documents normally' do
485-
496+ it 'should not roll over indices' do
486497 subject . register
487498 subject . multi_receive ( [
488499 LogStash ::Event . new ( "message" => "sample message here" ) ,
513524 expect ( indexes_written . values . first ) . to eq ( 6 )
514525 end
515526 end
527+
528+ context 'with a custom template name' do
529+ let ( :template_name ) { "custom_template_name" }
530+ let ( :settings ) { super . merge ( 'template_name' => template_name ) }
531+
532+ it 'should not write the ILM settings into the template' do
533+ subject . register
534+ sleep ( 1 )
535+ expect ( @es . indices . get_template ( name : template_name ) [ template_name ] [ "index_patterns" ] ) . to eq ( [ "logstash-*" ] )
536+ expect ( @es . indices . get_template ( name : template_name ) [ template_name ] [ "settings" ] [ 'index' ] [ 'lifecycle' ] ) . to be_nil
537+ end
538+ end
539+
516540 end
517541 end
518542end
0 commit comments