diff options
author | Lamont Granquist <lamont@scriptkiddie.org> | 2016-04-14 11:30:40 -0700 |
---|---|---|
committer | Lamont Granquist <lamont@scriptkiddie.org> | 2016-04-14 11:30:40 -0700 |
commit | 03503d7352ccad45107b055fc711e86c7c5d2918 (patch) | |
tree | 22b44530ad934d4846167021b2485abf45fb8110 /spec | |
parent | 95c13caaf4c8a20ba6d1f49680cd23de60cdb231 (diff) | |
download | chef-03503d7352ccad45107b055fc711e86c7c5d2918.tar.gz |
add nillable apt_repository and nillable properties
in Chef-13 nillable will become 'true' by default and we'll have
to deprecate and remove all nillable properties, but for now
this lets us opt-in, which was can't currently do in Chef-12.
Diffstat (limited to 'spec')
-rw-r--r-- | spec/unit/property/validation_spec.rb | 30 | ||||
-rw-r--r-- | spec/unit/provider/apt_repository_spec.rb | 5 | ||||
-rw-r--r-- | spec/unit/resource/apt_repository_spec.rb | 4 |
3 files changed, 32 insertions, 7 deletions
diff --git a/spec/unit/property/validation_spec.rb b/spec/unit/property/validation_spec.rb index db3c9fe4f6..4e1b252863 100644 --- a/spec/unit/property/validation_spec.rb +++ b/spec/unit/property/validation_spec.rb @@ -99,13 +99,15 @@ describe "Chef::Resource.property validation" do expect(resource.x nil).to be_nil expect(resource.x).to be_nil end - it "changing x to nil warns that the get will change to a set in Chef 13 and does not change the value" do - resource.instance_eval { @x = "default" } - expect { resource.x nil }.to raise_error Chef::Exceptions::DeprecatedFeatureError, - /An attempt was made to change x from "default" to nil by calling x\(nil\). In Chef 12, this does a get rather than a set. In Chef 13, this will change to set the value to nil./ - Chef::Config[:treat_deprecation_warnings_as_errors] = false - expect(resource.x nil).to eq "default" - expect(resource.x).to eq "default" + unless tags.include?(:nillable) + it "changing x to nil warns that the get will change to a set in Chef 13 and does not change the value" do + resource.instance_eval { @x = "default" } + expect { resource.x nil }.to raise_error Chef::Exceptions::DeprecatedFeatureError, + /An attempt was made to change x from "default" to nil by calling x\(nil\). In Chef 12, this does a get rather than a set. In Chef 13, this will change to set the value to nil./ + Chef::Config[:treat_deprecation_warnings_as_errors] = false + expect(resource.x nil).to eq "default" + expect(resource.x).to eq "default" + end end end if tags.include?(:nil_is_valid) @@ -123,6 +125,15 @@ describe "Chef::Resource.property validation" do expect(resource.x).to eq "default" end end + elsif tags.include?(:nillable) + with_property ":x, #{validation}, nillable: true" do + it "changing x to nil with nillable true overwrites defaults and just works" do + resource.instance_eval { @x = "default" } + expect { resource.x nil }.not_to raise_error + expect(resource.x nil).to eq nil + expect(resource.x).to eq nil + end + end else it "property :x, #{validation}, default: nil warns that the default is invalid" do expect { resource_class.class_eval("property :x, #{validation}, default: nil", __FILE__, __LINE__) }.to raise_error Chef::Exceptions::DeprecatedFeatureError, @@ -268,6 +279,11 @@ describe "Chef::Resource.property validation" do validation_test "[]", [], [ :a ] + + validation_test "[ String, nil ], nillable: true", + [ nil, "thing" ], + [ :nope, false ], + :nillable end # is diff --git a/spec/unit/provider/apt_repository_spec.rb b/spec/unit/provider/apt_repository_spec.rb index 543b65cc90..d8f2c85cb7 100644 --- a/spec/unit/provider/apt_repository_spec.rb +++ b/spec/unit/provider/apt_repository_spec.rb @@ -158,6 +158,11 @@ C5986B4F1257FFA86632CBA746181433FBB75451 expect(provider.build_repo("http://test/uri", "unstable", "main", false, nil)).to eql(target) end + it "should create a repository string with no distribution" do + target = %Q{deb "http://test/uri" main\n} + expect(provider.build_repo("http://test/uri", nil, "main", false, nil)).to eql(target) + end + it "should create a repository string with source" do target = %Q{deb "http://test/uri" unstable main\ndeb-src "http://test/uri" unstable main\n} expect(provider.build_repo("http://test/uri", "unstable", "main", false, nil, true)).to eql(target) diff --git a/spec/unit/resource/apt_repository_spec.rb b/spec/unit/resource/apt_repository_spec.rb index 88d9ca2508..cd55ce66cc 100644 --- a/spec/unit/resource/apt_repository_spec.rb +++ b/spec/unit/resource/apt_repository_spec.rb @@ -31,4 +31,8 @@ describe Chef::Resource::AptRepository do expect(resource.keyserver).to eql("keyserver.ubuntu.com") end + it "the default distribution should be nillable" do + expect(resource.distribution(nil)).to eql(nil) + expect(resource.distribution).to eql(nil) + end end |