Sha256: 3e34ec7d484410741f1450cb6e886196a92dc5b94f331fdf82efe2231345dd5a

Contents?: true

Size: 999 Bytes

Versions: 4

Compression:

Stored size: 999 Bytes

Contents

require 'json'
require 'faraday'
require 'request_tracer'
require 'request_tracer/trace'
require 'rest-client'

class TestApp
  RequestTracer.integrate_with(:rest_client)
  def call(env)
    store_current_trace_info # store so tests can look at historical data

    req = Rack::Request.new(env)
    if req.path == '/hello_world'
      [ 200, {'Content-Type' => 'application/json'}, ['Hello World'] ]
    elsif req.path == '/ouroboros' # this path will cause the TestApp to call the helloworld path of the app in certain port
      port = Rack::Utils.parse_query(env['QUERY_STRING'], "&")['out_port']
      response = RestClient.get("http://localhost:#{port}/hello_world")
      [ 200, {'Content-Type' => 'application/json'}, ["Ouroboros says #{response}"]]
    else
      [ 500, {'Content-Type' => "text/txt"}, ["Unrecognized path #{req.path}"]]
    end
  end

  def store_current_trace_info
    $stderr.puts "%%% #{(Time.now.to_f * 1000).to_i} #{RequestTracer.latest_trace_hash.to_json}"
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
request-tracer-0.7.0 spec/support/test_app.rb
request-tracer-0.6.6 spec/support/test_app.rb
request-tracer-0.6.5 spec/support/test_app.rb
request-tracer-0.6.4 spec/support/test_app.rb