read_file_agent_spec.rb 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. require 'rails_helper'
  2. describe Agents::ReadFileAgent do
  3. before(:each) do
  4. @valid_params = {
  5. 'data_key' => 'data',
  6. }
  7. @checker = Agents::ReadFileAgent.new(:name => 'somename', :options => @valid_params)
  8. @checker.user = users(:jane)
  9. @checker.save!
  10. end
  11. it_behaves_like 'FileHandlingConsumer'
  12. context '#validate_options' do
  13. it 'is valid with the given options' do
  14. expect(@checker).to be_valid
  15. end
  16. it "requires data_key to be present" do
  17. @checker.options['data_key'] = ''
  18. expect(@checker).not_to be_valid
  19. end
  20. end
  21. context '#working' do
  22. it 'is not working without having received an event' do
  23. expect(@checker).not_to be_working
  24. end
  25. it 'is working after receiving an event without error' do
  26. @checker.last_receive_at = Time.now
  27. expect(@checker).to be_working
  28. end
  29. end
  30. context '#receive' do
  31. it "emits an event with the contents of the receives files" do
  32. event = Event.new(payload: {file_pointer: {agent_id: 111, file: 'test'}})
  33. io_mock = mock()
  34. mock(@checker).get_io(event) { StringIO.new("testdata") }
  35. expect { @checker.receive([event]) }.to change(Event, :count).by(1)
  36. expect(Event.last.payload).to eq('data' => 'testdata')
  37. end
  38. end
  39. end