|
1 | 1 | # |
2 | 2 | # Author:: Lee Jensen (<ljensen@engineyard.com>) |
| 3 | +# Author:: AJ Christensen (<aj@opscode.com>) |
3 | 4 | # Copyright:: Copyright (c) 2008 Opscode, Inc. |
4 | 5 | # License:: Apache License, Version 2.0 |
5 | 6 | # |
|
28 | 29 |
|
29 | 30 | @provider = Chef::Provider::Service::Gentoo.new(@node, @new_resource) |
30 | 31 | Chef::Resource::Service.stub!(:new).and_return(@current_resource) |
31 | | - File.stub!(:exists?).and_return(true) |
32 | | - |
33 | | - @status = mock("Status", :exitstatus => 0) |
34 | 32 | @provider.stub!(:popen4).and_return(@status) |
35 | | - @stdin = mock("STDIN", :null_object => true) |
36 | | - @stdout = mock("STDOUT", :null_object => true) |
37 | | - @stdout.stub!(:each_line).and_yield(" gfs | default ") |
38 | | - @stderr = mock("STDERR", :null_object => true) |
39 | | - @pid = mock("PID", :null_object => true) |
| 33 | + @provider.stub!(:run_command).with(:command => "/etc/init.d/chef status").and_return(true) |
| 34 | + File.stub!(:exists?).with("/etc/init.d/chef").and_return(true) |
| 35 | + File.stub!(:exists?).with("/sbin/rc-update").and_return(true) |
| 36 | + File.stub!(:exists?).with("/etc/runlevels/default/chef").and_return(false) |
| 37 | + File.stub!(:readable?).with("/etc/runlevels/default/chef").and_return(false) |
40 | 38 | end |
41 | 39 |
|
42 | 40 | describe "load_current_resource" do |
43 | 41 | it "should raise Chef::Exceptions::Service if /sbin/rc-update does not exist" do |
44 | 42 | File.should_receive(:exists?).with("/sbin/rc-update").and_return(false) |
45 | 43 | lambda { @provider.load_current_resource }.should raise_error(Chef::Exceptions::Service) |
46 | 44 | end |
47 | | - |
| 45 | + |
| 46 | + describe "when detecting the service enable state" do |
| 47 | + describe "and the glob returns a default service script file" do |
| 48 | + before do |
| 49 | + Dir.stub!(:glob).with("/etc/runlevels/**/chef").and_return(["/etc/runlevels/default/chef"]) |
| 50 | + end |
| 51 | + |
| 52 | + describe "and the file exists and is readable" do |
| 53 | + before do |
| 54 | + File.stub!(:exists?).with("/etc/runlevels/default/chef").and_return(true) |
| 55 | + File.stub!(:readable?).with("/etc/runlevels/default/chef").and_return(true) |
| 56 | + end |
| 57 | + it "should set enabled to true" do |
| 58 | + @current_resource.should_receive(:enabled).with(true).and_return(true) |
| 59 | + @provider.load_current_resource |
| 60 | + end |
| 61 | + end |
| 62 | + |
| 63 | + describe "and the file exists but is not readable" do |
| 64 | + before do |
| 65 | + File.stub!(:exists?).with("/etc/runlevels/default/chef").and_return(true) |
| 66 | + File.stub!(:readable?).with("/etc/runlevels/default/chef").and_return(false) |
| 67 | + end |
| 68 | + |
| 69 | + it "should set enabled to false" do |
| 70 | + @current_resource.should_receive(:enabled).with(false).and_return(false) |
| 71 | + @provider.load_current_resource |
| 72 | + end |
| 73 | + end |
| 74 | + |
| 75 | + describe "and the file does not exist" do |
| 76 | + before do |
| 77 | + File.stub!(:exists?).with("/etc/runlevels/default/chef").and_return(false) |
| 78 | + File.stub!(:readable?).with("/etc/runlevels/default/chef").and_return("foobarbaz") |
| 79 | + end |
| 80 | + |
| 81 | + it "should set enabled to false" do |
| 82 | + @current_resource.should_receive(:enabled).with(false).and_return(false) |
| 83 | + @provider.load_current_resource |
| 84 | + end |
| 85 | + |
| 86 | + end |
| 87 | + end |
| 88 | + |
| 89 | + end |
| 90 | + |
| 91 | +=begin |
48 | 92 | it "should set enabled true if rc-update indicates service is in default runlevel" do |
49 | 93 | @stdout.should_receive(:each_line). |
50 | 94 | and_yield(' gfs | default '). |
|
66 | 110 | @provider.load_current_resource |
67 | 111 | @current_resource.enabled.should be_false |
68 | 112 | end |
| 113 | +=end |
69 | 114 |
|
70 | 115 | it "should return the current_resource" do |
71 | 116 | @provider.load_current_resource.should == @current_resource |
|
0 commit comments