|
6 | 6 | describe Puppet::Configurer::Downloader do
|
7 | 7 | require 'puppet_spec/files'
|
8 | 8 | include PuppetSpec::Files
|
| 9 | + |
| 10 | + let(:path) { Puppet[:plugindest] } |
| 11 | + let(:source) { 'puppet://puppet/plugins' } |
| 12 | + |
9 | 13 | it "should require a name" do
|
10 | 14 | lambda { Puppet::Configurer::Downloader.new }.should raise_error(ArgumentError)
|
11 | 15 | end
|
|
21 | 25 | dler.source.should == "source"
|
22 | 26 | end
|
23 | 27 |
|
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 |
28 | 34 |
|
| 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 |
29 | 41 | 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]) |
32 | 46 | end
|
33 | 47 |
|
34 | 48 | 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]) |
37 | 53 | end
|
38 | 54 |
|
39 | 55 | 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 |
42 | 59 | end
|
43 | 60 |
|
44 | 61 | 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 |
47 | 65 | end
|
48 | 66 |
|
49 | 67 | 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 |
52 | 71 | end
|
53 | 72 |
|
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) |
57 | 83 | end
|
58 | 84 |
|
59 | 85 | describe "on POSIX", :as_platform => :posix do
|
60 | 86 | it "should always set the owner to the current UID" do
|
61 | 87 | 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) |
64 | 91 | end
|
65 | 92 |
|
66 | 93 | it "should always set the group to the current GID" do
|
67 | 94 | 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) |
70 | 98 | end
|
71 | 99 | end
|
72 | 100 |
|
73 | 101 | describe "on Windows", :as_platform => :windows do
|
74 | 102 | 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 |
77 | 106 | end
|
78 | 107 |
|
79 | 108 | 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 |
82 | 112 | end
|
83 | 113 | end
|
84 | 114 |
|
85 | 115 | 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 |
88 | 119 | end
|
89 | 120 |
|
90 | 121 | 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 |
93 | 125 | end
|
94 | 126 |
|
95 | 127 | 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']) |
99 | 131 | end
|
100 | 132 |
|
101 | 133 | 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']) |
105 | 137 | end
|
106 | 138 | end
|
107 | 139 |
|
|
0 commit comments