diff options
| author | Andrew Parker <andy@puppetlabs.com> | 2014-10-16 16:37:46 -0700 |
|---|---|---|
| committer | Andrew Parker <andy@puppetlabs.com> | 2014-10-16 16:37:46 -0700 |
| commit | d4b882760269060287bd8325548eea2a29f64506 (patch) | |
| tree | 356a401d5e7488b9f1aff618ca62624d69f28d82 /spec | |
| parent | a40cfd624fbc7380690d76a6cb691225e0e9eeba (diff) | |
| download | puppet-d4b882760269060287bd8325548eea2a29f64506.tar.gz | |
(PUP-3201) Stop using :undef for parameters in 4x
The :undef symbol was still leaking all over the place internally. This
caused type inference to sometimes end up with Runtime[ruby, Symbol]. By
using nil instead of :undef, everything can be much more
straightforward. Once the code removal for puppet 4 comes into play even
more oddities around how resource parameters are handled can be
performed.
Diffstat (limited to 'spec')
| -rw-r--r-- | spec/integration/parser/future_compiler_spec.rb | 36 | ||||
| -rwxr-xr-x | spec/unit/parser/resource/param_spec.rb | 32 | ||||
| -rwxr-xr-x | spec/unit/parser/resource_spec.rb | 4 |
3 files changed, 46 insertions, 26 deletions
diff --git a/spec/integration/parser/future_compiler_spec.rb b/spec/integration/parser/future_compiler_spec.rb index 3a27a3aad..9b612e400 100644 --- a/spec/integration/parser/future_compiler_spec.rb +++ b/spec/integration/parser/future_compiler_spec.rb @@ -468,6 +468,15 @@ describe "Puppet::Parser::Compiler" do end.to raise_error(/type Integer, got String/) end + it 'denies undef for a non-optional type' do + expect do + catalog = compile_to_catalog(<<-MANIFEST) + define foo(Integer $x) { } + foo { 'test': x => undef } + MANIFEST + end.to raise_error(/type Integer, got Undef/) + end + it 'denies non type compliant default argument' do expect do catalog = compile_to_catalog(<<-MANIFEST) @@ -477,6 +486,15 @@ describe "Puppet::Parser::Compiler" do end.to raise_error(/type Integer, got String/) end + it 'denies undef as the default for a non-optional type' do + expect do + catalog = compile_to_catalog(<<-MANIFEST) + define foo(Integer $x = undef) { } + foo { 'test': } + MANIFEST + end.to raise_error(/type Integer, got Undef/) + end + it 'accepts a Resource as a Type' do catalog = compile_to_catalog(<<-MANIFEST) define foo(Type[Bar] $x) { @@ -527,6 +545,15 @@ describe "Puppet::Parser::Compiler" do end.to raise_error(/type Integer, got String/) end + it 'denies undef for a non-optional type' do + expect do + catalog = compile_to_catalog(<<-MANIFEST) + class foo(Integer $x) { } + class { 'foo': x => undef } + MANIFEST + end.to raise_error(/type Integer, got Undef/) + end + it 'denies non type compliant default argument' do expect do catalog = compile_to_catalog(<<-MANIFEST) @@ -536,6 +563,15 @@ describe "Puppet::Parser::Compiler" do end.to raise_error(/type Integer, got String/) end + it 'denies undef as the default for a non-optional type' do + expect do + catalog = compile_to_catalog(<<-MANIFEST) + class foo(Integer $x = undef) { } + class { 'foo': } + MANIFEST + end.to raise_error(/type Integer, got Undef/) + end + it 'accepts a Resource as a Type' do catalog = compile_to_catalog(<<-MANIFEST) class foo(Type[Bar] $x) { diff --git a/spec/unit/parser/resource/param_spec.rb b/spec/unit/parser/resource/param_spec.rb index 7989d060d..dcb8a3616 100755 --- a/spec/unit/parser/resource/param_spec.rb +++ b/spec/unit/parser/resource/param_spec.rb @@ -1,19 +1,13 @@ -#! /usr/bin/env ruby require 'spec_helper' describe Puppet::Parser::Resource::Param do - it "can be instantiated" do - Puppet::Parser::Resource::Param.new(:name => 'myparam', :value => 'foo') - end - - it "stores the source file" do - param = Puppet::Parser::Resource::Param.new(:name => 'myparam', :value => 'foo', :file => 'foo.pp') - param.file.should == 'foo.pp' - end + it "has readers for all of the attributes" do + param = Puppet::Parser::Resource::Param.new(:name => 'myparam', :value => 'foo', :file => 'foo.pp', :line => 42) - it "stores the line number" do - param = Puppet::Parser::Resource::Param.new(:name => 'myparam', :value => 'foo', :line => 42) - param.line.should == 42 + expect(param.name).to eq(:myparam) + expect(param.value).to eq('foo') + expect(param.file).to eq('foo.pp') + expect(param.line).to eq(42) end context "parameter validation" do @@ -23,21 +17,15 @@ describe Puppet::Parser::Resource::Param do }.to raise_error(Puppet::Error, /name is a required option/) end - it "throws an error when instantiated without a value" do - expect { - Puppet::Parser::Resource::Param.new(:name => 'myparam') - }.to raise_error(Puppet::Error, /value is a required option/) - end + it "does not require a value" do + param = Puppet::Parser::Resource::Param.new(:name => 'myparam') - it "throws an error when instantiated with a nil value" do - expect { - Puppet::Parser::Resource::Param.new(:name => 'myparam', :value => nil) - }.to raise_error(Puppet::Error, /value is a required option/) + expect(param.value).to be_nil end it "includes file/line context in errors" do expect { - Puppet::Parser::Resource::Param.new(:name => 'myparam', :value => nil, :file => 'foo.pp', :line => 42) + Puppet::Parser::Resource::Param.new(:file => 'foo.pp', :line => 42) }.to raise_error(Puppet::Error, /foo.pp:42/) end end diff --git a/spec/unit/parser/resource_spec.rb b/spec/unit/parser/resource_spec.rb index d0ec5f49c..97f19e21a 100755 --- a/spec/unit/parser/resource_spec.rb +++ b/spec/unit/parser/resource_spec.rb @@ -561,10 +561,6 @@ describe Puppet::Parser::Resource do @resource["foo"].should == "bar" end - it "should fail when provided a parameter name but no value" do - expect { @resource.set_parameter("myparam") }.to raise_error(ArgumentError) - end - it "should allow parameters to be set to 'false'" do @resource.set_parameter("myparam", false) @resource["myparam"].should be_false |
