5 provider_class = Puppet::Type.type(:a2mod).provider(:gentoo)
7 describe provider_class do
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)
18 describe "when fetching modules" do
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)
27 expect(provider_class.modules).to eq(%w{bar baz foo})
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)
34 2.times { expect(provider_class.modules).to eq(%w{bar baz foo}) }
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)
41 expect(provider_class.modules).to eq(%w{bar foo})
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)
51 provider_class.expects(:instances).returns([provider])
52 provider_class.prefetch("ssl" => resource)
56 describe "when flushing" do
59 @filetype.stubs(:backup)
60 provider_class.expects(:filetype).at_least_once.returns(@filetype)
63 @info.stubs(:[]).with(:name).returns("info")
64 @info.stubs(:provider=)
67 @mpm.stubs(:[]).with(:name).returns("mpm")
68 @mpm.stubs(:provider=)
71 @ssl.stubs(:[]).with(:name).returns("ssl")
72 @ssl.stubs(:provider=)
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"})
79 @info.stubs(:should).with(:ensure).returns(:present)
80 provider_class.prefetch("info" => @info)
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=""})
89 @info.stubs(:should).with(:ensure).returns(:absent)
90 @info.stubs(:provider=)
91 provider_class.prefetch("info" => @info)
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"})
100 @info.stubs(:should).with(:ensure).returns(:absent)
101 provider_class.prefetch("info" => @info)
103 @ssl.stubs(:should).with(:ensure).returns(:present)
104 provider_class.prefetch("ssl" => @ssl)
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"})
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)
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"})
127 @info.stubs(:should).with(:ensure).returns(:present)
128 provider_class.prefetch("info" => @info)
130 @ssl.stubs(:should).with(:ensure).returns(:present)
131 provider_class.prefetch("ssl" => @ssl)
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})
140 @info.stubs(:should).with(:ensure).returns(:present)
141 provider_class.prefetch("info" => @info)
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"})
149 @info.stubs(:should).with(:ensure).returns(:present)
150 provider_class.prefetch("info" => @info)
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"})
158 @info.stubs(:should).with(:ensure).returns(:present)
159 provider_class.prefetch("info" => @info)
161 @ssl.stubs(:should).with(:ensure).returns(:present)
162 provider_class.prefetch("ssl" => @ssl)
164 @filetype.unstub(:backup)
165 @filetype.expects(:backup)
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
173 @info.stubs(:should).with(:ensure).returns(:present)
174 provider_class.prefetch("info" => @info)
176 @ssl.stubs(:should).with(:ensure).returns(:present)
177 provider_class.prefetch("ssl" => @ssl)
179 @filetype.unstub(:backup)
180 @filetype.expects(:backup).never