|
| 1 | +# |
| 2 | +# Author:: Adam Jacob (<adam@hjksolutions.com>) |
| 3 | +# Copyright:: Copyright (c) 2008 HJK Solutions, LLC |
| 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::Resource::User, "initialize" do |
| 22 | + before(:each) do |
| 23 | + @resource = Chef::Resource::User.new("adam") |
| 24 | + end |
| 25 | + |
| 26 | + it "should create a new Chef::Resource::User" do |
| 27 | + @resource.should be_a_kind_of(Chef::Resource) |
| 28 | + @resource.should be_a_kind_of(Chef::Resource::User) |
| 29 | + end |
| 30 | + |
| 31 | + it "should set the resource_name to :user" do |
| 32 | + @resource.resource_name.should eql(:user) |
| 33 | + end |
| 34 | + |
| 35 | + it "should set the username equal to the argument to initialize" do |
| 36 | + @resource.username.should eql("adam") |
| 37 | + end |
| 38 | + |
| 39 | + %w{comment uid gid home shell password}.each do |attrib| |
| 40 | + it "should set #{attrib} to nil" do |
| 41 | + @resource.send(attrib).should eql(nil) |
| 42 | + end |
| 43 | + end |
| 44 | + |
| 45 | + it "should set action to :create" do |
| 46 | + @resource.action.should eql(:create) |
| 47 | + end |
| 48 | + |
| 49 | + it "should set supports[:manage_home] to false" do |
| 50 | + @resource.supports[:manage_home].should eql(false) |
| 51 | + end |
| 52 | + |
| 53 | + %w{create remove modify manage lock unlock}.each do |action| |
| 54 | + it "should allow action #{action}" do |
| 55 | + @resource.allowed_actions.detect { |a| a == action.to_sym }.should eql(action.to_sym) |
| 56 | + end |
| 57 | + end |
| 58 | +end |
| 59 | + |
| 60 | +%w{username comment home shell password}.each do |attrib| |
| 61 | + describe Chef::Resource::User, attrib do |
| 62 | + before(:each) do |
| 63 | + @resource = Chef::Resource::User.new("adam") |
| 64 | + end |
| 65 | + |
| 66 | + it "should allow a string" do |
| 67 | + @resource.send(attrib, "adam") |
| 68 | + @resource.send(attrib).should eql("adam") |
| 69 | + end |
| 70 | + |
| 71 | + it "should not allow a hash" do |
| 72 | + lambda { @resource.send(attrib, { :woot => "i found it" }) }.should raise_error(ArgumentError) |
| 73 | + end |
| 74 | + end |
| 75 | +end |
| 76 | + |
| 77 | +%w{uid gid}.each do |attrib| |
| 78 | + describe Chef::Resource::User, attrib do |
| 79 | + before(:each) do |
| 80 | + @resource = Chef::Resource::User.new("adam") |
| 81 | + end |
| 82 | + |
| 83 | + it "should allow a string" do |
| 84 | + @resource.send(attrib, "100") |
| 85 | + @resource.send(attrib).should eql("100") |
| 86 | + end |
| 87 | + |
| 88 | + it "should allow an integer" do |
| 89 | + @resource.send(attrib, 100) |
| 90 | + @resource.send(attrib).should eql(100) |
| 91 | + end |
| 92 | + |
| 93 | + it "should not allow a hash" do |
| 94 | + lambda { @resource.send(attrib, { :woot => "i found it" }) }.should raise_error(ArgumentError) |
| 95 | + end |
| 96 | + end |
| 97 | +end |
0 commit comments