Skip to content

Commit

Permalink
test local time serialization
Browse files Browse the repository at this point in the history
  • Loading branch information
p committed Nov 4, 2024
1 parent f99462e commit 00f247b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
12 changes: 9 additions & 3 deletions spec/datadog/di/serializer_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ module SerializerHelper
def define_serialize_value_cases(cases)
cases.each do |c|
value = c.fetch(:input)
expected = c.fetch(:expected)
var_name = c[:var_name]

context c.fetch(:name) do
Expand All @@ -18,8 +17,15 @@ def define_serialize_value_cases(cases)
{name: var_name}
end

it "serializes as expected" do
expect(serialized).to eq(expected)
if expected_matches = c[:expected_matches]
it "serialization matches expectation" do
expect(serialized).to match(expected_matches)
end
else
expected = c.fetch(:expected)
it "serializes exactly as specified" do
expect(serialized).to eq(expected)
end
end
end
end
Expand Down
6 changes: 5 additions & 1 deletion spec/datadog/di/serializer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,12 @@ class DISerializerCustomExceptionTestClass; end
expected: {type: "String", notCapturedReason: "redactedIdent"}},
{name: "variable name given and is not a redacted identifier", input: "123", var_name: "normal",
expected: {type: "String", value: "123"}},
{name: 'Time value', input: Time.utc(2020, 1, 2, 3, 4, 5),
# We can assert exact value when the time zone is UTC,
# since we don't know the local time zone ahead of time.
{name: 'Time value in UTC', input: Time.utc(2020, 1, 2, 3, 4, 5),
expected: {type: 'Time', value: '2020-01-02T03:04:05Z'}},
{name: 'Time value in local time zone', input: Time.local(2020, 1, 2, 3, 4, 5),
expected_matches: {type: 'Time', value: %r,\A2020-01-02T03:04:05[-+]\d\d:\d\d\z, }},
{name: 'Date value', input: Date.new(2020, 1, 2),
expected: {type: 'Date', value: '2020-01-02'}},
{name: 'DateTime value', input: DateTime.new(2020, 1, 2, 3, 4, 5),
Expand Down

0 comments on commit 00f247b

Please sign in to comment.