Sha256: 0290f0559412bce03d2e8b6284b7bf5e507b7b201effb7c1a69276cfd5eb6d09

Contents?: true

Size: 1.81 KB

Versions: 10

Compression:

Stored size: 1.81 KB

Contents

require_relative '../../response'

module Datadog
  module Transport
    module HTTP
      module Adapters
        # Adapter for testing
        class Test
          attr_reader \
            :buffer,
            :status

          # @param buffer [Array] an optional array that will capture all spans sent to this adapter, defaults to +nil+
          # @deprecated Positional parameters are deprecated. Use named parameters instead.
          def initialize(buffer = nil, **options)
            @buffer = buffer || options[:buffer]
            @mutex = Mutex.new
            @status = 200
          end

          def call(env)
            add_request(env)
            Response.new(status)
          end

          def buffer?
            !@buffer.nil?
          end

          def add_request(env)
            @mutex.synchronize { buffer << env } if buffer?
          end

          def set_status!(status)
            @status = status
          end

          def url; end

          # Response for test adapter
          class Response
            include Datadog::Transport::Response

            attr_reader \
              :body,
              :code

            def initialize(code, body = nil)
              @code = code
              @body = body
            end

            def payload
              @body
            end

            def ok?
              code.between?(200, 299)
            end

            def unsupported?
              code == 415
            end

            def not_found?
              code == 404
            end

            def client_error?
              code.between?(400, 499)
            end

            def server_error?
              code.between?(500, 599)
            end

            def inspect
              "#{super}, code:#{code}"
            end
          end
        end
      end
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
ddtrace-1.14.0 lib/ddtrace/transport/http/adapters/test.rb
ddtrace-1.13.1 lib/ddtrace/transport/http/adapters/test.rb
ddtrace-1.13.0 lib/ddtrace/transport/http/adapters/test.rb
ddtrace-1.12.1 lib/ddtrace/transport/http/adapters/test.rb
ddtrace-1.12.0 lib/ddtrace/transport/http/adapters/test.rb
ddtrace-1.11.1 lib/ddtrace/transport/http/adapters/test.rb
ddtrace-1.11.0 lib/ddtrace/transport/http/adapters/test.rb
ddtrace-1.11.0.beta1 lib/ddtrace/transport/http/adapters/test.rb
ddtrace-1.10.1 lib/ddtrace/transport/http/adapters/test.rb
ddtrace-1.10.0 lib/ddtrace/transport/http/adapters/test.rb