|
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
|
|
96 | 96 | endpoint = described_class.template_endpoint(plugin)
|
97 | 97 | expect(endpoint).to be_equal(LogStash::Outputs::ElasticSearch::TemplateManager::LEGACY_TEMPLATE_ENDPOINT)
|
98 | 98 | end
|
99 |
| - |
100 |
| - it "should raise an error when installing the default template" do |
101 |
| - expect(plugin).to receive(:maximum_seen_major_version).at_least(:once).and_return(8) |
102 |
| - expect{ described_class.install_template(plugin) }.to raise_error(LogStash::ConfigurationError, a_string_including("Plugin cannot resolve the default template when using legacy template API with Elasticsearch 8.x (or higher) versions. Please consider using a `template_api => composable` option or set the custom template by providing `template` path.")) |
103 |
| - end |
104 | 99 | end
|
105 | 100 | end
|
106 | 101 |
|
|
117 | 112 | end
|
118 | 113 | end
|
119 | 114 | end
|
| 115 | + |
| 116 | + describe "installing default template" do |
| 117 | + |
| 118 | + describe "when 'template_api' => 'auto'" do |
| 119 | + # by default the `template_api` config is `auto` |
| 120 | + let(:plugin_settings) { {"manage_template" => true } } |
| 121 | + let(:plugin) { LogStash::Outputs::ElasticSearch.new(plugin_settings) } |
| 122 | + |
| 123 | + it "should not raise an error without custom template with ES 7.x" do |
| 124 | + expect(plugin).to receive(:client).at_least(:once).and_return(Object.new) |
| 125 | + expect(plugin.client).to receive(:template_install).at_least(:once).and_return({}) |
| 126 | + expect(plugin).to receive(:maximum_seen_major_version).at_least(:once).and_return(7) |
| 127 | + expect{ described_class.install_template(plugin) }.not_to raise_error |
| 128 | + end |
| 129 | + |
| 130 | + it "should not raise an error with custom template with ES 7.x" do |
| 131 | + file_path = described_class.default_template_path(7) |
| 132 | + plugin = LogStash::Outputs::ElasticSearch.new(plugin_settings.merge({"template" => file_path})) |
| 133 | + expect(plugin).to receive(:client).at_least(:once).and_return(Object.new) |
| 134 | + expect(plugin.client).to receive(:template_install).at_least(:once).and_return({}) |
| 135 | + expect(plugin).to receive(:maximum_seen_major_version).at_least(:once).and_return(7) |
| 136 | + expect{ described_class.install_template(plugin) }.not_to raise_error |
| 137 | + end |
| 138 | + |
| 139 | + it "should not raise an error without custom template with ES 8.x" do |
| 140 | + expect(plugin).to receive(:client).at_least(:once).and_return(Object.new) |
| 141 | + expect(plugin.client).to receive(:template_install).at_least(:once).and_return({}) |
| 142 | + expect(plugin).to receive(:maximum_seen_major_version).at_least(:once).and_return(8) |
| 143 | + expect{ described_class.install_template(plugin) }.not_to raise_error |
| 144 | + end |
| 145 | + |
| 146 | + it "should not raise an error with custom template with ES 8.x" do |
| 147 | + file_path = described_class.default_template_path(8) |
| 148 | + plugin = LogStash::Outputs::ElasticSearch.new(plugin_settings.merge({"template" => file_path})) |
| 149 | + expect(plugin).to receive(:client).at_least(:once).and_return(Object.new) |
| 150 | + expect(plugin.client).to receive(:template_install).at_least(:once).and_return({}) |
| 151 | + expect(plugin).to receive(:maximum_seen_major_version).at_least(:once).and_return(8) |
| 152 | + expect{ described_class.install_template(plugin) }.not_to raise_error |
| 153 | + end |
| 154 | + end |
| 155 | + |
| 156 | + # 'template_api' => 'composable' behaves same |
| 157 | + describe "when 'template_api' => 'legacy'" do |
| 158 | + |
| 159 | + let(:plugin_settings) { {"manage_template" => true, "template_api" => 'legacy'} } |
| 160 | + let(:plugin) { LogStash::Outputs::ElasticSearch.new(plugin_settings) } |
| 161 | + |
| 162 | + it "should raise an error without custom template with ES 7.x" do |
| 163 | + expect(plugin).to receive(:maximum_seen_major_version).at_least(:once).and_return(7) |
| 164 | + expect{ described_class.install_template(plugin) }.to raise_error(LogStash::ConfigurationError, a_string_including("Custom template has to be set When using `template_api` => legacy. Please consider using a `template_api => auto` or set the custom template by providing `template` path.")) |
| 165 | + end |
| 166 | + |
| 167 | + it "should raise an error without custom template with ES 8.x" do |
| 168 | + expect(plugin).to receive(:maximum_seen_major_version).at_least(:once).and_return(8) |
| 169 | + expect{ described_class.install_template(plugin) }.to raise_error(LogStash::ConfigurationError, a_string_including("Custom template has to be set When using `template_api` => legacy. Please consider using a `template_api => auto` or set the custom template by providing `template` path.")) |
| 170 | + end |
| 171 | + |
| 172 | + it "should not raise an error with custom template with ES 7.x" do |
| 173 | + file_path = described_class.default_template_path(7) |
| 174 | + plugin = LogStash::Outputs::ElasticSearch.new(plugin_settings.merge({"template" => file_path})) |
| 175 | + expect(plugin).to receive(:maximum_seen_major_version).at_least(:once).and_return(7) |
| 176 | + expect(plugin).to receive(:client).at_least(:once).and_return(Object.new) |
| 177 | + expect(plugin.client).to receive(:template_install).at_least(:once).and_return({}) |
| 178 | + expect{ described_class.install_template(plugin) }.not_to raise_error |
| 179 | + end |
| 180 | + |
| 181 | + it "should not raise an error with custom template with ES 8.x" do |
| 182 | + file_path = described_class.default_template_path(8) |
| 183 | + plugin = LogStash::Outputs::ElasticSearch.new(plugin_settings.merge({"template" => file_path})) |
| 184 | + expect(plugin).to receive(:maximum_seen_major_version).at_least(:once).and_return(8) |
| 185 | + expect(plugin).to receive(:client).at_least(:once).and_return(Object.new) |
| 186 | + expect(plugin.client).to receive(:template_install).at_least(:once).and_return({}) |
| 187 | + expect{ described_class.install_template(plugin) }.not_to raise_error |
| 188 | + end |
| 189 | + end |
| 190 | + end |
120 | 191 | end
|
0 commit comments