Skip to content

Commit 18e49e1

Browse files
committed
Merge branch 'pr/2715' into stable
* pr/2715: (maint) Test downloader behavior, not implementation (PUP-2705) Use source permissions for fact pluginsync
2 parents 8c5313a + 35ebbc2 commit 18e49e1

File tree

4 files changed

+73
-40
lines changed

4 files changed

+73
-40
lines changed

lib/puppet/configurer/downloader.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ def evaluate
2525
files
2626
end
2727

28-
def initialize(name, path, source, ignore = nil, environment = nil)
29-
@name, @path, @source, @ignore, @environment = name, path, source, ignore, environment
28+
def initialize(name, path, source, ignore = nil, environment = nil, source_permissions = :ignore)
29+
@name, @path, @source, @ignore, @environment, @source_permissions = name, path, source, ignore, environment, source_permissions
3030
end
3131

3232
def catalog
@@ -51,7 +51,7 @@ def default_arguments
5151
:path => path,
5252
:recurse => true,
5353
:source => source,
54-
:source_permissions => :ignore,
54+
:source_permissions => @source_permissions,
5555
:tag => name,
5656
:purge => true,
5757
:force => true,

lib/puppet/configurer/plugin_handler.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ def download_plugins(environment)
1717
Puppet[:pluginfactdest],
1818
Puppet[:pluginfactsource],
1919
Puppet[:pluginsignore],
20-
environment
20+
environment,
21+
:use
2122
)
2223
plugin_fact_downloader.evaluate
2324
end

spec/unit/configurer/downloader_spec.rb

Lines changed: 67 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@
66
describe Puppet::Configurer::Downloader do
77
require 'puppet_spec/files'
88
include PuppetSpec::Files
9+
10+
let(:path) { Puppet[:plugindest] }
11+
let(:source) { 'puppet://puppet/plugins' }
12+
913
it "should require a name" do
1014
lambda { Puppet::Configurer::Downloader.new }.should raise_error(ArgumentError)
1115
end
@@ -21,87 +25,115 @@
2125
dler.source.should == "source"
2226
end
2327

24-
describe "when creating the file that does the downloading" do
25-
before do
26-
@dler = Puppet::Configurer::Downloader.new("foo", "path", "source")
27-
end
28+
def downloader(options = {})
29+
options[:name] ||= "facts"
30+
options[:path] ||= path
31+
options[:source_permissions] ||= :ignore
32+
Puppet::Configurer::Downloader.new(options[:name], options[:path], source, options[:ignore], options[:environment], options[:source_permissions])
33+
end
2834

35+
def generate_file_resource(options = {})
36+
dler = downloader(options)
37+
dler.file
38+
end
39+
40+
describe "when creating the file that does the downloading" do
2941
it "should create a file instance with the right path and source" do
30-
Puppet::Type.type(:file).expects(:new).with { |opts| opts[:path] == "path" and opts[:source] == "source" }
31-
@dler.file
42+
file = generate_file_resource(:path => path, :source => source)
43+
44+
expect(file[:path]).to eq(path)
45+
expect(file[:source]).to eq([source])
3246
end
3347

3448
it "should tag the file with the downloader name" do
35-
Puppet::Type.type(:file).expects(:new).with { |opts| opts[:tag] == "foo" }
36-
@dler.file
49+
name = "mydownloader"
50+
file = generate_file_resource(:name => name)
51+
52+
expect(file[:tag]).to eq([name])
3753
end
3854

3955
it "should always recurse" do
40-
Puppet::Type.type(:file).expects(:new).with { |opts| opts[:recurse] == true }
41-
@dler.file
56+
file = generate_file_resource
57+
58+
expect(file[:recurse]).to be_true
4259
end
4360

4461
it "should always purge" do
45-
Puppet::Type.type(:file).expects(:new).with { |opts| opts[:purge] == true }
46-
@dler.file
62+
file = generate_file_resource
63+
64+
expect(file[:purge]).to be_true
4765
end
4866

4967
it "should never be in noop" do
50-
Puppet::Type.type(:file).expects(:new).with { |opts| opts[:noop] == false }
51-
@dler.file
68+
file = generate_file_resource
69+
70+
expect(file[:noop]).to be_false
5271
end
5372

