Sha256: 5273a89c240daa1d6cfb9c032d70eabf9bfaef2577072bc7000c7a0caf9fa583

Contents?: true

Size: 1.22 KB

Versions: 3

Compression:

Stored size: 1.22 KB

Contents

# encoding: utf-8
require_relative "../spec_helper"
require "logstash/plugin"

describe LogStash::Outputs::Mongodb do

  let(:uri)        { 'mongodb://localhost:27017' }
  let(:database)   { 'logstash' }
  let(:collection) { 'logs' }

  let(:config) do
    { "uri" => uri, "database" => database, "collection" => collection }
  end

  it "should register" do
    plugin = LogStash::Plugin.lookup("output", "mongodb").new(config)
    expect {plugin.register}.to_not raise_error
  end

  describe "#send" do

    subject { LogStash::Outputs::Mongodb.new(config) }

    let(:properties) { { "message" => "This is a message!"} }
    let(:event)      { LogStash::Event.new(properties) }
    let(:connection) { double("connection") }
    let(:client)     { double("client") }
    let(:collection) { double("collection") }

    before(:each) do
      allow(Mongo::Client).to receive(:new).and_return(connection)
      allow(connection).to receive(:use).and_return(client)
      allow(client).to receive(:[]).and_return(collection)
      allow(collection).to receive(:insert_one)
      subject.register
    end

    it "should send the event to the database" do
      expect(collection).to receive(:insert_one)
      subject.receive(event)
    end
  end

end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
logstash-output-mongodb-2.0.2 spec/outputs/mongodb_spec.rb
logstash-output-mongodb-2.0.1 spec/outputs/mongodb_spec.rb
logstash-output-mongodb-1.0.0 spec/outputs/mongodb_spec.rb