]> git.donarmstrong.com Git - dsa-puppet.git/blob - 3rdparty/modules/apache/spec/unit/provider/a2mod/gentoo_spec.rb
add Openstack modules to 3rdparty
[dsa-puppet.git] / 3rdparty / modules / apache / spec / unit / provider / a2mod / gentoo_spec.rb
1 #!/usr/bin/env rspec
2
3 require 'spec_helper'
4
5 provider_class = Puppet::Type.type(:a2mod).provider(:gentoo)
6
7 describe provider_class do
8   before :each do
9     provider_class.clear
10   end
11
12   [:conf_file, :instances, :modules, :initvars, :conf_file, :clear].each do |method|
13     it "should respond to the class method #{method}" do
14       expect(provider_class).to respond_to(method)
15     end
16   end
17
18   describe "when fetching modules" do
19     before do
20       @filetype = mock()
21     end
22
23     it "should return a sorted array of the defined parameters" do
24       @filetype.expects(:read).returns(%Q{APACHE2_OPTS="-D FOO -D BAR -D BAZ"\n})
25       provider_class.expects(:filetype).returns(@filetype)
26
27       expect(provider_class.modules).to eq(%w{bar baz foo})
28     end
29
30     it "should cache the module list" do
31       @filetype.expects(:read).once.returns(%Q{APACHE2_OPTS="-D FOO -D BAR -D BAZ"\n})
32       provider_class.expects(:filetype).once.returns(@filetype)
33
34       2.times { expect(provider_class.modules).to eq(%w{bar baz foo}) }
35     end
36
37     it "should normalize parameters" do
38       @filetype.expects(:read).returns(%Q{APACHE2_OPTS="-D FOO -D BAR -D BAR"\n})
39       provider_class.expects(:filetype).returns(@filetype)
40
41       expect(provider_class.modules).to eq(%w{bar foo})
42     end
43   end
44
45   describe "when prefetching" do
46     it "should match providers to resources" do
47       provider = mock("ssl_provider", :name => "ssl")
48       resource = mock("ssl_resource")
49       resource.expects(:provider=).with(provider)
50
51       provider_class.expects(:instances).returns([provider])
52       provider_class.prefetch("ssl" => resource)
53     end
54   end
55
56   describe "when flushing" do
57     before :each do
58       @filetype = mock()
59       @filetype.stubs(:backup)
60       provider_class.expects(:filetype).at_least_once.returns(@filetype)
61
62       @info = mock()
63       @info.stubs(:[]).with(:name).returns("info")
64       @info.stubs(:provider=)
65
66       @mpm = mock()
67       @mpm.stubs(:[]).with(:name).returns("mpm")
68       @mpm.stubs(:provider=)
69
70       @ssl = mock()
71       @ssl.stubs(:[]).with(:name).returns("ssl")
72       @ssl.stubs(:provider=)
73     end
74
75     it "should add modules whose ensure is present" do
76       @filetype.expects(:read).at_least_once.returns(%Q{APACHE2_OPTS=""})
77       @filetype.expects(:write).with(%Q{APACHE2_OPTS="-D INFO"})
78
79       @info.stubs(:should).with(:ensure).returns(:present)
80       provider_class.prefetch("info" => @info)
81
82       provider_class.flush
83     end
84
85     it "should remove modules whose ensure is present" do
86       @filetype.expects(:read).at_least_once.returns(%Q{APACHE2_OPTS="-D INFO"})
87       @filetype.expects(:write).with(%Q{APACHE2_OPTS=""})
88
89       @info.stubs(:should).with(:ensure).returns(:absent)
90       @info.stubs(:provider=)
91       provider_class.prefetch("info" => @info)
92
93       provider_class.flush
94     end
95
96     it "should not modify providers without resources" do
97       @filetype.expects(:read).at_least_once.returns(%Q{APACHE2_OPTS="-D INFO -D MPM"})
98       @filetype.expects(:write).with(%Q{APACHE2_OPTS="-D MPM -D SSL"})
99
100       @info.stubs(:should).with(:ensure).returns(:absent)
101       provider_class.prefetch("info" => @info)
102
103       @ssl.stubs(:should).with(:ensure).returns(:present)
104       provider_class.prefetch("ssl" => @ssl)
105
106       provider_class.flush
107     end
108
109     it "should write the modules in sorted order" do
110       @filetype.expects(:read).at_least_once.returns(%Q{APACHE2_OPTS=""})
111       @filetype.expects(:write).with(%Q{APACHE2_OPTS="-D INFO -D MPM -D SSL"})
112
113       @mpm.stubs(:should).with(:ensure).returns(:present)
114       provider_class.prefetch("mpm" => @mpm)
115       @info.stubs(:should).with(:ensure).returns(:present)
116       provider_class.prefetch("info" => @info)
117       @ssl.stubs(:should).with(:ensure).returns(:present)
118       provider_class.prefetch("ssl" => @ssl)
119
120       provider_class.flush
121     end
122
123     it "should write the records back once" do
124       @filetype.expects(:read).at_least_once.returns(%Q{APACHE2_OPTS=""})
125       @filetype.expects(:write).once.with(%Q{APACHE2_OPTS="-D INFO -D SSL"})
126
127       @info.stubs(:should).with(:ensure).returns(:present)
128       provider_class.prefetch("info" => @info)
129
130       @ssl.stubs(:should).with(:ensure).returns(:present)
131       provider_class.prefetch("ssl" => @ssl)
132
133       provider_class.flush
134     end
135
136     it "should only modify the line containing APACHE2_OPTS" do
137       @filetype.expects(:read).at_least_once.returns(%Q{# Comment\nAPACHE2_OPTS=""\n# Another comment})
138       @filetype.expects(:write).once.with(%Q{# Comment\nAPACHE2_OPTS="-D INFO"\n# Another comment})
139
140       @info.stubs(:should).with(:ensure).returns(:present)
141       provider_class.prefetch("info" => @info)
142       provider_class.flush
143     end
144
145     it "should restore any arbitrary arguments" do
146       @filetype.expects(:read).at_least_once.returns(%Q{APACHE2_OPTS="-Y -D MPM -X"})
147       @filetype.expects(:write).once.with(%Q{APACHE2_OPTS="-Y -X -D INFO -D MPM"})
148
149       @info.stubs(:should).with(:ensure).returns(:present)
150       provider_class.prefetch("info" => @info)
151       provider_class.flush
152     end
153
154     it "should backup the file once if changes were made" do
155       @filetype.expects(:read).at_least_once.returns(%Q{APACHE2_OPTS=""})
156       @filetype.expects(:write).once.with(%Q{APACHE2_OPTS="-D INFO -D SSL"})
157
158       @info.stubs(:should).with(:ensure).returns(:present)
159       provider_class.prefetch("info" => @info)
160
161       @ssl.stubs(:should).with(:ensure).returns(:present)
162       provider_class.prefetch("ssl" => @ssl)
163
164       @filetype.unstub(:backup)
165       @filetype.expects(:backup)
166       provider_class.flush
167     end
168
169     it "should not write the file or run backups if no changes were made" do
170       @filetype.expects(:read).at_least_once.returns(%Q{APACHE2_OPTS="-X -D INFO -D SSL -Y"})
171       @filetype.expects(:write).never
172
173       @info.stubs(:should).with(:ensure).returns(:present)
174       provider_class.prefetch("info" => @info)
175
176       @ssl.stubs(:should).with(:ensure).returns(:present)
177       provider_class.prefetch("ssl" => @ssl)
178
179       @filetype.unstub(:backup)
180       @filetype.expects(:backup).never
181       provider_class.flush
182     end
183   end
184 end