54-
it "should set source_permissions to ignore" do
55-
Puppet::Type.type(:file).expects(:new).with { |opts| opts[:source_permissions] == :ignore }
56-
@dler.file
73+
it "should set source_permissions to ignore by default" do
74+
file = generate_file_resource
75+
76+
expect(file[:source_permissions]).to eq(:ignore)
77+
end
78+
79+
it "should allow source_permissions to be overridden" do
80+
file = generate_file_resource(:source_permissions => :use)
81+
82+
expect(file[:source_permissions]).to eq(:use)
5783
end
5884

5985
describe "on POSIX", :as_platform => :posix do
6086
it "should always set the owner to the current UID" do
6187
Process.expects(:uid).returns 51
62-
Puppet::Type.type(:file).expects(:new).with { |opts| opts[:owner] == 51 }
63-
@dler.file
88+
89+
file = generate_file_resource(:path => '/path')
90+
expect(file[:owner]).to eq(51)
6491
end
6592

6693
it "should always set the group to the current GID" do
6794
Process.expects(:gid).returns 61
68-
Puppet::Type.type(:file).expects(:new).with { |opts| opts[:group] == 61 }
69-
@dler.file
95+
96+
file = generate_file_resource(:path => '/path')
97+
expect(file[:group]).to eq(61)
7098
end
7199
end
72100

73101
describe "on Windows", :as_platform => :windows do
74102
it "should omit the owner" do
75-
Puppet::Type.type(:file).expects(:new).with { |opts| opts[:owner] == nil }
76-
@dler.file
103+
file = generate_file_resource(:path => 'C:/path')
104+
105+
expect(file[:owner]).to be_nil
77106
end
78107

79108
it "should omit the group" do
80-
Puppet::Type.type(:file).expects(:new).with { |opts| opts[:group] == nil }
81-
@dler.file
109+
file = generate_file_resource(:path => 'C:/path')
110+
111+
expect(file[:group]).to be_nil
82112
end
83113
end
84114

85115
it "should always force the download" do
86-
Puppet::Type.type(:file).expects(:new).with { |opts| opts[:force] == true }
87-
@dler.file
116+
file = generate_file_resource
117+
118+
expect(file[:force]).to be_true
88119
end
89120

90121
it "should never back up when downloading" do
91-
Puppet::Type.type(:file).expects(:new).with { |opts| opts[:backup] == false }
92-
@dler.file
122+
file = generate_file_resource
123+
124+
expect(file[:backup]).to be_false
93125
end
94126

95127
it "should support providing an 'ignore' parameter" do
96-
Puppet::Type.type(:file).expects(:new).with { |opts| opts[:ignore] == [".svn"] }
97-
@dler = Puppet::Configurer::Downloader.new("foo", "path", "source", ".svn")
98-
@dler.file
128+
file = generate_file_resource(:ignore => '.svn')
129+
130+
expect(file[:ignore]).to eq(['.svn'])
99131
end
100132

101133
it "should split the 'ignore' parameter on whitespace" do
102-
Puppet::Type.type(:file).expects(:new).with { |opts| opts[:ignore] == %w{.svn CVS} }
103-
@dler = Puppet::Configurer::Downloader.new("foo", "path", "source", ".svn CVS")
104-
@dler.file
134+
file = generate_file_resource(:ignore => '.svn CVS')
135+
136+
expect(file[:ignore]).to eq(['.svn', 'CVS'])
105137
end
106138
end
107139

spec/unit/configurer/plugin_handler_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ class PluginHandlerTester
2828
Puppet[:pluginfactdest] = plugindest
2929

3030
downloader = mock 'downloader'
31-
Puppet::Configurer::Downloader.expects(:new).with("pluginfacts", plugindest, "psource", "pignore", environment).returns downloader
31+
Puppet::Configurer::Downloader.expects(:new).with("pluginfacts", plugindest, "psource", "pignore", environment, :use).returns downloader
3232
Puppet::Configurer::Downloader.expects(:new).with("plugin", plugindest, "psource", "pignore", environment).returns downloader
3333

3434
downloader.stubs(:evaluate).returns([])

0 commit comments

Comments
 (0)