1+ #
2+ # Author:: Lee Jensen (<ljensen@engineyard.com>)
3+ # Copyright:: Copyright (c) 2008 Opscode, Inc.
4+ # License:: Apache License, Version 2.0
5+ #
6+ # Licensed under the Apache License, Version 2.0 (the "License");
7+ # you may not use this file except in compliance with the License.
8+ # You may obtain a copy of the License at
9+ #
10+ # http://www.apache.org/licenses/LICENSE-2.0
11+ #
12+ # Unless required by applicable law or agreed to in writing, software
13+ # distributed under the License is distributed on an "AS IS" BASIS,
14+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+ # See the License for the specific language governing permissions and
16+ # limitations under the License.
17+ #
18+
19+ require File . expand_path ( File . join ( File . dirname ( __FILE__ ) , ".." , ".." , ".." , "spec_helper" ) )
20+
21+ describe Chef ::Provider ::Service ::Gentoo do
22+ before ( :each ) do
23+ @node = mock ( "Chef::Node" , :null_object => true )
24+
25+ resource_opts = { :null_object => true , :name => 'chef' , :service_name => 'chef' , :enabled => false , :running => nil }
26+ @new_resource = mock ( "Chef::Resource::Service" , resource_opts )
27+ @current_resource = mock ( "Chef::Resource::Service" , resource_opts )
28+
29+ @provider = Chef ::Provider ::Service ::Gentoo . new ( @node , @new_resource )
30+ Chef ::Resource ::Service . stub! ( :new ) . and_return ( @current_resource )
31+ File . stub! ( :exists? ) . and_return ( true )
32+
33+ @io = mock ( "IO" )
34+ IO . stub! ( :popen ) . and_return ( @io )
35+ @io . stub! ( :each_line ) . and_yield ( " gfs | default " )
36+ end
37+
38+ describe "load_current_resource" do
39+ it "should raise Chef::Exception::Service if /sbin/rc-update does not exist" do
40+ File . should_receive ( :exists? ) . with ( "/sbin/rc-update" ) . and_return ( false )
41+ lambda { @provider . load_current_resource } . should raise_error ( Chef ::Exception ::Service )
42+ end
43+
44+ it "should set enabled true if rc-update indicates service is in default runlevel" do
45+ IO . should_receive ( :popen ) . with ( "/sbin/rc-update -s default" ) . and_yield ( @io )
46+ @io . should_receive ( :each_line ) .
47+ and_yield ( ' gfs | default ' ) .
48+ and_yield ( ' chef | default ' ) .
49+ and_yield ( 'monit | default ' ) .
50+ and_yield ( 'mysql | default ' )
51+
52+ @current_resource . should_receive ( :enabled ) . with ( true )
53+ @provider . load_current_resource
54+ end
55+
56+ it "should set enabled false if rc-update indicates service is not in default runlevel" do
57+ IO . should_receive ( :popen ) . with ( "/sbin/rc-update -s default" ) . and_yield ( @io )
58+ @io . should_receive ( :each_line ) .
59+ and_yield ( ' gfs | default ' ) .
60+ and_yield ( 'notchef | default ' ) .
61+ and_yield ( ' monit | default ' ) .
62+ and_yield ( ' mysql | default ' )
63+
64+ @provider . load_current_resource
65+ @current_resource . enabled . should be_false
66+ end
67+
68+ it "should return the current_resource" do
69+ @provider . load_current_resource . should == @current_resource
70+ end
71+ end
72+
73+ describe "action_methods" do
74+ before ( :each ) { @provider . stub! ( :load_current_resource ) . and_return ( @current_resource ) }
75+
76+ describe Chef ::Provider ::Service ::Gentoo , "enable_service" do
77+ it "should call rc-update add *service* default" do
78+ @provider . should_receive ( :run_command ) . with ( { :command => "/sbin/rc-update add chef default" } )
79+ @provider . enable_service ( 'chef' )
80+ end
81+ end
82+
83+ describe Chef ::Provider ::Service ::Gentoo , "disable_service" do
84+ it "should call rc-update del *service* default" do
85+ @provider . should_receive ( :run_command ) . with ( { :command => "/sbin/rc-update del chef default" } )
86+ @provider . disable_service ( 'chef' )
87+ end
88+ end
89+ end
90+ end
0 commit comments