|
| 1 | +# frozen_string_literal: true |
| 2 | + |
| 3 | +require "webrick" |
| 4 | +require "stringio" |
| 5 | +require "rack" |
| 6 | + |
| 7 | +Given "HTTP Protocol Binding is supported" do |
| 8 | + @http_binding = CloudEvents::HttpBinding.default |
| 9 | +end |
| 10 | + |
| 11 | +Given "an HTTP request" do |str| |
| 12 | + webrick_request = WEBrick::HTTPRequest.new WEBrick::Config::HTTP |
| 13 | + webrick_request.parse StringIO.new str |
| 14 | + @rack_request = {} |
| 15 | + @rack_request[Rack::REQUEST_METHOD] = webrick_request.request_method |
| 16 | + @rack_request[Rack::SCRIPT_NAME] = webrick_request.script_name |
| 17 | + @rack_request[Rack::PATH_INFO] = webrick_request.path_info |
| 18 | + @rack_request[Rack::QUERY_STRING] = webrick_request.query_string |
| 19 | + @rack_request[Rack::SERVER_NAME] = webrick_request.server_name |
| 20 | + @rack_request[Rack::SERVER_PORT] = webrick_request.port |
| 21 | + @rack_request[Rack::RACK_VERSION] = Rack::VERSION |
| 22 | + @rack_request[Rack::RACK_URL_SCHEME] = webrick_request.ssl? ? "https" : "http" |
| 23 | + @rack_request[Rack::RACK_INPUT] = StringIO.new webrick_request.body |
| 24 | + @rack_request[Rack::RACK_ERRORS] = StringIO.new |
| 25 | + webrick_request.each do |key, value| |
| 26 | + key = key.upcase.tr "-", "_" |
| 27 | + key = "HTTP_#{key}" unless key == "CONTENT_TYPE" |
| 28 | + @rack_request[key] = value |
| 29 | + end |
| 30 | +end |
| 31 | + |
| 32 | +When "parsed as HTTP request" do |
| 33 | + @event = @http_binding.decode_event @rack_request |
| 34 | +end |
| 35 | + |
| 36 | +Then "the attributes are:" do |table| |
| 37 | + table.hashes.each do |hash| |
| 38 | + assert_equal hash["value"], @event[hash["key"]] |
| 39 | + end |
| 40 | +end |
| 41 | + |
| 42 | +Then "the data is equal to the following JSON:" do |str| |
| 43 | + json = JSON.parse str |
| 44 | + assert_equal json, @event.data |
| 45 | +end |
| 46 | + |
| 47 | +Given "Kafka Protocol Binding is supported" do |
| 48 | + pending "Kafka Protocol Binding is not yet implemented" |
| 49 | +end |
| 50 | + |
| 51 | +Given "a Kafka message with payload:" do |_str| |
| 52 | + pending |
| 53 | +end |
| 54 | + |
| 55 | +Given "Kafka headers:" do |_table| |
| 56 | + pending |
| 57 | +end |
| 58 | + |
| 59 | +When "parsed as Kafka message" do |
| 60 | + pending |
| 61 | +end |
0 commit comments