Sha256: cdb316f038d3013b1e0b40b6130b46ba6acb96a88cdd55cc59ffa6b86158b5cf

Contents?: true

Size: 1.46 KB

Versions: 1

Compression:

Stored size: 1.46 KB

Contents

require production_code

describe Snmpjr do
  describe "#get" do
    context "when the call is synchronous" do

      let(:target) { double Snmpjr::Target }
      let(:community_target) { double :community_target }
      let(:getter) { double Snmpjr::Getter }

      before do
        allow(Snmpjr::Target).to receive(:new).and_return target
        allow(target).to receive(:create).with(agent_details).and_return community_target
        allow(Snmpjr::Getter).to receive(:new).with(target: community_target, max_oids_per_request: 20).and_return getter
      end

      let(:agent_details) { { host: '127.0.0.1', port: 161, community: 'some_community', timeout: 50, retries: 50 } }

      subject { described_class.new(agent_details.merge({max_oids_per_request: 20})) }

      context 'when passed a single oid' do
        it 'performs a synchronous get' do
          expect(getter).to receive(:get).with('1.2.3.4.5.6')
          subject.get '1.2.3.4.5.6'
        end
      end

      context 'when passed multiple oids' do
        it 'performs a get multiple using the getter' do
          expect(getter).to receive(:get_multiple).with(['1.2.3.4.5.6', '6.5.4.3.2.1'])
          subject.get ['1.2.3.4.5.6', '6.5.4.3.2.1']
        end
      end

      context 'when an invalid argument was passed in' do
        it 'raises an ArgumentError' do
          expect {
            subject.get({'oid_value' => '1.3.4.5.6'})
          }.to raise_error ArgumentError
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
snmpjr-0.1.7-java spec/snmpjr_spec.rb