Skip to content
This repository was archived by the owner on Jul 19, 2023. It is now read-only.

Commit 128e348

Browse files
committed
Test find_log_groups when log_group_prefix is set to false
1 parent 50ce964 commit 128e348

File tree

1 file changed

+39
-7
lines changed

1 file changed

+39
-7
lines changed

spec/inputs/cloudwatch_logs_spec.rb

Lines changed: 39 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
# encoding: utf-8
2-
require "logstash/devutils/rspec/spec_helper"
3-
require "logstash/inputs/cloudwatch_logs"
2+
require 'logstash/devutils/rspec/spec_helper'
3+
require 'logstash/inputs/cloudwatch_logs'
4+
require 'aws-sdk-resources'
5+
require 'aws-sdk'
46

57
describe LogStash::Inputs::CloudWatch_Logs do
68
let(:config) {
@@ -18,21 +20,51 @@
1820
end
1921

2022

21-
context "when interrupting the plugin" do
22-
let(:config) { super.merge({ "interval" => 5 }) }
23+
context 'when interrupting the plugin' do
24+
let(:config) {super.merge({'interval' => 5})}
2325

2426
before do
25-
expect_any_instance_of(LogStash::Inputs::CloudWatch_Logs).to receive(:process_group)
27+
expect_any_instance_of(LogStash::Inputs::CloudWatch_Logs).to receive(:process_group).and_return(nil)
2628
end
2729

28-
it_behaves_like "an interruptible input plugin"
30+
it_behaves_like 'an interruptible input plugin'
2931
end
3032

3133
describe '#register' do
3234
subject {LogStash::Inputs::CloudWatch_Logs.new(config)}
3335

34-
it "registers succesfully" do
36+
it 'registers succesfully' do
3537
expect {subject.register}.to_not raise_error
3638
end
3739
end
40+
41+
describe '#find_log_groups without prefix true' do
42+
context 'with an array in the config' do
43+
subject {LogStash::Inputs::CloudWatch_Logs.new(config)}
44+
45+
it 'passes through configuration' do
46+
expect(subject.find_log_groups).to eq(['sample-log-group'])
47+
end
48+
end
49+
50+
context 'with a single string in the log_group' do
51+
subject {LogStash::Inputs::CloudWatch_Logs.new(config.merge({'log_group' => 'sample-log-group-string'}))}
52+
53+
it 'array-ifies the single string' do
54+
expect(subject.find_log_groups).to eq(['sample-log-group-string'])
55+
end
56+
end
57+
end
58+
59+
# describe '#find_log_groups with prefix true' do
60+
# subject {LogStash::Inputs::CloudWatch_Logs.new(config.merge({'log_group_prefix' => true}))}
61+
#
62+
# before(:each) {subject.register}
63+
#
64+
# it 'should create list of prefixes' do
65+
# expect_any_instance_of(Aws::CloudWatchLogs::Resource).to receive(:describe_log_groups).and_return({'log_groups' => [{'log_group_name' => '1'},{'log_group_name' => '2'}]})
66+
# expect(subject.find_log_groups).to eq(['sample-log-group-1', 'sample-log-group-2'])
67+
# end
68+
# end
69+
3870
end

0 commit comments

Comments
 (0)