Sha256: 194fb24734ea9314f46a78262a18f9aefbff09aa221274aac91bc317c1b169f5

Contents?: true

Size: 1.77 KB

Versions: 2

Compression:

Stored size: 1.77 KB

Contents

require 'logstash/devutils/rspec/spec_helper'
require 'logstash/inputs/cloudwatch'
require 'aws-sdk'

describe LogStash::Inputs::CloudWatch do
  subject { LogStash::Inputs::CloudWatch.new(config) }
  let(:config) {
    {
        'access_key_id' => '1234',
        'secret_access_key' => 'secret',
        'metrics' => [ 'CPUUtilization' ],
        'region' => 'us-east-1'
    }
  }


  before do
    Aws.config[:stub_responses] = true
    Thread.abort_on_exception = true
  end

  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

  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

  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

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
logstash-input-cloudwatch-2.2.3 spec/inputs/cloudwatch_spec.rb
logstash-input-cloudwatch-2.2.2 spec/inputs/cloudwatch_spec.rb