Skip to content

Commit 153b084

Browse files
authored
chore: Use the cucumber tests from the conformance repo (#68)
Signed-off-by: Daniel Azuma <[email protected]>
1 parent c0a3080 commit 153b084

File tree

7 files changed

+96
-1
lines changed

7 files changed

+96
-1
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@ coverage/
66
doc/
77
pkg/
88
tmp/
9+
features/conformance

.toys/ci.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ def handle_result result
1717
def run
1818
::Dir.chdir context_directory
1919
exec_tool ["test"], name: "Tests"
20+
exec_tool ["cucumber"], name: "Behaviors"
2021
exec_tool ["rubocop"], name: "Style checker"
2122
exec_tool ["yardoc"], name: "Docs generation"
2223
exec_tool ["build"], name: "Gem build"

.toys/cucumber.rb

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# frozen_string_literal: true
2+
3+
toys_version! ">= 0.12"
4+
5+
desc "Run cucumber tests"
6+
7+
remaining_args :features
8+
9+
include :bundler
10+
include :exec, e: true
11+
include :git_cache
12+
include :fileutils
13+
14+
def run
15+
setup_features
16+
cmd = ["cucumber", "--publish-quiet"]
17+
cmd += (verbosity > 0 ? ["--format=pretty"] : ["--format=progress"])
18+
cmd += features
19+
exec cmd
20+
end
21+
22+
def setup_features
23+
remote_features = git_cache.find "https://github.com/cloudevents/conformance", path: "features"
24+
local_features = File.join context_directory, "features", "conformance"
25+
rm_rf local_features
26+
cp_r remote_features, local_features
27+
end

Gemfile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
source "https://rubygems.org"
22
gemspec
33

4+
gem "cucumber", "7.0"
45
gem "google-style", "~> 1.25.1"
56
gem "minitest", "~> 5.14"
67
gem "minitest-focus", "~> 1.1"
78
gem "minitest-rg", "~> 5.2"
89
gem "rack", "~> 2.2"
910
gem "redcarpet", "~> 3.5" unless ::RUBY_PLATFORM == "java"
11+
gem "webrick", "~> 1.7"
1012
gem "yard", "~> 0.9.25"

examples/server/app.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@
44
cloud_events_http = CloudEvents::HttpBinding.default
55

66
post "/" do
7-
event = cloud_events_http.decode_rack_env request.env
7+
event = cloud_events_http.decode_event request.env
88
logger.info "Received CloudEvent: #{event.to_h}"
99
end

features/step_definitions/steps.rb

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
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

features/support/env.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
dir = ::File.expand_path "../../lib", __dir__
2+
$LOAD_PATH.unshift dir unless $LOAD_PATH.include? dir
3+
require "cloud_events"

0 commit comments

Comments
 (0)