|
3 | 3 | require "helpers/spec_helper"
|
4 | 4 | require "logstash/devutils/rspec/shared_examples"
|
5 | 5 | require "logstash/inputs/file"
|
| 6 | +require "logstash/plugin_mixins/ecs_compatibility_support/spec_helper" |
6 | 7 |
|
| 8 | +require "json" |
7 | 9 | require "tempfile"
|
8 | 10 | require "stud/temporary"
|
9 | 11 | require "logstash/codecs/multiline"
|
|
99 | 101 | end
|
100 | 102 | end
|
101 | 103 |
|
102 |
| - context "when path and host fields exist" do |
103 |
| - let(:name) { "C" } |
104 |
| - it "should not overwrite them" do |
105 |
| - conf = <<-CONFIG |
106 |
| - input { |
107 |
| - file { |
108 |
| - type => "blah" |
109 |
| - path => "#{path_path}" |
110 |
| - start_position => "beginning" |
111 |
| - sincedb_path => "#{sincedb_path}" |
112 |
| - delimiter => "#{TEST_FILE_DELIMITER}" |
113 |
| - codec => "json" |
114 |
| - } |
115 |
| - } |
116 |
| - CONFIG |
117 | 104 |
|
118 |
| - File.open(tmpfile_path, "w") do |fd| |
119 |
| - fd.puts('{"path": "my_path", "host": "my_host"}') |
120 |
| - fd.puts('{"my_field": "my_val"}') |
121 |
| - fd.fsync |
| 105 | + context "when path and host fields exist", :ecs_compatibility_support do |
| 106 | + ecs_compatibility_matrix(:disabled, :v1) do |ecs_select| |
| 107 | + |
| 108 | + before(:each) do |
| 109 | + allow_any_instance_of(described_class).to receive(:ecs_compatibility).and_return(ecs_compatibility) |
122 | 110 | end
|
123 | 111 |
|
124 |
| - events = input(conf) do |pipeline, queue| |
125 |
| - 2.times.collect { queue.pop } |
| 112 | + let(:file_path_target_field ) { ecs_select[disabled: "path", v1: '[log][file][path]'] } |
| 113 | + let(:source_host_target_field) { ecs_select[disabled: "host", v1: '[host][name]'] } |
| 114 | + |
| 115 | + let(:event_with_existing) do |
| 116 | + LogStash::Event.new.tap do |e| |
| 117 | + e.set(file_path_target_field, 'my_path') |
| 118 | + e.set(source_host_target_field, 'my_host') |
| 119 | + end.to_hash |
126 | 120 | end
|
127 | 121 |
|
128 |
| - existing_path_index, added_path_index = "my_val" == events[0].get("my_field") ? [1,0] : [0,1] |
| 122 | + let(:name) { "C" } |
| 123 | + it "should not overwrite them" do |
| 124 | + conf = <<-CONFIG |
| 125 | + input { |
| 126 | + file { |
| 127 | + type => "blah" |
| 128 | + path => "#{path_path}" |
| 129 | + start_position => "beginning" |
| 130 | + sincedb_path => "#{sincedb_path}" |
| 131 | + delimiter => "#{TEST_FILE_DELIMITER}" |
| 132 | + codec => "json" |
| 133 | + } |
| 134 | + } |
| 135 | + CONFIG |
129 | 136 |
|
130 |
| - expect(events[existing_path_index].get("path")).to eq "my_path" |
131 |
| - expect(events[existing_path_index].get("host")).to eq "my_host" |
132 |
| - expect(events[existing_path_index].get("[@metadata][host]")).to eq "#{Socket.gethostname.force_encoding(Encoding::UTF_8)}" |
| 137 | + File.open(tmpfile_path, "w") do |fd| |
| 138 | + fd.puts(event_with_existing.to_json) |
| 139 | + fd.puts('{"my_field": "my_val"}') |
| 140 | + fd.fsync |
| 141 | + end |
133 | 142 |
|
134 |
| - expect(events[added_path_index].get("path")).to eq "#{tmpfile_path}" |
135 |
| - expect(events[added_path_index].get("host")).to eq "#{Socket.gethostname.force_encoding(Encoding::UTF_8)}" |
136 |
| - expect(events[added_path_index].get("[@metadata][host]")).to eq "#{Socket.gethostname.force_encoding(Encoding::UTF_8)}" |
| 143 | + events = input(conf) do |pipeline, queue| |
| 144 | + 2.times.collect { queue.pop } |
| 145 | + end |
| 146 | + |
| 147 | + existing_path_index, added_path_index = "my_val" == events[0].get("my_field") ? [1,0] : [0,1] |
| 148 | + |
| 149 | + expect(events[existing_path_index].get(file_path_target_field)).to eq "my_path" |
| 150 | + expect(events[existing_path_index].get(source_host_target_field)).to eq "my_host" |
| 151 | + expect(events[existing_path_index].get("[@metadata][host]")).to eq "#{Socket.gethostname.force_encoding(Encoding::UTF_8)}" |
| 152 | + |
| 153 | + expect(events[added_path_index].get(file_path_target_field)).to eq "#{tmpfile_path}" |
| 154 | + expect(events[added_path_index].get(source_host_target_field)).to eq "#{Socket.gethostname.force_encoding(Encoding::UTF_8)}" |
| 155 | + expect(events[added_path_index].get("[@metadata][host]")).to eq "#{Socket.gethostname.force_encoding(Encoding::UTF_8)}" |
| 156 | + end |
137 | 157 | end
|
138 | 158 | end
|
139 | 159 |
|
|
0 commit comments