Sha256: f5d9f0171db7c0223fb861157cf50065dc92ac6bb4a87eb4186b955975582c0d

Contents?: true

Size: 1.5 KB

Versions: 7

Compression:

Stored size: 1.5 KB

Contents

require 'ostruct'
require File.join(File.dirname(__FILE__), 'fakes_sending_data')

module NewRelic
  class FakeService
    attr_accessor :request_timeout, :agent_id, :agent_data, :collector, :mock

    include FakesSendingData

    def initialize
      @agent_data = []
      @supported_methods = [ :connect, :metric_data, :transaction_sample_data,
                             :error_data, :sql_trace_data, :profile_data,
                             :get_agent_commands, :shutdown ]
      @collector = NewRelic::Control::Server.new(:name => 'fakehost', :port => 0)
      @id_counter = 0
      @base_expectations = {
        'get_redirect_host'       => 'localhost',
        'connect'                 => { 'agent_run_id' => agent_run_id },
        'get_agent_commands'      => [],
        'metric_data'             => [[{ 'name' => 'Some/Metric/Spec' }, 1]],
        'sql_trace_data'          => nil,
        'transaction_sample_data' => nil,
        'error_data'              => nil,
        'shutdown'                => nil,
      }
      reset
    end

    def agent_run_id
      @id_counter += 1
    end

    def reset
      @mock = @base_expectations.dup
      @id_counter = 0
      @agent_data = []
    end

    def stub_service(method, value)
      @mock[method.to_s] = value
    end
    
    def method_missing(method, *args)
      if @supported_methods.include?(method)
        @agent_data << OpenStruct.new(:action => method, :params => args)
        @mock[method.to_s]
      else
        super
      end
    end  
  end
end

Version data entries

7 entries across 7 versions & 2 rubygems

Version Path
newrelic_rpm-3.5.6.48.beta test/new_relic/fake_service.rb
newrelic_rpm-3.5.6.46.beta test/new_relic/fake_service.rb
newrelic_rpm-3.5.6.42.beta test/new_relic/fake_service.rb
newrelic_rpm-3.5.5.39.beta test/new_relic/fake_service.rb
wd_newrelic_rpm-3.5.5 test/new_relic/fake_service.rb
newrelic_rpm-3.5.5.38 test/new_relic/fake_service.rb
newrelic_rpm-3.5.5.540.dev test/new_relic/fake_service.rb