forked from TonyCTHsu/vaccine
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'tonycthsu/spec-for-crash'
- Loading branch information
Showing
8 changed files
with
175 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/records |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
--require spec_helper | ||
--format documentation |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
3.2.2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
source "https://rubygems.org" | ||
|
||
gem "pry" | ||
gem "rspec" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
GEM | ||
remote: https://rubygems.org/ | ||
specs: | ||
coderay (1.1.3) | ||
diff-lcs (1.5.1) | ||
method_source (1.1.0) | ||
pry (0.14.2) | ||
coderay (~> 1.1) | ||
method_source (~> 1.0) | ||
rspec (3.13.0) | ||
rspec-core (~> 3.13.0) | ||
rspec-expectations (~> 3.13.0) | ||
rspec-mocks (~> 3.13.0) | ||
rspec-core (3.13.0) | ||
rspec-support (~> 3.13.0) | ||
rspec-expectations (3.13.1) | ||
diff-lcs (>= 1.2.0, < 2.0) | ||
rspec-support (~> 3.13.0) | ||
rspec-mocks (3.13.1) | ||
diff-lcs (>= 1.2.0, < 2.0) | ||
rspec-support (~> 3.13.0) | ||
rspec-support (3.13.1) | ||
|
||
PLATFORMS | ||
arm64-darwin-22 | ||
ruby | ||
|
||
DEPENDENCIES | ||
pry | ||
rspec | ||
|
||
BUNDLED WITH | ||
2.5.16 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
require "json" | ||
|
||
RSpec.describe "Records" do | ||
def records | ||
Dir.glob("#{ENV["RECORDS_DIR"] || "records"}/**.json") | ||
end | ||
|
||
describe "trace records" do | ||
it do | ||
trace_report = records.first | ||
|
||
data = JSON.parse(File.read(trace_report), symbolize_names: true) | ||
|
||
expect(data).to a_hash_including( | ||
request: hash_including( | ||
method: "POST", | ||
path: "/v0.4/traces", | ||
headers: hash_including("content-type": "application/msgpack"), | ||
body: an_instance_of(Array).and(having_attributes(length: 1)) | ||
) | ||
) | ||
|
||
render_span, controller_span, rack_span = trace = data[:request][:body].first | ||
|
||
expect(trace.map { |s| s[:trace_id] }.uniq.length).to eq(1) | ||
|
||
expect(render_span).to a_hash_including(name: "rails.render_template") | ||
expect(controller_span).to a_hash_including(name: "rails.action_controller") | ||
expect(rack_span).to a_hash_including(name: "rack.request") | ||
end | ||
end | ||
|
||
describe "crash report records" do | ||
it do | ||
crash_report = records.last | ||
|
||
data = JSON.parse(File.read(crash_report), symbolize_names: true) | ||
|
||
expect(data).to a_hash_including( | ||
request: a_hash_including( | ||
method: "POST", | ||
path: "/telemetry/proxy/api/v2/apmtelemetry", | ||
body: a_hash_including( | ||
request_type: "logs", | ||
payload: an_instance_of(Array) | ||
) | ||
) | ||
) | ||
|
||
payloads = data.dig(:request, :body, :payload) | ||
expect(payloads.length).to eq(1) | ||
|
||
payload = payloads.first | ||
expect(payload).to a_hash_including( | ||
message: an_instance_of(String), | ||
level: "ERROR", | ||
tags: a_string_matching(/SIGSEGV/) | ||
) | ||
|
||
message = JSON.parse(payload[:message], symbolize_names: true) | ||
expect(message).to a_hash_including( | ||
:additional_stacktraces, | ||
:files, | ||
metadata: a_hash_including( | ||
:tags, | ||
family: "ruby" | ||
) | ||
) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
require "pry" | ||
|
||
RSpec.configure do |config| | ||
config.expect_with :rspec do |expectations| | ||
expectations.include_chain_clauses_in_custom_matcher_descriptions = true | ||
end | ||
|
||
config.mock_with :rspec do |mocks| | ||
mocks.verify_partial_doubles = true | ||
end | ||
|
||
# This option will default to `:apply_to_host_groups` in RSpec 4 (and will | ||
# have no way to turn it off -- the option exists only for backwards | ||
# compatibility in RSpec 3). It causes shared context metadata to be | ||
# inherited by the metadata hash of host groups and examples, rather than | ||
# triggering implicit auto-inclusion in groups with matching metadata. | ||
config.shared_context_metadata_behavior = :apply_to_host_groups | ||
end |