|
1 |
| -require "logstash/devutils/rspec/spec_helper" |
| 1 | +require_relative "../../../../spec/spec_helper" |
2 | 2 | require "logstash/outputs/elasticsearch/template_manager"
|
3 | 3 |
|
4 | 4 | describe LogStash::Outputs::ElasticSearch::TemplateManager do
|
|
33 | 33 | end
|
34 | 34 | end
|
35 | 35 |
|
36 |
| - describe "index template with ilm settings" do |
| 36 | + context "index template with ilm settings" do |
37 | 37 | let(:plugin_settings) { {"manage_template" => true, "template_overwrite" => true} }
|
38 | 38 | let(:plugin) { LogStash::Outputs::ElasticSearch.new(plugin_settings) }
|
39 | 39 |
|
40 |
| - describe "in version 8+" do |
41 |
| - let(:file_path) { described_class.default_template_path(8) } |
42 |
| - let(:template) { described_class.read_template_file(file_path)} |
| 40 | + describe "with custom template" do |
43 | 41 |
|
44 |
| - it "should update settings" do |
45 |
| - expect(plugin).to receive(:maximum_seen_major_version).at_least(:once).and_return(8) |
46 |
| - described_class.add_ilm_settings_to_template(plugin, template) |
47 |
| - expect(template['template']['settings']['index.lifecycle.name']).not_to eq(nil) |
48 |
| - expect(template['template']['settings']['index.lifecycle.rollover_alias']).not_to eq(nil) |
49 |
| - expect(template.include?('settings')).to be_falsey |
| 42 | + describe "in version 8+" do |
| 43 | + let(:file_path) { described_class.default_template_path(8) } |
| 44 | + let(:template) { described_class.read_template_file(file_path)} |
| 45 | + |
| 46 | + it "should update settings" do |
| 47 | + expect(plugin).to receive(:maximum_seen_major_version).at_least(:once).and_return(8) |
| 48 | + described_class.add_ilm_settings_to_template(plugin, template) |
| 49 | + expect(template['template']['settings']['index.lifecycle.name']).not_to eq(nil) |
| 50 | + expect(template['template']['settings']['index.lifecycle.rollover_alias']).not_to eq(nil) |
| 51 | + expect(template.include?('settings')).to be_falsey |
| 52 | + end |
| 53 | + end |
| 54 | + |
| 55 | + describe "in version < 8" do |
| 56 | + let(:file_path) { described_class.default_template_path(7) } |
| 57 | + let(:template) { described_class.read_template_file(file_path)} |
| 58 | + |
| 59 | + it "should update settings" do |
| 60 | + expect(plugin).to receive(:maximum_seen_major_version).at_least(:once).and_return(7) |
| 61 | + described_class.add_ilm_settings_to_template(plugin, template) |
| 62 | + expect(template['settings']['index.lifecycle.name']).not_to eq(nil) |
| 63 | + expect(template['settings']['index.lifecycle.rollover_alias']).not_to eq(nil) |
| 64 | + expect(template.include?('template')).to be_falsey |
| 65 | + end |
50 | 66 | end
|
51 | 67 | end
|
52 | 68 |
|
53 |
| - describe "in version < 8" do |
54 |
| - let(:file_path) { described_class.default_template_path(7) } |
55 |
| - let(:template) { described_class.read_template_file(file_path)} |
| 69 | + context "resolve template setting" do |
| 70 | + let(:plugin_settings) { super().merge({"template_api" => template_api}) } |
| 71 | + |
| 72 | + describe "with composable template API" do |
| 73 | + let(:template_api) { "composable" } |
56 | 74 |
|
57 |
| - it "should update settings" do |
58 |
| - expect(plugin).to receive(:maximum_seen_major_version).at_least(:once).and_return(7) |
59 |
| - described_class.add_ilm_settings_to_template(plugin, template) |
60 |
| - expect(template['settings']['index.lifecycle.name']).not_to eq(nil) |
61 |
| - expect(template['settings']['index.lifecycle.rollover_alias']).not_to eq(nil) |
62 |
| - expect(template.include?('template')).to be_falsey |
| 75 | + it 'resolves composable index template API compatible setting' do |
| 76 | + expect(plugin).to receive(:maximum_seen_major_version).at_least(:once).and_return(8) # required to log |
| 77 | + template = {} |
| 78 | + described_class.resolve_template_settings(plugin, template) |
| 79 | + expect(template["template"]["settings"]).not_to eq(nil) |
| 80 | + end |
| 81 | + end |
| 82 | + |
| 83 | + describe "with legacy template API" do |
| 84 | + let(:template_api) { "legacy" } |
| 85 | + |
| 86 | + it 'resolves legacy index template API compatible setting' do |
| 87 | + expect(plugin).to receive(:maximum_seen_major_version).at_least(:once).and_return(7) # required to log |
| 88 | + template = {} |
| 89 | + described_class.resolve_template_settings(plugin, template) |
| 90 | + expect(template["settings"]).not_to eq(nil) |
| 91 | + end |
| 92 | + end |
| 93 | + |
| 94 | + describe "with `template_api => 'auto'`" do |
| 95 | + let(:template_api) { "auto" } |
| 96 | + |
| 97 | + describe "with ES < 8 versions" do |
| 98 | + |
| 99 | + it 'resolves legacy index template API compatible setting' do |
| 100 | + expect(plugin).to receive(:maximum_seen_major_version).at_least(:once).and_return(7) |
| 101 | + template = {} |
| 102 | + described_class.resolve_template_settings(plugin, template) |
| 103 | + expect(template["settings"]).not_to eq(nil) |
| 104 | + end |
| 105 | + end |
| 106 | + |
| 107 | + describe "with ES >= 8 versions" do |
| 108 | + it 'resolves composable index template API compatible setting' do |
| 109 | + expect(plugin).to receive(:maximum_seen_major_version).at_least(:once).and_return(8) |
| 110 | + template = {} |
| 111 | + described_class.resolve_template_settings(plugin, template) |
| 112 | + expect(template["template"]["settings"]).not_to eq(nil) |
| 113 | + end |
| 114 | + end |
63 | 115 | end
|
64 | 116 | end
|
65 | 117 | end
|
|
0 commit comments