summaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
authorTim Smith <tsmith84@gmail.com>2020-02-03 12:29:12 -0800
committerTim Smith <tsmith84@gmail.com>2020-02-03 12:29:12 -0800
commit1e55b1f6926d353889e6eb4efbc4affb9458a8db (patch)
treea4024db8f7faee92f7048a5e09287a6dc1d46da0 /spec
parentf7f809f85b5c67962d770cf5ef05f19b9f69cc0a (diff)
downloadchef-1e55b1f6926d353889e6eb4efbc4affb9458a8db.tar.gz
Add an introduced field to sysctl and expand testing
Break the content generation out into its own method so we can test it. Signed-off-by: Tim Smith <tsmith@chef.io>
Diffstat (limited to 'spec')
-rw-r--r--spec/unit/resource/sysctl_spec.rb24
1 files changed, 23 insertions, 1 deletions
diff --git a/spec/unit/resource/sysctl_spec.rb b/spec/unit/resource/sysctl_spec.rb
index ba4b23f098..5d978d3b38 100644
--- a/spec/unit/resource/sysctl_spec.rb
+++ b/spec/unit/resource/sysctl_spec.rb
@@ -1,5 +1,5 @@
#
-# Copyright:: Copyright 2018, Chef Software, Inc.
+# Copyright:: Copyright 2018-2020, Chef Software, Inc.
# License:: Apache License, Version 2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
@@ -19,6 +19,7 @@ require "spec_helper"
describe Chef::Resource::Sysctl do
let(:resource) { Chef::Resource::Sysctl.new("fakey_fakerton") }
+ let(:provider) { resource.provider_for_action(:create) }
it "sets resource name as :sysctl" do
expect(resource.resource_name).to eql(:sysctl)
@@ -51,4 +52,25 @@ describe Chef::Resource::Sysctl do
resource.value 1.1
expect(resource.value).to eql("1.1")
end
+
+ context "#contruct_sysctl_content" do
+ before do
+ resource.key("foo")
+ resource.value("bar")
+ end
+
+ context "when comment is a String" do
+ it "Returns content for use with a file resource" do
+ resource.comment("This sets foo / bar on our system")
+ expect(provider.contruct_sysctl_content).to eql("# This sets foo / bar on our system\nfoo = bar")
+ end
+ end
+
+ context "when comment is an Array" do
+ it "Returns content for use with a file resource" do
+ resource.comment(["This sets foo / bar on our system", "We need for baz"])
+ expect(provider.contruct_sysctl_content).to eql("# This sets foo / bar on our system\n# We need for baz\nfoo = bar")
+ end
+ end
+ end
end