Sha256: bb787695d8d5f0d8ebb9958c667649675349f81f8a400102af1cf320b523b21f

Contents?: true

Size: 1.71 KB

Versions: 35

Compression:

Stored size: 1.71 KB

Contents

require 'spec_helper'
require 'flydata/api_client'
require_relative '../helper_shared_context'

module Flydata
  module Helper
    module Action
      describe SendLogs do
        include_context 'helper context'

        let(:agent) { double("agent") }

        let(:api_client) do
          a = double("api_client")
          allow(a).to receive(:agent).and_return(agent)
          a
        end

        let(:send_log_action) do
          allow(ApiClient).to receive(:instance).and_return(api_client)
          described_class.new(config)
        end

        let(:action_info) do
          { id: 101, config: %Q|{"num_of_lines" : "10"}| }
        end

        describe "#execute" do
          before do
            File.open(FLYDATA_LOG, 'w') do |f|
              0.upto(500) do |i|
                f.write("line#{i}\n")
              end
            end
          end
          context "action config does not have num_of_lines property" do
            it "posts default number of lines to api_client" do
              expect(agent).to receive(:send_logs) do |action_id, logs|
                expect(action_id).to eq(101)
                expect(logs.count("\n")).to eq(SendLogs::DEFAULT_NUM_OF_LINES)
              end
              send_log_action.execute({id:101, config: nil})
            end
          end
          context "action config has num_of_lines property" do
            it "posts configured number of lines to api_client" do
              expect(agent).to receive(:send_logs) do |action_id, logs|
                expect(action_id).to eq(101)
                expect(logs.count("\n")).to eq(10)
              end
              send_log_action.execute(action_info)
            end
          end
        end
      end
    end
  end
end

Version data entries

35 entries across 35 versions & 1 rubygems

Version Path
flydata-0.7.19 spec/flydata/helper/action/send_logs_spec.rb
flydata-0.7.18 spec/flydata/helper/action/send_logs_spec.rb
flydata-0.7.17 spec/flydata/helper/action/send_logs_spec.rb
flydata-0.7.16 spec/flydata/helper/action/send_logs_spec.rb
flydata-0.7.15 spec/flydata/helper/action/send_logs_spec.rb
flydata-0.7.14 spec/flydata/helper/action/send_logs_spec.rb
flydata-0.7.13 spec/flydata/helper/action/send_logs_spec.rb
flydata-0.7.12 spec/flydata/helper/action/send_logs_spec.rb
flydata-0.7.11 spec/flydata/helper/action/send_logs_spec.rb
flydata-0.7.10 spec/flydata/helper/action/send_logs_spec.rb
flydata-0.7.9 spec/flydata/helper/action/send_logs_spec.rb
flydata-0.7.8 spec/flydata/helper/action/send_logs_spec.rb
flydata-0.7.7 spec/flydata/helper/action/send_logs_spec.rb
flydata-0.7.6 spec/flydata/helper/action/send_logs_spec.rb
flydata-0.7.5 spec/flydata/helper/action/send_logs_spec.rb
flydata-0.7.4 spec/flydata/helper/action/send_logs_spec.rb
flydata-0.7.2.1 spec/flydata/helper/action/send_logs_spec.rb
flydata-0.7.2 spec/flydata/helper/action/send_logs_spec.rb
flydata-0.7.1 spec/flydata/helper/action/send_logs_spec.rb
flydata-0.7.0 spec/flydata/helper/action/send_logs_spec.rb