spec/inputs/cloudwatch_spec.rb in logstash-input-cloudwatch-2.1.1 vs spec/inputs/cloudwatch_spec.rb in logstash-input-cloudwatch-2.2.2

- old
+ new

@@ -1,66 +1,72 @@ require 'logstash/devutils/rspec/spec_helper' require 'logstash/inputs/cloudwatch' require 'aws-sdk' describe LogStash::Inputs::CloudWatch do - before do - AWS.stub! - Thread.abort_on_exception = true - end - - describe '#register' do - let(:config) { - { + subject { LogStash::Inputs::CloudWatch.new(config) } + let(:config) { + { 'access_key_id' => '1234', 'secret_access_key' => 'secret', - 'namespace' => 'AWS/EC2', - 'filters' => { 'instance-id' => 'i-12344321' }, + 'metrics' => [ 'CPUUtilization' ], 'region' => 'us-east-1' - } } - subject { LogStash::Inputs::CloudWatch.new(config) } + } - it "registers succesfully" do - expect { subject.register }.to_not raise_error - end + + before do + Aws.config[:stub_responses] = true + Thread.abort_on_exception = true end - context "EC2 events" do - let(:config) { - { - 'access_key_id' => '1234', - 'secret_access_key' => 'secret', - 'namespace' => 'AWS/EC2', - 'metrics' => [ 'CPUUtilization' ], - 'filters' => { 'tag:Monitoring' => 'Yes' }, - 'region' => 'us-east-1' - } - } + shared_examples_for 'it requires filters' do + context 'without filters' do + it "raises an error" do + expect { subject.register }.to raise_error(StandardError) + end + end + + context 'with filters' do + let (:config) { super().merge('filters' => { 'tag:Monitoring' => 'Yes' })} + + it "registers succesfully" do + expect { subject.register }.to_not raise_error + end + end end - context "EBS events" do - let(:config) { - { - 'access_key_id' => '1234', - 'secret_access_key' => 'secret', - 'namespace' => 'AWS/EBS', - 'metrics' => [ 'VolumeQueueLength' ], - 'filters' => { 'tag:Monitoring' => 'Yes' }, - 'region' => 'us-east-1' - } - } + shared_examples_for 'it does not require filters' do + context 'without filters' do + it "registers succesfully" do + expect { subject.register }.to_not raise_error + end + end + + context 'with filters' do + let (:config) { super().merge('filters' => { 'tag:Monitoring' => 'Yes' })} + + it "registers succesfully" do + expect { subject.register }.to_not raise_error + end + end end - context "RDS events" do - let(:config) { - { - 'access_key_id' => '1234', - 'secret_access_key' => 'secret', - 'namespace' => 'AWS/RDS', - 'metrics' => [ 'CPUUtilization', 'CPUCreditUsage' ], - 'filters' => { 'EngineName' => 'mysql' }, - 'region' => 'us-east-1' - } - } + describe '#register' do + + context "EC2 namespace" do + let(:config) { super().merge('namespace' => 'AWS/EC2') } + it_behaves_like 'it does not require filters' + end + + context "EBS namespace" do + let(:config) { super().merge('namespace' => 'AWS/EBS') } + it_behaves_like 'it requires filters' + end + + context "RDS namespace" do + let(:config) { super().merge('namespace' => 'AWS/RDS') } + it_behaves_like 'it requires filters' + end + end end