summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorkaustubh-d <kaustubh@clogeny.com>2014-09-11 22:37:57 +0530
committerkaustubh-d <kaustubh@clogeny.com>2014-09-11 22:37:57 +0530
commit65ce1d839b427bf3902b98636cb900135aa02817 (patch)
treea8d5fae254a3ab033f719ec1872f045548fffd27
parent395f6f3868ab1c696365a02a75c8ef0db7757820 (diff)
downloadchef-65ce1d839b427bf3902b98636cb900135aa02817.tar.gz
aixinit specs
-rw-r--r--spec/unit/provider/service/aixinit_service_spec.rb269
1 files changed, 269 insertions, 0 deletions
diff --git a/spec/unit/provider/service/aixinit_service_spec.rb b/spec/unit/provider/service/aixinit_service_spec.rb
new file mode 100644
index 0000000000..bb090b112c
--- /dev/null
+++ b/spec/unit/provider/service/aixinit_service_spec.rb
@@ -0,0 +1,269 @@
+#
+# Author:: kaustubh (<kaustubh@clogeny.com>)
+# Copyright:: Copyright (c) 2014 Chef Software, Inc.
+# License:: Apache License, Version 2.0
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+require 'spec_helper'
+
+describe Chef::Provider::Service::AixInit do
+ before(:each) do
+ @node = Chef::Node.new
+ @node.automatic_attrs[:command] = {:ps => 'fuuuu'}
+ @events = Chef::EventDispatch::Dispatcher.new
+ @run_context = Chef::RunContext.new(@node, {}, @events)
+
+ @new_resource = Chef::Resource::Service.new("chef")
+ @provider = Chef::Provider::Service::AixInit.new(@new_resource, @run_context)
+
+ @current_resource = Chef::Resource::Service.new("chef")
+ @provider.current_resource = @current_resource
+
+ @pid, @stdin, @stdout, @stderr = nil, nil, nil, nil
+ end
+
+ describe "load_current_resource" do
+ it "sets current resource attributes" do
+ @provider.should_receive(:set_current_resource_attributes)
+
+ @provider.load_current_resource
+ end
+ end
+
+ describe "action_enable" do
+ shared_examples_for "the service is up to date" do
+ it "does not enable the service" do
+ @provider.should_not_receive(:enable_service)
+ @provider.action_enable
+ @provider.set_updated_status
+ @provider.new_resource.should_not be_updated
+ end
+ end
+
+ shared_examples_for "the service is not up to date" do
+ it "enables the service and sets the resource as updated" do
+ @provider.should_receive(:enable_service).and_return(true)
+ @provider.action_enable
+ @provider.set_updated_status
+ @provider.new_resource.should be_updated
+ end
+ end
+
+ context "when the service is disabled" do
+ before do
+ @current_resource.enabled(false)
+ end
+
+ it_behaves_like "the service is not up to date"
+ end
+
+ context "when the service is enabled" do
+ before do
+ @current_resource.enabled(true)
+ @current_resource.priority(80)
+ end
+
+ context "and the service sets no priority" do
+ it_behaves_like "the service is up to date"
+ end
+
+ context "and the service requests the same priority as is set" do
+ before do
+ @new_resource.priority(80)
+ end
+ it_behaves_like "the service is up to date"
+ end
+
+ context "and the service requests a different priority than is set" do
+ before do
+ @new_resource.priority(20)
+ end
+ it_behaves_like "the service is not up to date"
+ end
+ end
+ end
+
+ describe "enable_service" do
+ before do
+ Dir.stub(:glob).with(["/etc/rc.d/rc2.d/[SK][0-9][0-9]#{@new_resource.service_name}", "/etc/rc.d/rc2.d/[SK]#{@new_resource.service_name}"]).and_return([])
+ end
+
+ context "when the service doesn't set a priority" do
+ it "creates symlink with status S" do
+ @provider.should_receive(:create_symlink).with(2,'S','')
+
+ @provider.enable_service
+ end
+ end
+
+ context "when the service sets a simple priority (integer)" do
+ before do
+ @new_resource.priority(75)
+ end
+
+ it "creates a symlink with status S and a priority" do
+ @provider.should_receive(:create_symlink).with(2,'S',75)
+
+ @provider.enable_service
+ end
+ end
+
+ context "when the service sets complex priorities (hash)" do
+ before do
+ priority = {2 => [:start, 20], 3 => [:stop, 10]}
+ @new_resource.priority(priority)
+ end
+
+ it "create symlink with status start (S) or stop (K) and a priority " do
+ @provider.should_receive(:create_symlink).with(2,'S',20)
+ @provider.should_receive(:create_symlink).with(3,'K',10)
+
+ @provider.enable_service
+ end
+ end
+ end
+
+ describe "disable_service" do
+ before do
+ Dir.stub(:glob).with(["/etc/rc.d/rc2.d/[SK][0-9][0-9]#{@new_resource.service_name}", "/etc/rc.d/rc2.d/[SK]#{@new_resource.service_name}"]).and_return([])
+ end
+
+ context "when the service doesn't set a priority" do
+ it "creates symlinks with status stop (K)" do
+ @provider.should_receive(:create_symlink).with(2,'K','')
+
+ @provider.disable_service
+ end
+ end
+
+ context "when the service sets a simple priority (integer)" do
+ before do
+ @new_resource.priority(75)
+ end
+
+ it "create symlink with status stop (k) and a priority " do
+ @provider.should_receive(:create_symlink).with(2,'K',25)
+
+ @provider.disable_service
+ end
+ end
+
+ context "when the service sets complex priorities (hash)" do
+ before do
+ @priority = {2 => [:start, 20], 3 => [:stop, 10]}
+ @new_resource.priority(@priority)
+ end
+
+ it "create symlink with status stop (k) and a priority " do
+ @provider.should_receive(:create_symlink).with(3,'K',90)
+
+ @provider.disable_service
+ end
+ end
+ end
+
+ describe "set_current_resource_attributes" do
+ context "when rc2.d contains only start script" do
+ before do
+ files = ["/etc/rc.d/rc2.d/S20apache"]
+
+ Dir.stub(:glob).with(["/etc/rc.d/rc2.d/[SK][0-9][0-9]#{@new_resource.service_name}", "/etc/rc.d/rc2.d/[SK]chef"]).and_return(files)
+ end
+
+ it "the service is enabled" do
+ @provider.current_resource.should_receive(:enabled).with(true)
+ @provider.current_resource.should_receive(:priority).with(20)
+
+ @provider.set_current_resource_attributes
+ end
+ end
+
+ context "when rc2.d contains only stop script" do
+ before do
+ files = ["/etc/rc.d/rc2.d/K20apache"]
+ @priority = {2 => [:stop, 20]}
+
+ Dir.stub(:glob).with(["/etc/rc.d/rc2.d/[SK][0-9][0-9]#{@new_resource.service_name}", "/etc/rc.d/rc2.d/[SK]chef"]).and_return(files)
+ end
+ it "the service is not enabled" do
+ @provider.current_resource.should_receive(:enabled).with(false)
+ @provider.current_resource.should_receive(:priority).with(@priority)
+
+ @provider.set_current_resource_attributes
+ end
+ end
+
+ context "when rc2.d contains both start and stop scripts" do
+ before do
+ @files = ["/etc/rc.d/rc2.d/S20apache", "/etc/rc.d/rc2.d/K80apache"]
+ @priority = {2 => [:start, 20], 2 => [:stop, 80]}
+
+ Dir.stub(:glob).with(["/etc/rc.d/rc2.d/[SK][0-9][0-9]#{@new_resource.service_name}", "/etc/rc.d/rc2.d/[SK]chef"]).and_return(@files)
+ end
+ it "the service is enabled" do
+ @current_resource.should_receive(:enabled).with(true)
+ @current_resource.should_receive(:priority).with(@priority)
+
+ @provider.set_current_resource_attributes
+ end
+ end
+
+ context "when rc2.d contains only start script (without priority)" do
+ before do
+ files = ["/etc/rc.d/rc2.d/Sapache"]
+
+ Dir.stub(:glob).with(["/etc/rc.d/rc2.d/[SK][0-9][0-9]#{@new_resource.service_name}", "/etc/rc.d/rc2.d/[SK]#{@new_resource.service_name}"]).and_return(files)
+ end
+
+ it "the service is enabled" do
+ @provider.current_resource.should_receive(:enabled).with(true)
+ @provider.current_resource.should_receive(:priority).with('')
+
+ @provider.set_current_resource_attributes
+ end
+ end
+
+ context "when rc2.d contains only stop script (without priority)" do
+ before do
+ files = ["/etc/rc.d/rc2.d/Kapache"]
+ @priority = {2 => [:stop, '']}
+
+ Dir.stub(:glob).with(["/etc/rc.d/rc2.d/[SK][0-9][0-9]#{@new_resource.service_name}", "/etc/rc.d/rc2.d/[SK]#{@new_resource.service_name}"]).and_return(files)
+ end
+ it "the service is not enabled" do
+ @provider.current_resource.should_receive(:enabled).with(false)
+ @provider.current_resource.should_receive(:priority).with(@priority)
+
+ @provider.set_current_resource_attributes
+ end
+ end
+
+ context "when rc2.d contains both start and stop scripts" do
+ before do
+ files = ["/etc/rc.d/rc2.d/Sapache", "/etc/rc.d/rc2.d/Kapache"]
+ @priority = {2 => [:start, ''], 2 => [:stop, '']}
+
+ Dir.stub(:glob).with(["/etc/rc.d/rc2.d/[SK][0-9][0-9]#{@new_resource.service_name}", "/etc/rc.d/rc2.d/[SK]#{@new_resource.service_name}"]).and_return(files)
+ end
+ it "the service is enabled" do
+ @current_resource.should_receive(:enabled).with(true)
+ @current_resource.should_receive(:priority).with(@priority)
+
+ @provider.set_current_resource_attributes
+ end
+ end
+ end
+end
+