|
39 | 39 |
|
40 | 40 | let(:manticore_urls) { subject.client.pool.urls }
|
41 | 41 | let(:manticore_url) { manticore_urls.first }
|
42 |
| - |
| 42 | + |
43 | 43 | describe "getting a document type" do
|
44 | 44 | it "should default to 'doc'" do
|
45 | 45 | expect(subject.send(:get_event_type, LogStash::Event.new)).to eql("doc")
|
|
88 | 88 | end
|
89 | 89 | end
|
90 | 90 | end
|
91 |
| - |
| 91 | + |
92 | 92 | describe "with auth" do
|
93 | 93 | let(:user) { "myuser" }
|
94 | 94 | let(:password) { ::LogStash::Util::Password.new("mypassword") }
|
95 |
| - |
| 95 | + |
96 | 96 | shared_examples "an authenticated config" do
|
97 | 97 | it "should set the URL auth correctly" do
|
98 | 98 | expect(manticore_url.user).to eq user
|
99 | 99 | end
|
100 | 100 | end
|
101 |
| - |
| 101 | + |
102 | 102 | context "as part of a URL" do
|
103 | 103 | let(:options) {
|
104 | 104 | super.merge("hosts" => ["http://#{user}:#{password.value}@localhost:9200"])
|
105 | 105 | }
|
106 |
| - |
| 106 | + |
107 | 107 | include_examples("an authenticated config")
|
108 | 108 | end
|
109 |
| - |
| 109 | + |
110 | 110 | context "as a hash option" do
|
111 | 111 | let(:options) {
|
112 | 112 | super.merge!(
|
113 | 113 | "user" => user,
|
114 | 114 | "password" => password
|
115 | 115 | )
|
116 | 116 | }
|
117 |
| - |
| 117 | + |
118 | 118 | include_examples("an authenticated config")
|
119 | 119 | end
|
120 | 120 | end
|
|
218 | 218 |
|
219 | 219 | context "429 errors" do
|
220 | 220 | let(:event) { ::LogStash::Event.new("foo" => "bar") }
|
221 |
| - let(:error) do |
| 221 | + let(:error) do |
222 | 222 | ::LogStash::Outputs::ElasticSearch::HttpClient::Pool::BadResponseCodeError.new(
|
223 | 223 | 429, double("url").as_null_object, double("request body"), double("response body")
|
224 | 224 | )
|
|
252 | 252 | end
|
253 | 253 | end
|
254 | 254 | end
|
255 |
| - |
| 255 | + |
256 | 256 | context "with timeout set" do
|
257 | 257 | let(:listener) { Flores::Random.tcp_listener }
|
258 | 258 | let(:port) { listener[2] }
|
|
290 | 290 | end
|
291 | 291 | end
|
292 | 292 |
|
| 293 | + context "with a sprintf action equals to update" do |
| 294 | + let(:options) { {"action" => "%{myactionfield}", "upsert" => '{"message": "some text"}' } } |
| 295 | + |
| 296 | + let(:event) { LogStash::Event.new("myactionfield" => "update", "message" => "blah") } |
| 297 | + |
| 298 | + it "should obtain specific action's params from event_action_tuple" do |
| 299 | + expect(subject.event_action_tuple(event)[1]).to include(:_upsert) |
| 300 | + end |
| 301 | + end |
| 302 | + |
293 | 303 | context "with an invalid action" do
|
294 | 304 | let(:options) { {"action" => "SOME Garbaaage"} }
|
295 | 305 | let(:do_register) { false } # this is what we want to test, so we disable the before(:each) call
|
|
301 | 311 | end
|
302 | 312 |
|
303 | 313 | describe "SSL end to end" do
|
304 |
| - let(:manticore_double) do |
305 |
| - double("manticoreX#{self.inspect}") |
| 314 | + let(:manticore_double) do |
| 315 | + double("manticoreX#{self.inspect}") |
306 | 316 | end
|
307 | 317 |
|
308 | 318 | before(:each) do
|
|
311 | 321 | allow(manticore_double).to receive(:head).with(any_args).and_return(response_double)
|
312 | 322 | allow(manticore_double).to receive(:get).with(any_args).and_return(response_double)
|
313 | 323 | allow(manticore_double).to receive(:close)
|
314 |
| - |
| 324 | + |
315 | 325 | allow(::Manticore::Client).to receive(:new).and_return(manticore_double)
|
316 | 326 | subject.register
|
317 | 327 | end
|
318 |
| - |
| 328 | + |
319 | 329 | shared_examples("an encrypted client connection") do
|
320 | 330 | it "should enable SSL in manticore" do
|
321 | 331 | expect(subject.client.pool.urls.map(&:scheme).uniq).to eql(['https'])
|
322 | 332 | end
|
323 | 333 | end
|
324 | 334 |
|
325 |
| - |
| 335 | + |
326 | 336 | context "With the 'ssl' option" do
|
327 | 337 | let(:options) { {"ssl" => true}}
|
328 | 338 |
|
|
337 | 347 |
|
338 | 348 | describe "retry_on_conflict" do
|
339 | 349 | let(:num_retries) { 123 }
|
340 |
| - let(:event) { LogStash::Event.new("message" => "blah") } |
| 350 | + let(:event) { LogStash::Event.new("myactionfield" => "update", "message" => "blah") } |
341 | 351 | let(:options) { { 'retry_on_conflict' => num_retries } }
|
342 | 352 |
|
343 | 353 | context "with a regular index" do
|
344 | 354 | let(:options) { super.merge("action" => "index") }
|
345 | 355 |
|
346 |
| - it "should interpolate the requested action value when creating an event_action_tuple" do |
| 356 | + it "should not set the retry_on_conflict parameter when creating an event_action_tuple" do |
347 | 357 | action, params, event_data = subject.event_action_tuple(event)
|
348 | 358 | expect(params).not_to include({:_retry_on_conflict => num_retries})
|
349 | 359 | end
|
350 | 360 | end
|
351 | 361 |
|
352 | 362 | context "using a plain update" do
|
353 |
| - let(:options) { super.merge("action" => "update", "retry_on_conflict" => num_retries, "document_id" => 1) } |
| 363 | + let(:options) { super.merge("action" => "update", "retry_on_conflict" => num_retries, "document_id" => 1) } |
354 | 364 |
|
355 |
| - it "should interpolate the requested action value when creating an event_action_tuple" do |
| 365 | + it "should set the retry_on_conflict parameter when creating an event_action_tuple" do |
| 366 | + action, params, event_data = subject.event_action_tuple(event) |
| 367 | + expect(params).to include({:_retry_on_conflict => num_retries}) |
| 368 | + end |
| 369 | + end |
| 370 | + |
| 371 | + context "with a sprintf action that resolves to update" do |
| 372 | + let(:options) { super.merge("action" => "%{myactionfield}", "retry_on_conflict" => num_retries, "document_id" => 1) } |
| 373 | + |
| 374 | + it "should set the retry_on_conflict parameter when creating an event_action_tuple" do |
356 | 375 | action, params, event_data = subject.event_action_tuple(event)
|
357 | 376 | expect(params).to include({:_retry_on_conflict => num_retries})
|
| 377 | + expect(action).to eq("update") |
358 | 378 | end
|
359 | 379 | end
|
360 | 380 | end
|
|
0 commit comments