Skip to content

Commit dc6e58e

Browse files
authored
[Test] Fix integration tests for 8.x (#53)
* [Test] Fix integration tests for 8.x The change to ECS compatibility by default in 8.x has broken a large number of integration tests expecting header and property values in the "old" location. This commit fixes the integration tests by adding matchers that will check both locations for header and property values * Update changelog
1 parent 7ae73f3 commit dc6e58e

File tree

3 files changed

+59
-19
lines changed

3 files changed

+59
-19
lines changed

CHANGELOG.md

+3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
## unreleased
2+
- Fix: Fix test failures due to ECS compatibility default changes in `8.x` of logstash [#53](https://github.com/logstash-plugins/logstash-input-jms/pull/53)
3+
14
## 3.2.0
25
- Feat: event_factory support + targets to aid ECS [#49](https://github.com/logstash-plugins/logstash-input-jms/pull/49)
36
- Fix: when configured to add JMS headers to the event, headers whose value is not set no longer result in nil entries on the event

spec/inputs/integration/jms_spec.rb

+19-19
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,11 @@
2323
msg
2424
end
2525
expect(queue.first.get('message')).to eql(message)
26-
expect(queue.first.get('jms_destination')).to_not be_nil
27-
expect(queue.first.get('jms_timestamp')).to_not be_nil
28-
expect(queue.first.get('this')).to be_nil
29-
expect(queue.first.get('that')).to be_nil
30-
expect(queue.first.get('the_other')).to eql('the_other_prop')
26+
expect(queue.first).to have_header('jms_destination')
27+
expect(queue.first).to have_header('jms_timestamp')
28+
expect(queue.first).not_to have_property('this')
29+
expect(queue.first).not_to have_property('this')
30+
expect(queue.first).to have_property_value('the_other', 'the_other_prop')
3131
end
3232
end
3333

@@ -45,8 +45,8 @@
4545
msg
4646
end
4747
expect(queue.first.get('message')).to eql(message)
48-
expect(queue.first.get('this')).to eql(4)
49-
expect(queue.first.get('that')).to eql('that_prop')
48+
expect(queue.first).to have_property_value('this', 4)
49+
expect(queue.first).to have_property_value('that', 'that_prop')
5050
end
5151

5252
it 'does not process messages that do not conform to the message selector' do
@@ -71,8 +71,8 @@
7171
msg
7272
end
7373
expect(queue.first.get('message')).to eql(message)
74-
expect(queue.first.get('this')).to eql(3)
75-
expect(queue.first.get('that')).to eql('that_prop')
74+
expect(queue.first).to have_property_value('this', 3)
75+
expect(queue.first).to have_property_value('that', 'that_prop')
7676
end
7777

7878
it 'does not process messages that do not conform to the message selector' do
@@ -97,8 +97,8 @@
9797
msg
9898
end
9999
expect(queue.first.get('message')).to eql(message)
100-
expect(queue.first.get('this')).to be_within(0.001).of(3.1)
101-
expect(queue.first.get('that')).to eql('that_prop')
100+
expect(get_property_value(queue.first, 'this')).to be_within(0.001).of(3.1)
101+
expect(queue.first).to have_property_value('that', 'that_prop')
102102
end
103103

104104
it 'does not process messages that do not conform to the message selector' do
@@ -124,8 +124,8 @@
124124
msg
125125
end
126126
expect(queue.first.get('message')).to eql(message)
127-
expect(queue.first.get('this')).to eql('this_prop')
128-
expect(queue.first.get('that')).to eql('that_prop')
127+
expect(queue.first).to have_property_value('this', 'this_prop')
128+
expect(queue.first).to have_property_value('that', 'that_prop')
129129
end
130130

131131
it 'does not process messages that do not conform to the message selector' do
@@ -154,11 +154,11 @@
154154
msg
155155
end
156156
expect(queue.first.get('message')).to eql(message)
157-
expect(queue.first.get('jms_destination')).to be_nil
158-
expect(queue.first.get('jms_timestamp')).to_not be_nil
159-
expect(queue.first.get('this')).to eq('this_prop')
160-
expect(queue.first.get('that')).to eq('that_prop')
161-
expect(queue.first.get('the_other')).to eq('the_other_prop')
157+
expect(queue.first).not_to have_header('jms_destination')
158+
expect(queue.first).to have_header('jms_timestamp')
159+
expect(queue.first).to have_property_value('this', 'this_prop')
160+
expect(queue.first).to have_property_value('that', 'that_prop')
161+
expect(queue.first).to have_property_value('the_other', 'the_other_prop')
162162
end
163163
end
164164

@@ -293,7 +293,7 @@
293293
end
294294
expect(queue.size).to eql 1
295295
expect(queue.first.get('message')).to eql 'hello world'
296-
expect(queue.first.get("jms_destination")).to eql(destination)
296+
expect(queue.first).to have_header_value("jms_destination", destination)
297297
end
298298
end
299299
end

spec/inputs/spec_helper.rb

+37
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,40 @@ def send_message(&block)
3535
destination = "#{pub_sub ? 'topic' : 'queue'}://#{queue_name}"
3636
tt.join(3)
3737
end
38+
39+
40+
def get_value(type, actual, name)
41+
actual.get(name) || actual.get("[@metadata][input][jms][#{type}][#{name}]")
42+
end
43+
44+
def get_header_value(actual, name)
45+
get_value('headers', actual, name)
46+
end
47+
48+
def get_property_value(actual, name)
49+
get_value('properties', actual, name)
50+
end
51+
52+
RSpec::Matchers.define :have_header do |expected|
53+
match do |actual|
54+
get_header_value(actual, expected)
55+
end
56+
end
57+
58+
RSpec::Matchers.define :have_property do |expected|
59+
match do |actual|
60+
get_property_value(actual, expected)
61+
end
62+
end
63+
64+
RSpec::Matchers.define :have_header_value do |header, expected|
65+
match do |actual|
66+
expected == get_header_value(actual, header)
67+
end
68+
end
69+
70+
RSpec::Matchers.define :have_property_value do |property, expected|
71+
match do |actual|
72+
expected == get_property_value(actual, property)
73+
end
74+
end

0 commit comments

Comments
 (0)