Skip to content

Commit

Permalink
(PUP-1763) Memoize downloader's catalog and file
Browse files Browse the repository at this point in the history
Memoize the catalog and file so it is accessible in tests, instead of setting
expectations on the wrong instance or using *_any_instance_of. This keeps the
old behavior of validating the `file` resource when the downloader is evaluated.
  • Loading branch information
joshcooper committed Jul 15, 2020
1 parent 57667a7 commit 5fddf54
Showing 1 changed file with 15 additions and 9 deletions.
24 changes: 15 additions & 9 deletions lib/puppet/configurer/downloader.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,25 @@ def evaluate

def initialize(name, path, source, ignore = nil, environment = nil, source_permissions = :ignore)
@name, @path, @source, @ignore, @environment, @source_permissions = name, path, source, ignore, environment, source_permissions
end

def catalog
catalog = Puppet::Resource::Catalog.new("PluginSync", @environment)
catalog.host_config = false
catalog.add_resource(file)
catalog
end

def file
args = default_arguments.merge(:path => path, :source => source)
args[:ignore] = ignore.split if ignore
Puppet::Type.type(:file).new(args)
unless @file
args = default_arguments.merge(:path => path, :source => source)
args[:ignore] = ignore.split if ignore
@file = Puppet::Type.type(:file).new(args)
end
@file
end

def catalog
unless @catalog
@catalog = Puppet::Resource::Catalog.new("PluginSync", @environment)
@catalog.host_config = false
@catalog.add_resource(file)
end
@catalog
end

private
Expand Down

0 comments on commit 5fddf54

Please sign in to comment.