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(helper_conf) 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