-
Notifications
You must be signed in to change notification settings - Fork 3.5k
Expand file tree
/
Copy pathmixed_codec_spec.rb
More file actions
121 lines (98 loc) · 3.92 KB
/
mixed_codec_spec.rb
File metadata and controls
121 lines (98 loc) · 3.92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
# Licensed to Elasticsearch B.V. under one or more contributor
# license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright
# ownership. Elasticsearch B.V. licenses this file to you under
# the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
require_relative '../framework/fixture'
require_relative '../framework/settings'
require "stud/temporary"
require "stud/try"
require "rspec/wait"
require "yaml"
require "fileutils"
require "logstash/devutils/rspec/spec_helper"
# SPLIT_ESTIMATE: 26
describe "Ruby codec when used in" do
before(:all) {
@fixture = Fixture.new(__FILE__)
}
after(:all) {
@fixture.teardown
}
before(:each) {
# backup the application settings file -- logstash.yml
FileUtils.cp(logstash_service.application_settings_file, "#{logstash_service.application_settings_file}.original")
IO.write(logstash_service.application_settings_file, settings.to_yaml)
}
after(:each) {
logstash_service.teardown
# restore the application settings file -- logstash.yml
FileUtils.mv("#{logstash_service.application_settings_file}.original", logstash_service.application_settings_file)
}
let(:temp_dir) { Stud::Temporary.directory("logstash-pipelinelog-test") }
let(:logstash_service) { @fixture.get_service("logstash") }
let(:out_capture) { Tempfile.new("file_out") }
let(:settings) do
{"path.logs" => temp_dir }
end
context "input Java plugin" do
let(:config) { @fixture.config("input_decode") }
it "should encode correctly to file and don't log any ERROR" do
logstash_service.env_variables = {'PATH_TO_OUT' => out_capture.path}
logstash_service.start_with_stdin(config)
# wait for Logstash to fully start
logstash_service.wait_for_rest_api
logstash_service.write_to_stdin('{"project": "Teleport"}')
sleep(2)
logstash_service.teardown
plainlog_file = "#{temp_dir}/logstash-plain.log"
expect(File.exist?(plainlog_file)).to be true
logs = IO.read(plainlog_file)
expect(logs).to_not include("ERROR")
out_capture.rewind
expect(out_capture.read).to include("\"project\":\"Teleport\"")
end
end
context "input Java plugin with configured codec" do
let(:config) { @fixture.config("input_decode_configured") }
it "should encode correctly to file and don't log any ERROR" do
logstash_service.env_variables = {'PATH_TO_OUT' => out_capture.path}
logstash_service.spawn_logstash("-w", "1", "-e", config)
logstash_service.wait_for_logstash
logstash_service.wait_for_rest_api
logstash_service.write_to_stdin('Teleport ray')
sleep(2)
logstash_service.teardown
plainlog_file = "#{temp_dir}/logstash-plain.log"
expect(File.exist?(plainlog_file)).to be true
logs = IO.read(plainlog_file)
expect(logs).to_not include("ERROR")
out_capture.rewind
expect(out_capture.read).to include("Teleport ray")
end
end
context "output Java plugin" do
let(:config) { @fixture.config("output_encode") }
it "should encode correctly without any ERROR log" do
logstash_service.spawn_logstash("-w", "1", "-e", config)
logstash_service.wait_for_logstash
logstash_service.wait_for_rest_api
logstash_service.teardown
plainlog_file = "#{temp_dir}/logstash-plain.log"
expect(File.exist?(plainlog_file)).to be true
logs = IO.read(plainlog_file)
expect(logs).to_not include("ERROR")
end
end
end