Skip to content

Commit

Permalink
Covered the #load_yaml method with test
Browse files Browse the repository at this point in the history
  • Loading branch information
andsel committed Jun 15, 2023
1 parent a2c56df commit cf81c3e
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
4 changes: 3 additions & 1 deletion lib/logstash/plugin_mixins/jdbc/value_tracking.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# encoding: utf-8
require "yaml" # persistence
require "date"
require "bigdecimal"

module LogStash module PluginMixins module Jdbc
class ValueTracking
Expand Down Expand Up @@ -32,7 +34,7 @@ def initialize(handler)
end

if Psych::VERSION&.split('.')&.first.to_i >= 4
YAML_PERMITTED_CLASSES = [DateTime, Time, BigDecimal].freeze
YAML_PERMITTED_CLASSES = [::DateTime, ::Time, ::BigDecimal].freeze
def self.load_yaml(source)
Psych::safe_load(source, permitted_classes: YAML_PERMITTED_CLASSES)
end
Expand Down
18 changes: 18 additions & 0 deletions spec/plugin_mixins/jdbc/value_tracking_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# encoding: utf-8
require "logstash/plugin_mixins/jdbc/value_tracking"

module LogStash module PluginMixins module Jdbc
describe ValueTracking do

let(:yaml_date_source) { "--- !ruby/object:DateTime '2023-06-15 09:59:30.558000000 +02:00'\n" }

context "#load_yaml" do
it "should load yaml with date string" do
parsed_date = LogStash::PluginMixins::Jdbc::ValueTracking.load_yaml(yaml_date_source)
expect(parsed_date.year).to eq 2023
expect(parsed_date.month).to eq 6
expect(parsed_date.day).to eq 15
end
end
end
end end end

0 comments on commit cf81c3e

Please sign in to comment.