diff options
author | Tim Smith <tsmith@chef.io> | 2018-11-15 19:09:48 -0800 |
---|---|---|
committer | Tim Smith <tsmith@chef.io> | 2018-11-15 19:24:15 -0800 |
commit | 003830c2bc8512a85756042e9699e1768771c4cc (patch) | |
tree | 739aac1741a735b37425dedab9c29775fdd94d29 /spec/unit | |
parent | a9d4f25dd6a6aed743c743dbef7624510b53cf70 (diff) | |
download | chef-003830c2bc8512a85756042e9699e1768771c4cc.tar.gz |
Simplify the service resource specs
Signed-off-by: Tim Smith <tsmith@chef.io>
Diffstat (limited to 'spec/unit')
-rw-r--r-- | spec/unit/resource/service_spec.rb | 142 |
1 files changed, 59 insertions, 83 deletions
diff --git a/spec/unit/resource/service_spec.rb b/spec/unit/resource/service_spec.rb index eb32ddf596..7c2b46a0dc 100644 --- a/spec/unit/resource/service_spec.rb +++ b/spec/unit/resource/service_spec.rb @@ -66,28 +66,6 @@ describe Chef::Resource::Service do end.to raise_error(ArgumentError) end - it "accepts a String for the service_start command" do - resource.start_command "/etc/init.d/chef start" - expect(resource.start_command).to eql("/etc/init.d/chef start") - end - - it "does not accept a regexp for the service start command" do - expect do - resource.start_command /.*/ - end.to raise_error(ArgumentError) - end - - it "accepts a String for the service stop command" do - resource.stop_command "/etc/init.d/chef stop" - expect(resource.stop_command).to eql("/etc/init.d/chef stop") - end - - it "does not accept a regexp for the service stop command" do - expect do - resource.stop_command /.*/ - end.to raise_error(ArgumentError) - end - it "accepts a String for the user property" do resource.user "fakey_fakerton" expect(resource.user).to eql("fakey_fakerton") @@ -104,105 +82,103 @@ describe Chef::Resource::Service do expect(resource.parameters).to eql(param_hash) end - it "accepts a String for the service status command" do - resource.status_command "/etc/init.d/chef status" - expect(resource.status_command).to eql("/etc/init.d/chef status") - end - - it "does not accept a regexp for the service status command" do - expect do - resource.status_command /.*/ - end.to raise_error(ArgumentError) - end - - it "accepts a String for the service restart command" do - resource.restart_command "/etc/init.d/chef restart" - expect(resource.restart_command).to eql("/etc/init.d/chef restart") - end - - it "does not accept a regexp for the service restart command" do - expect do - resource.restart_command /.*/ - end.to raise_error(ArgumentError) - end - - it "accepts a String for the service reload command" do - resource.reload_command "/etc/init.d/chef reload" - expect(resource.reload_command).to eql("/etc/init.d/chef reload") - end - - it "does not accept a regexp for the service reload command" do - expect do - resource.reload_command /.*/ - end.to raise_error(ArgumentError) - end - - it "accepts a String for the service init command" do + it "accepts a String for the init_command property" do resource.init_command "/etc/init.d/chef" expect(resource.init_command).to eql("/etc/init.d/chef") end - it "does not accept a regexp for the service init command" do + it "does not accept a regexp for the init_command property" do expect do resource.init_command /.*/ end.to raise_error(ArgumentError) end - it "accepts an array for options" do + it "accepts an array for options property" do resource.options ["-r", "-s"] expect(resource.options).to eql(["-r", "-s"]) end - it "accepts a String for options" do + it "accepts a String for options property" do resource.options "-r" expect(resource.options).to eql(["-r"]) end - it "accepts a String with multiple flags for options" do + it "accepts a String with multiple flags for options property" do resource.options "-r -s" expect(resource.options).to eql(["-r", "-s"]) end - it "does not accept a boolean for options" do + it "does not accept a boolean for options property" do expect do resource.options true end.to raise_error(ArgumentError) end - %w{enabled running}.each do |attrib| - it "accepts true for #{attrib}" do - resource.send(attrib, true) - expect(resource.send(attrib)).to eql(true) + %w{restart_command start_command stop_command status_command reload_command}.each do |prop| + it "accepts a String for the #{prop} property" do + resource.send(prop, "service foo bar") + expect(resource.send(prop)).to eql("service foo bar") end - it "accepts false for #{attrib}" do - resource.send(attrib, false) - expect(resource.send(attrib)).to eql(false) + it "accepts false for #{prop} property" do + resource.send(prop, false) + expect(resource.send(prop)).to eql(false) end - it "does not accept a String for #{attrib}" do - expect { resource.send(attrib, "poop") }.to raise_error(ArgumentError) + it "does not accept a regexp for the #{prop} property" do + expect { resource.send(prop, /.*/) }.to raise_error(ArgumentError) end + end + + it "accepts a String for priority property" do + resource.priority "1" + expect(resource.priority).to eql("1") + end - it "defaults all the feature support to nil" do - support_hash = { status: nil, restart: nil, reload: nil } - expect(resource.supports).to eq(support_hash) + it "accepts an Integer for priority property" do + resource.priority 1 + expect(resource.priority).to eql(1) + end + + it "accepts an Integer for timeout property" do + resource.timeout 1 + expect(resource.timeout).to eql(1) + end + + %w{enabled running}.each do |prop| + it "accepts true for #{prop} property" do + resource.send(prop, true) + expect(resource.send(prop)).to eql(true) end - it "allows you to set what features this resource supports as a array" do - support_array = [ :status, :restart ] - support_hash = { status: true, restart: true } - resource.supports(support_array) - expect(resource.supports).to eq(support_hash) + it "accepts false for #{prop} property" do + resource.send(prop, false) + expect(resource.send(prop)).to eql(false) end - it "allows you to set what features this resource supports as a hash" do - support_hash = { status: true, restart: true } - resource.supports(support_hash) - expect(resource.supports).to eq(support_hash) + it "does not accept a String for #{prop} property" do + expect { resource.send(prop, "poop") }.to raise_error(ArgumentError) end end + it "defaults all the feature support to nil" do + support_hash = { status: nil, restart: nil, reload: nil } + expect(resource.supports).to eq(support_hash) + end + + it "allows you to set what features this resource supports as an array" do + support_array = [ :status, :restart ] + support_hash = { status: true, restart: true } + resource.supports(support_array) + expect(resource.supports).to eq(support_hash) + end + + it "allows you to set what features this resource supports as a hash" do + support_hash = { status: true, restart: true } + resource.supports(support_hash) + expect(resource.supports).to eq(support_hash) + end + describe "when it has pattern and supports" do before do resource.service_name("superfriend") @@ -216,7 +192,7 @@ describe Chef::Resource::Service do expect(state[:running]).to eql(false) end - it "returns the service name as its identity" do + it "returns the service_name property as its identity" do expect(resource.identity).to eq("superfriend") end end |