|
39 | 39 | @provider = Chef::Provider::Package::Apt.new(@node, @new_resource) |
40 | 40 | Chef::Resource::Package.stub!(:new).and_return(@current_resource) |
41 | 41 | @provider.stub!(:popen4).and_return(@status) |
| 42 | + @stdin = mock("STDIN", :null_object => true) |
| 43 | + @stdout = mock("STDOUT", :null_object => true) |
| 44 | + @stdout.stub!(:each).and_yield("emacs:"). |
| 45 | + and_yield(" Installed: (none)"). |
| 46 | + and_yield(" Candidate: (none)"). |
| 47 | + and_yield(" Version Table:") |
| 48 | + @stderr = mock("STDERR", :null_object => true) |
| 49 | + @pid = mock("PID", :null_object => true) |
42 | 50 | end |
43 | 51 |
|
44 | 52 | it "should create a current resource with the name of the new_resource" do |
|
56 | 64 | @provider.load_current_resource |
57 | 65 | end |
58 | 66 |
|
| 67 | + it "should close stdin on apt-cache policy" do |
| 68 | + @provider.stub!(:popen4).and_yield(@pid, @stdin, @stdout, @stderr).and_return(@status) |
| 69 | + @stdin.should_receive(:close).and_return(true) |
| 70 | + @provider.load_current_resource |
| 71 | + end |
| 72 | + |
| 73 | + it "should read stdout on apt-cache policy" do |
| 74 | + @provider.stub!(:popen4).and_yield(@pid, @stdin, @stdout, @stderr).and_return(@status) |
| 75 | + @stdout.should_receive(:each).and_return(true) |
| 76 | + @provider.load_current_resource |
| 77 | + end |
| 78 | + |
| 79 | + it "should set the installed version to nil on the current resource if apt-cache policy installed version is (none)" do |
| 80 | + @provider.stub!(:popen4).and_yield(@pid, @stdin, @stdout, @stderr).and_return(@status) |
| 81 | + @current_resource.should_receive(:version).with(nil).and_return(true) |
| 82 | + @provider.load_current_resource |
| 83 | + end |
| 84 | + |
| 85 | + it "should set the installed version if apt-cache policy has one" do |
| 86 | + @stdout.stub!(:each).and_yield("emacs:"). |
| 87 | + and_yield(" Installed: 0.1.1"). |
| 88 | + and_yield(" Candidate: (none)"). |
| 89 | + and_yield(" Version Table:") |
| 90 | + @provider.stub!(:popen4).and_yield(@pid, @stdin, @stdout, @stderr).and_return(@status) |
| 91 | + @current_resource.should_receive(:version).with("0.1.1").and_return(true) |
| 92 | + @provider.load_current_resource |
| 93 | + end |
| 94 | + |
| 95 | + it "should set the candidate version if apt-cache policy has one" do |
| 96 | + @stdout.stub!(:each).and_yield("emacs:"). |
| 97 | + and_yield(" Installed: 0.1.1"). |
| 98 | + and_yield(" Candidate: 10"). |
| 99 | + and_yield(" Version Table:") |
| 100 | + @provider.stub!(:popen4).and_yield(@pid, @stdin, @stdout, @stderr).and_return(@status) |
| 101 | + @provider.load_current_resource |
| 102 | + @provider.candidate_version.should eql("10") |
| 103 | + end |
| 104 | + |
59 | 105 | it "should raise an exception if apt-cache policy fails" do |
60 | 106 | @status.should_receive(:exitstatus).and_return(1) |
61 | 107 | lambda { @provider.load_current_resource }.should raise_error(Chef::Exception::Package) |
|
0 commit comments