summaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
authorThom May <thom@may.lt>2017-04-28 08:31:39 +0100
committerGitHub <noreply@github.com>2017-04-28 08:31:39 +0100
commit09994cadf6747f8765ce94f6d6687705a508bf32 (patch)
tree2a77749efb1ea7f4f7f79b1cd5c517fbac18dd35 /spec
parent059fbdd0ea44cb85dd47065c48c9a87933e45bb8 (diff)
parentd2c661c56d3306c916118f8f75b878d817fa24d3 (diff)
downloadchef-09994cadf6747f8765ce94f6d6687705a508bf32.tar.gz
Merge pull request #6097 from chef/tm/aix_manage_home
Fix manage_home on AIX
Diffstat (limited to 'spec')
-rw-r--r--spec/unit/provider/user/aix_spec.rb97
1 files changed, 97 insertions, 0 deletions
diff --git a/spec/unit/provider/user/aix_spec.rb b/spec/unit/provider/user/aix_spec.rb
new file mode 100644
index 0000000000..c70fdd9a57
--- /dev/null
+++ b/spec/unit/provider/user/aix_spec.rb
@@ -0,0 +1,97 @@
+# Copyright:: Copyright 2017, 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 "mixlib/shellout"
+require "spec_helper"
+
+describe Chef::Provider::User::Aix do
+
+ let(:shellcmdresult) do
+ Struct.new(:stdout, :stderr, :exitstatus)
+ end
+
+ let(:node) do
+ Chef::Node.new.tap do |node|
+ node.automatic["platform"] = "solaris2"
+ end
+ end
+ let(:events) { Chef::EventDispatch::Dispatcher.new }
+ let(:run_context) { Chef::RunContext.new(node, {}, events) }
+ let(:new_resource) do
+ Chef::Resource::User::AixUser.new("adam", @run_context)
+ end
+ let(:current_resource) do
+ Chef::Resource::User::AixUser.new("adam", @run_context).tap do |cr|
+ cr.home "/home/adam"
+ end
+ end
+
+ subject(:provider) do
+ described_class.new(new_resource, run_context).tap do |p|
+ p.current_resource = current_resource
+ end
+ end
+
+ describe "when we set a password" do
+ before do
+ new_resource.password "Ostagazuzulum"
+ end
+
+ it "should call chpasswd correctly" do
+ expect(provider).to receive(:shell_out!).with("echo 'adam:Ostagazuzulum' | chpasswd -e").and_return true
+ provider.manage_user
+ end
+ end
+
+ describe "#create_user" do
+ context "with a system user" do
+ before { new_resource.system(true) }
+ it "should add the user to the system group" do
+ expect(provider).to receive(:shell_out!).with("useradd", "-g", "system", "adam")
+ provider.create_user
+ end
+ end
+
+ context "with manage_home" do
+ before do
+ new_resource.manage_home(true)
+ new_resource.home("/home/adam")
+ allow(provider).to receive(:updating_home?).and_return(true)
+ end
+
+ it "should create the home directory" do
+ allow(provider).to receive(:shell_out!).with("usermod", "-d", "/home/adam", "adam")
+ expect(FileUtils).to receive(:mkdir_p).and_return(true)
+ provider.manage_user
+ end
+
+ it "should move an existing home dir" do
+ allow(provider).to receive(:shell_out!).with("usermod", "-d", "/mnt/home/adam", "adam")
+ new_resource.home("/mnt/home/adam")
+ allow(File).to receive(:directory?).with("/home/adam").and_return(true)
+ expect(FileUtils).to receive(:mv).with("/home/adam", "/mnt/home/adam")
+ provider.manage_user
+ end
+
+ it "should not pass -m" do
+ allow(FileUtils).to receive(:mkdir_p).and_return(true)
+ expect(provider).to receive(:shell_out!).with("usermod", "-d", "/home/adam", "adam")
+ provider.manage_user
+ end
+ end
+ end
+end