|
6 | 6 | # Licensed under the Apache License, Version 2.0 (the "License"); |
7 | 7 | # you may not use this file except in compliance with the License. |
8 | 8 | # You may obtain a copy of the License at |
9 | | -# |
| 9 | +# |
10 | 10 | # http://www.apache.org/licenses/LICENSE-2.0 |
11 | | -# |
| 11 | +# |
12 | 12 | # Unless required by applicable law or agreed to in writing, software |
13 | 13 | # distributed under the License is distributed on an "AS IS" BASIS, |
14 | 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
22 | 22 | before(:each) do |
23 | 23 | @init_command = "sc" |
24 | 24 | @node = mock("Chef::Node", :null_object => true) |
25 | | - @new_resource = mock("Chef::Resource::Service", |
26 | | - :null_object => true, |
27 | | - :name => "chef", |
28 | | - :service_name => "chef", |
29 | | - :running => false |
30 | | - ) |
| 25 | + @new_resource = Chef::Resource::Service.new("chef") |
31 | 26 | @new_resource.stub!(:pattern).and_return("chef") |
32 | 27 | @new_resource.stub!(:status_command).and_return(false) |
33 | 28 |
|
34 | | - @current_resource = mock("Chef::Resource::Service", |
35 | | - :null_object => true, |
36 | | - :name => "chef", |
37 | | - :service_name => "chef", |
38 | | - :running => false |
39 | | - ) |
| 29 | + @current_resource = Chef::Resource::Service.new("chef") |
40 | 30 | @provider = Chef::Provider::Service::Windows.new(@node, @new_resource) |
41 | 31 | Chef::Resource::Service.stub!(:new).and_return(@current_resource) |
42 | 32 | IO.stub!(:popen).with("#{@init_command} query #{@new_resource.service_name}").and_return(['','','','4']) |
43 | | - IO.stub!(:popen).with("#{@init_command} qc #{@new_resource.service_name}").and_return(['','','','','2']) |
| 33 | + IO.stub!(:popen).with("#{@init_command} qc #{@new_resource.service_name}").and_return(['','','','','2']) |
44 | 34 | end |
45 | | - |
| 35 | + |
46 | 36 | it "should create a current resource with the name of the new resource" do |
47 | 37 | Chef::Resource::Service.should_receive(:new).and_return(@current_resource) |
48 | 38 | @provider.load_current_resource |
|
61 | 51 |
|
62 | 52 | describe Chef::Provider::Service::Windows, "start_service" do |
63 | 53 | before(:each) do |
64 | | - @new_resource = mock("Chef::Resource::Service", |
65 | | - :null_object => true, |
66 | | - :name => "chef", |
67 | | - :service_name => "chef", |
68 | | - :start_command => "sc start chef", |
69 | | - :running => false |
70 | | - ) |
71 | | - @new_resource.stub!(:start_command).and_return(false) |
| 54 | + @new_resource = Chef::Resource::Service.new("chef") |
| 55 | + @new_resource.start_command "sc start chef" |
72 | 56 |
|
73 | 57 | @provider = Chef::Provider::Service::Windows.new(@node, @new_resource) |
74 | 58 | Chef::Resource::Service.stub!(:new).and_return(@current_resource) |
75 | 59 | end |
76 | | - |
| 60 | + |
77 | 61 | it "should call the start command if one is specified" do |
78 | 62 | @new_resource.stub!(:start_command).and_return("#{@new_resource.start_command}") |
79 | | - IO.stub!(:popen).with("#{@new_resource.start_command}").and_return(IO.new(2,'w')) |
80 | | - IO.popen("#{@new_resource.start_command}").stub!(:readlines).and_return(["foo\n","bar\n","baz\n","2 START_PENDING\n"]) |
| 63 | + IO.should_receive(:popen).with("#{@new_resource.start_command}").and_return(StringIO.new("foo\nbar\nbaz\n2 START_PENDING\n")) |
81 | 64 | @provider.start_service() |
82 | 65 | end |
83 | 66 | end |
84 | 67 |
|
85 | 68 | describe Chef::Provider::Service::Windows, "stop_service" do |
86 | 69 | before(:each) do |
87 | 70 | @init_command = "sc" |
88 | | - @new_resource = mock("Chef::Resource::Service", |
89 | | - :null_object => true, |
90 | | - :name => "chef", |
91 | | - :service_name => "chef", |
92 | | - :stop_command => "sc stop chef", |
93 | | - :running => false |
94 | | - ) |
95 | | - @new_resource.stub!(:stop_command).and_return(false) |
| 71 | + @new_resource = Chef::Resource::Service.new("chef") |
| 72 | + @new_resource.stop_command "sc stop chef" |
96 | 73 |
|
97 | 74 | @provider = Chef::Provider::Service::Windows.new(@node, @new_resource) |
98 | 75 | Chef::Resource::Service.stub!(:new).and_return(@current_resource) |
99 | 76 | end |
100 | 77 |
|
101 | 78 | it "should call the stop command if one is specified" do |
102 | 79 | @new_resource.stub!(:stop_command).and_return("#{@new_resource.stop_command}") |
103 | | - IO.stub!(:popen).with("#{@new_resource.stop_command}").and_return(IO.new(2,'w')) |
104 | | - IO.popen("#{@new_resource.stop_command}").stub!(:readlines).and_return(["foo\n","bar\n","baz\n","1 STOPPED\n"]) |
105 | | - @provider.stop_service() |
| 80 | + IO.should_receive(:popen).with("#{@new_resource.stop_command}").and_return(StringIO.new("foo\nbar\nbaz\n1 STOPPED\n")) |
| 81 | + @provider.stop_service().should be_true |
106 | 82 | end |
107 | 83 |
|
108 | 84 | it "should use the built-in command if no stop command is specified" do |
109 | 85 | @new_resource.stub!(:stop_command).and_return(nil) |
110 | 86 | IO.stub!(:popen).with("#{@init_command} stop #{@new_resource.service_name}").and_return(IO.new(2,'w')) |
111 | | - IO.popen("#{@init_command} stop #{@new_resource.service_name}").stub!(:readlines).and_return(["foo\n","bar\n","baz\n","1 STOPPED\n"]) |
112 | | - @provider.stop_service() |
| 87 | + IO.popen("#{@init_command} stop #{@new_resource.service_name}").stub!(:readlines).and_return(["foo\n","bar\n","baz\n","1 STOPPED\n"]) |
| 88 | + @provider.stop_service().should be_true |
113 | 89 | end |
114 | 90 | end |
115 | 91 |
|
116 | 92 | describe Chef::Provider::Service::Windows, "restart_service" do |
117 | 93 | before(:each) do |
118 | 94 | @init_command = "sc" |
119 | | - @new_resource = mock("Chef::Resource::Service", |
120 | | - :null_object => true, |
121 | | - :name => "chef", |
122 | | - :service_name => "chef", |
123 | | - :running => false |
124 | | - ) |
125 | | - @new_resource.stub!(:restart_command).and_return(false) |
126 | | - @new_resource.stub!(:supports).and_return({:restart => false}) |
| 95 | + @new_resource = Chef::Resource::Service.new("chef") |
127 | 96 |
|
128 | 97 | @provider = Chef::Provider::Service::Windows.new(@node, @new_resource) |
129 | 98 | Chef::Resource::Service.stub!(:new).and_return(@current_resource) |
130 | 99 | end |
131 | 100 |
|
132 | | - it "should just call stop, then start when the resource doesn't support restart and no restart_command is specified" do |
133 | | - @new_resource.stub!(:restart_command).and_return(nil) |
134 | | - IO.stub!(:popen).with("#{@init_command} stop #{@new_resource.service_name}").and_return(IO.new(2,'w')) |
135 | | - IO.stub!(:popen).with("#{@init_command} start #{@new_resource.service_name}").and_return(IO.new(2,'w')) |
136 | | - IO.popen("#{@init_command} stop #{@new_resource.service_name}").stub!(:readlines).and_return(["foo\n","bar\n","baz\n","1 STOPPED\n"]) |
137 | | - IO.popen("#{@init_command} start #{@new_resource.service_name}").stub!(:readlines).and_return(["foo\n","bar\n","baz\n","2 START_PENDING\n"]) |
| 101 | + it "should just call stop, then start when the resource doesn't support restart and no restart_command is specified" do |
| 102 | + IO.should_receive(:popen).with("#{@init_command} stop #{@new_resource.service_name}").and_return(StringIO.new("foo\nbar\nbaz\n1 STOPPED\n")) |
| 103 | + IO.should_receive(:popen).with("#{@init_command} start #{@new_resource.service_name}").and_return(StringIO.new("foo\nbar\nbaz\n2 START_PENDING\n")) |
138 | 104 | @provider.restart_service() |
139 | 105 | end |
140 | 106 | end |
141 | 107 |
|
142 | 108 | describe Chef::Provider::Service::Windows, "enable_service" do |
143 | 109 | before(:each) do |
144 | 110 | @init_command = "sc" |
145 | | - @node = mock("Chef::Node", :null_object => true) |
146 | | - @new_resource = mock("Chef::Resource::Service", |
147 | | - :null_object => true, |
148 | | - :name => "chef", |
149 | | - :service_name => "chef", |
150 | | - :status_command => false, |
151 | | - :running => false, |
152 | | - :enabled => false |
153 | | - ) |
| 111 | + @node = Chef::Node.new |
| 112 | + @new_resource = Chef::Resource::Service.new("chef") |
| 113 | + @new_resource.running false |
| 114 | + @new_resource.enabled false |
154 | 115 |
|
155 | 116 | @provider = Chef::Provider::Service::Windows.new(@node, @new_resource) |
156 | 117 | Chef::Resource::Service.stub!(:new).and_return(@current_resource) |
157 | 118 | end |
158 | 119 |
|
159 | 120 | it "should enable service and set the startup type" do |
160 | | - @new_resource.stub!(:startup_type).and_return(:automatic) |
161 | | - IO.popen("sc config chef start= automatic").stub!(:readlines).and_return(["SUCCESS"]) |
162 | | - @provider.enable_service() |
| 121 | + @new_resource.startup_type :automatic |
| 122 | + IO.should_receive(:popen).with("sc config chef start= auto").and_return(StringIO.new("SUCCESS")) |
| 123 | + @provider.enable_service().should be_true |
163 | 124 | end |
164 | 125 | end |
165 | 126 |
|
166 | 127 | describe Chef::Provider::Service::Windows, "disable_service" do |
167 | 128 | before(:each) do |
168 | | - @node = mock("Chef::Node", :null_object => true) |
169 | | - @new_resource = mock("Chef::Resource::Service", |
170 | | - :null_object => true, |
171 | | - :name => "chef", |
172 | | - :service_name => "chef", |
173 | | - :status_command => false |
174 | | - ) |
| 129 | + @node = Chef::Node.new |
| 130 | + @new_resource = Chef::Resource::Service.new("chef") |
175 | 131 |
|
176 | 132 | @provider = Chef::Provider::Service::Windows.new(@node, @new_resource) |
177 | 133 | Chef::Resource::Service.stub!(:new).and_return(@current_resource) |
178 | 134 | end |
179 | 135 |
|
180 | 136 | it "should disable service" do |
181 | | - IO.popen("sc config chef start= disable").stub!(:readlines).and_return(["SUCCESS"]) |
182 | | - @provider.disable_service() |
| 137 | + IO.should_receive(:popen).with("sc config chef start= disabled").and_return(StringIO.new("SUCCESS")) |
| 138 | + @provider.disable_service().should be_true |
183 | 139 | end |
184 | 140 | end |
185 | 141 |
|
0 commit comments