From b284a3ee2c2ebf8e493f8f1caedeadc07b1da1eb Mon Sep 17 00:00:00 2001 From: Justin Stoller Date: Tue, 3 Sep 2024 15:47:56 -0700 Subject: [PATCH] [#9470] Respect environment/settings in base context rich_data value --- lib/puppet.rb | 2 +- spec/unit/resource_spec.rb | 20 ++++++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/lib/puppet.rb b/lib/puppet.rb index 484fda4c4ef..d8a0ec00114 100644 --- a/lib/puppet.rb +++ b/lib/puppet.rb @@ -237,7 +237,7 @@ def self.base_context(settings) :ssl_context => proc { Puppet.runtime[:http].default_ssl_context }, :http_session => proc { Puppet.runtime[:http].create_session }, :plugins => proc { Puppet::Plugins::Configuration.load_plugins }, - :rich_data => false + :rich_data => Puppet[:rich_data] } end diff --git a/spec/unit/resource_spec.rb b/spec/unit/resource_spec.rb index c527358e3f6..28d634991a3 100644 --- a/spec/unit/resource_spec.rb +++ b/spec/unit/resource_spec.rb @@ -906,6 +906,26 @@ def inject_and_set_defaults(resource, scope) # Note: to_stringified_spec.rb has tests for all other data types end + describe 'when serializing resources' do + require 'puppet_spec/compiler' + include PuppetSpec::Compiler + + it 'should do something' do + resource = compile_to_catalog('notify {"foo": message => Deferred("func", ["a", "b", "c"])}') + + # This should be true by default + if Puppet[:rich_data] + expect(resource.to_data_hash.class).to be(Hash) + end + + expect { + Puppet.override(rich_data: false) do + resource.to_data_hash + end + }.to raise_error(Puppet::PreformattedError) + end + end + describe "when converting from json" do before do @data = {