summaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
authorCorey Hemminger <hemminger@hotmail.com>2022-05-03 14:08:08 -0500
committerGitHub <noreply@github.com>2022-05-03 12:08:08 -0700
commitd4c3b8ad111ec7ff6b32ebccf9edd1b6a2f9e8e2 (patch)
tree58e5d97450a0c1277bd12feb6feea2e89c75cbf6 /spec
parent3f2e1ca604c2ab1079589a763058dfeb04986a94 (diff)
downloadchef-d4c3b8ad111ec7ff6b32ebccf9edd1b6a2f9e8e2.tar.gz
add expire and inactive options to linux user resource (#11659)
* add expire and inactive options to linux user resource * fix spell check * add tests Signed-off-by: Corey Hemminger <hemminger@hotmail.com>
Diffstat (limited to 'spec')
-rw-r--r--spec/unit/provider/user/linux_spec.rb50
-rw-r--r--spec/unit/resource/user/linux_user_spec.rb42
2 files changed, 92 insertions, 0 deletions
diff --git a/spec/unit/provider/user/linux_spec.rb b/spec/unit/provider/user/linux_spec.rb
index 1f22d963da..1fc8e3c6a1 100644
--- a/spec/unit/provider/user/linux_spec.rb
+++ b/spec/unit/provider/user/linux_spec.rb
@@ -70,4 +70,54 @@ describe Chef::Provider::User::Linux do
expect( provider.useradd_options ).to eql(["-m"])
end
end
+
+ describe "expire_date behavior" do
+ before(:each) do
+ @new_resource = Chef::Resource::User::LinuxUser.new("adam", @run_context)
+ @current_resource = Chef::Resource::User::LinuxUser.new("adam", @run_context)
+ end
+
+ it "defaults expire_date to nil" do
+ expect( @new_resource.expire_date ).to be nil
+ end
+
+ it "by default expire_date is nil and we use ''" do
+ expect( provider.universal_options ).to eql([])
+ end
+
+ it "setting expire_date to nil includes ''" do
+ @new_resource.expire_date nil
+ expect( provider.universal_options ).to eql([])
+ end
+
+ it "setting expire_date to 1982-04-16 includes -e" do
+ @new_resource.expire_date "1982-04-16"
+ expect( provider.universal_options ).to eql(["-e", "1982-04-16"])
+ end
+ end
+
+ describe "inactive behavior" do
+ before(:each) do
+ @new_resource = Chef::Resource::User::LinuxUser.new("adam", @run_context)
+ @current_resource = Chef::Resource::User::LinuxUser.new("adam", @run_context)
+ end
+
+ it "defaults inactive to nil" do
+ expect( @new_resource.inactive ).to be nil
+ end
+
+ it "by default inactive is nil and we use ''" do
+ expect( provider.universal_options ).to eql([])
+ end
+
+ it "setting inactive to nil includes ''" do
+ @new_resource.inactive nil
+ expect( provider.universal_options ).to eql([])
+ end
+
+ it "setting inactive to 90 includes -f" do
+ @new_resource.inactive 90
+ expect( provider.universal_options ).to eql(["-f", 90])
+ end
+ end
end
diff --git a/spec/unit/resource/user/linux_user_spec.rb b/spec/unit/resource/user/linux_user_spec.rb
new file mode 100644
index 0000000000..c9bd71b11d
--- /dev/null
+++ b/spec/unit/resource/user/linux_user_spec.rb
@@ -0,0 +1,42 @@
+require "spec_helper"
+
+describe Chef::Resource::User, "initialize" do
+ let(:resource) { Chef::Resource::User::LinuxUser.new("notarealuser") }
+
+ describe "inactive attribute" do
+ it "allows a string" do
+ resource.inactive "100"
+ expect(resource.inactive).to eql("100")
+ end
+
+ it "allows an integer" do
+ resource.inactive 100
+ expect(resource.inactive).to eql(100)
+ end
+
+ it "does not allow a hash" do
+ expect { resource.inactive({ woot: "i found it" }) }.to raise_error(ArgumentError)
+ end
+ end
+
+ describe "expire_date attribute" do
+ it "allows a string" do
+ resource.expire_date "100"
+ expect(resource.expire_date).to eql("100")
+ end
+
+ it "does not allow an integer" do
+ expect { resource.expire_date(90) }.to raise_error(ArgumentError)
+ end
+
+ it "does not allow a hash" do
+ expect { resource.expire_date({ woot: "i found it" }) }.to raise_error(ArgumentError)
+ end
+ end
+
+ %w{inactive expire_date}.each do |prop|
+ it "sets #{prop} to nil" do
+ expect(resource.send(prop)).to eql(nil)
+ end
+ end
+end