From 1229d5a831995ddc2c9814f5104ea2a2c9df65a9 Mon Sep 17 00:00:00 2001 From: Hunter Haugen Date: Thu, 19 Jan 2017 16:17:47 -0800 Subject: (MODULES-4098) Sync the rest of the files --- spec/functions/deprecation_spec.rb | 4 ++-- spec/functions/load_module_metadata_spec.rb | 37 +++++++++++++++++++---------- spec/functions/loadjson_spec.rb | 31 +++++++++++++++++------- spec/functions/validate_cmd_spec.rb | 2 +- spec/functions/validate_legacy_spec.rb | 2 +- 5 files changed, 52 insertions(+), 24 deletions(-) (limited to 'spec/functions') diff --git a/spec/functions/deprecation_spec.rb b/spec/functions/deprecation_spec.rb index cee4f1c..8a65b69 100644 --- a/spec/functions/deprecation_spec.rb +++ b/spec/functions/deprecation_spec.rb @@ -1,6 +1,6 @@ require 'spec_helper' -if Puppet.version.to_f >= 4.0 +if Puppet.version.to_f >= 4.5 describe 'deprecation' do before(:each) { # this is to reset the strict variable to default @@ -40,7 +40,7 @@ if Puppet.version.to_f >= 4.0 Puppet.settings[:strict] = :warning } end -else +elsif Puppet.version.to_f < 4.0 # Puppet version < 4 will use these tests. describe 'deprecation' do after(:all) do diff --git a/spec/functions/load_module_metadata_spec.rb b/spec/functions/load_module_metadata_spec.rb index 1a61e2c..2ba41a5 100755 --- a/spec/functions/load_module_metadata_spec.rb +++ b/spec/functions/load_module_metadata_spec.rb @@ -7,30 +7,43 @@ describe 'load_module_metadata' do describe "when calling with valid arguments" do before :each do - if RSpec.configuration.puppet_future - allow(File).to receive(:read).with(/\/stdlib\/metadata.json/, {:encoding=>"utf-8"}).and_return('{"name": "puppetlabs-stdlib"}') - else - allow(File).to receive(:read).with(/\/stdlib\/metadata.json/).and_return('{"name": "puppetlabs-stdlib"}') - end + allow(File).to receive(:read).with(/\/stdlib\/metadata.json/, {:encoding=>"utf-8"}).and_return('{"name": "puppetlabs-stdlib"}') + allow(File).to receive(:read).with(/\/stdlib\/metadata.json/).and_return('{"name": "puppetlabs-stdlib"}') end it "should json parse the file" do - allow(scope).to receive(:function_get_module_path).with(['science']).and_return('/path/to/module/') - allow(File).to receive(:exists?).with('/path/to/module/metadata.json').and_return(true) - allow(File).to receive(:read).with('/path/to/module/metadata.json').and_return('{"name": "spencer-science"}') + if Puppet::Util::Platform.windows? + allow(scope).to receive(:function_get_module_path).with(['science']).and_return('C:/path/to/module/') + allow(File).to receive(:exists?).with('C:/path/to/module/metadata.json').and_return(true) + allow(File).to receive(:read).with('C:/path/to/module/metadata.json').and_return('{"name": "spencer-science"}') + else + allow(scope).to receive(:function_get_module_path).with(['science']).and_return('/path/to/module/') + allow(File).to receive(:exists?).with('/path/to/module/metadata.json').and_return(true) + allow(File).to receive(:read).with('/path/to/module/metadata.json').and_return('{"name": "spencer-science"}') + end result = subject.call(['science']) expect(result['name']).to eq('spencer-science') end it "should fail by default if there is no metadata.json" do - allow(scope).to receive(:function_get_module_path).with(['science']).and_return('/path/to/module/') - allow(File).to receive(:exists?).with('/path/to/module/metadata.json').and_return(false) + if Puppet::Util::Platform.windows? + allow(scope).to receive(:function_get_module_path).with(['science']).and_return('C:/path/to/module/') + allow(File).to receive(:exists?).with('C:/path/to/module/metadata.json').and_return(false) + else + allow(scope).to receive(:function_get_module_path).with(['science']).and_return('/path/to/module/') + allow(File).to receive(:exists?).with('/path/to/module/metadata.json').and_return(false) + end expect {subject.call(['science'])}.to raise_error(Puppet::ParseError) end it "should return nil if user allows empty metadata.json" do - allow(scope).to receive(:function_get_module_path).with(['science']).and_return('/path/to/module/') - allow(File).to receive(:exists?).with('/path/to/module/metadata.json').and_return(false) + if Puppet::Util::Platform.windows? + allow(scope).to receive(:function_get_module_path).with(['science']).and_return('C:/path/to/module/') + allow(File).to receive(:exists?).with('C:/path/to/module/metadata.json').and_return(false) + else + allow(scope).to receive(:function_get_module_path).with(['science']).and_return('/path/to/module/') + allow(File).to receive(:exists?).with('/path/to/module/metadata.json').and_return(false) + end result = subject.call(['science', true]) expect(result).to eq({}) end diff --git a/spec/functions/loadjson_spec.rb b/spec/functions/loadjson_spec.rb index a00dff9..9d26e93 100644 --- a/spec/functions/loadjson_spec.rb +++ b/spec/functions/loadjson_spec.rb @@ -6,15 +6,18 @@ describe 'loadjson' do describe "when calling with valid arguments" do before :each do - if RSpec.configuration.puppet_future - allow(File).to receive(:read).with(/\/stdlib\/metadata.json/, {:encoding=>"utf-8"}).and_return('{"name": "puppetlabs-stdlib"}') - else - allow(File).to receive(:read).with(/\/stdlib\/metadata.json/).and_return('{"name": "puppetlabs-stdlib"}') - end + allow(File).to receive(:read).with(/\/stdlib\/metadata.json/, {:encoding=>"utf-8"}).and_return('{"name": "puppetlabs-stdlib"}') + allow(File).to receive(:read).with(/\/stdlib\/metadata.json/).and_return('{"name": "puppetlabs-stdlib"}') end context 'when a non-existing file is specified' do - let(:filename) { '/tmp/doesnotexist' } + let(:filename) { + if Puppet::Util::Platform.windows? + 'C:/tmp/doesnotexist' + else + '/tmp/doesnotexist' + end + } before { allow(File).to receive(:exists?).with(filename).and_return(false).once allow(PSON).to receive(:load).never @@ -23,7 +26,13 @@ describe 'loadjson' do end context 'when an existing file is specified' do - let(:filename) { '/tmp/doesexist' } + let(:filename) { + if Puppet::Util::Platform.windows? + 'C:/tmp/doesexist' + else + '/tmp/doesexist' + end + } let(:data) { { 'key' => 'value' } } let(:json) { '{"key":"value"}' } before { @@ -36,7 +45,13 @@ describe 'loadjson' do end context 'when the file could not be parsed' do - let(:filename) { '/tmp/doesexist' } + let(:filename) { + if Puppet::Util::Platform.windows? + 'C:/tmp/doesexist' + else + '/tmp/doesexist' + end + } let(:json) { '{"key":"value"}' } before { allow(File).to receive(:exists?).with(filename).and_return(true).once diff --git a/spec/functions/validate_cmd_spec.rb b/spec/functions/validate_cmd_spec.rb index ab0cbc9..c6559e8 100755 --- a/spec/functions/validate_cmd_spec.rb +++ b/spec/functions/validate_cmd_spec.rb @@ -1,6 +1,6 @@ require 'spec_helper' -describe 'validate_cmd' do +describe 'validate_cmd', :unless => Puppet::Util::Platform.windows? do let(:touch) { File.exists?('/usr/bin/touch') ? '/usr/bin/touch' : '/bin/touch' } describe 'signature validation' do diff --git a/spec/functions/validate_legacy_spec.rb b/spec/functions/validate_legacy_spec.rb index 50cb317..10b2aee 100644 --- a/spec/functions/validate_legacy_spec.rb +++ b/spec/functions/validate_legacy_spec.rb @@ -1,6 +1,6 @@ require 'spec_helper' -if Puppet.version.to_f >= 4.0 +if Puppet.version.to_f >= 4.4 describe 'validate_legacy' do it { is_expected.not_to eq(nil) } it { is_expected.to run.with_params.and_raise_error(ArgumentError) } -- cgit v1.2.3 From 20855b9d24de7a8b02b7f5beb70a16139a6c3d74 Mon Sep 17 00:00:00 2001 From: Paula McMaw Date: Wed, 1 Feb 2017 11:47:09 +0000 Subject: (FM-6019) - [WIP] - i18N tests for Spike --- spec/functions/any2array_spec.rb | 6 ++++++ spec/functions/ensure_resource_spec.rb | 24 ++++++++++++++++++++++++ 2 files changed, 30 insertions(+) (limited to 'spec/functions') diff --git a/spec/functions/any2array_spec.rb b/spec/functions/any2array_spec.rb index 70121f1..631657f 100755 --- a/spec/functions/any2array_spec.rb +++ b/spec/functions/any2array_spec.rb @@ -12,4 +12,10 @@ describe "any2array" do it { is_expected.to run.with_params({}).and_return([]) } it { is_expected.to run.with_params({ 'key' => 'value' }).and_return(['key', 'value']) } it { is_expected.to run.with_params({ 'key' => 'value' }).and_return(['key', 'value']) } + + it { is_expected.to run.with_params('‰').and_return(['‰']) } + it { is_expected.to run.with_params('竹').and_return(['竹']) } + it { is_expected.to run.with_params('Ü').and_return(['Ü']) } + it { is_expected.to run.with_params('∇').and_return(['∇']) } + it { is_expected.to run.with_params('€', '万', 'Ö', '♥', '割').and_return(['€', '万', 'Ö', '♥', '割']) } end diff --git a/spec/functions/ensure_resource_spec.rb b/spec/functions/ensure_resource_spec.rb index d552f4e..fddc4c4 100755 --- a/spec/functions/ensure_resource_spec.rb +++ b/spec/functions/ensure_resource_spec.rb @@ -38,7 +38,31 @@ describe 'ensure_resource' do it { expect(lambda { catalogue }).to contain_user('username1').with_ensure('present') } it { expect(lambda { catalogue }).to contain_user('username1').without_gid } end + end + + context 'given a catalog with UTF8 chars' do + describe 'after running ensure_resource("user", "Şắოрŀễ Ţëם", {})' do + before { subject.call(['User', 'Şắოрŀễ Ţëם', {}]) } + + # this lambda is required due to strangeness within rspec-puppet's expectation handling + it { expect(lambda { catalogue }).to contain_user('Şắოрŀễ Ţëם').without_ensure } + end + + describe 'after running ensure_resource("user", "Şắოрŀễ Ţëם", { gid => undef })' do + before { subject.call(['User', 'Şắოрŀễ Ţëם', { 'gid' => :undef }]) } + # this lambda is required due to strangeness within rspec-puppet's expectation handling + it { expect(lambda { catalogue }).to contain_user('Şắოрŀễ Ţëם').without_ensure } + it { expect(lambda { catalogue }).to contain_user('Şắოрŀễ Ţëם').without_gid } + end + + describe 'after running ensure_resource("user", "Şắოрŀễ Ţëם", { ensure => present, gid => undef })' do + before { subject.call(['User', 'Şắოрŀễ Ţëם', { 'ensure' => 'present', 'gid' => :undef }]) } + + # this lambda is required due to strangeness within rspec-puppet's expectation handling + it { expect(lambda { catalogue }).to contain_user('Şắოрŀễ Ţëם').with_ensure('present') } + it { expect(lambda { catalogue }).to contain_user('Şắოрŀễ Ţëם').without_gid } + end end context 'given a catalog with "user { username1: ensure => present }"' do -- cgit v1.2.3 From 530d2ef184d19b965a4c9db2c415c26b80f9d31b Mon Sep 17 00:00:00 2001 From: Emerson Prado Date: Fri, 3 Feb 2017 17:05:52 -0200 Subject: Add spec test for present + installed convergence --- spec/functions/ensure_packages_spec.rb | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'spec/functions') diff --git a/spec/functions/ensure_packages_spec.rb b/spec/functions/ensure_packages_spec.rb index 5d97684..357a6e1 100755 --- a/spec/functions/ensure_packages_spec.rb +++ b/spec/functions/ensure_packages_spec.rb @@ -41,4 +41,16 @@ describe 'ensure_packages' do it { expect(lambda { catalogue }).to contain_package('foo').with({'provider' => 'rpm', 'ensure' => 'present'}) } it { expect(lambda { catalogue }).to contain_package('bar').with({'provider' => 'gem', 'ensure' => 'present'}) } end + + context 'given a catalog with "package { puppet: ensure => present }"' do + let(:pre_condition) { 'package { puppet: ensure => present }' } + + describe 'after running ensure_package("puppet", { "ensure" => "installed" })' do + before { subject.call(['puppet', { "ensure" => "installed" }]) } + + # this lambda is required due to strangeness within rspec-puppet's expectation handling + it { expect(lambda { catalogue }).to contain_package('puppet').with_ensure('present') } + end + end + end -- cgit v1.2.3 From 89a36c67d8efe22a16c2ce8ab2a40fc69ce589b2 Mon Sep 17 00:00:00 2001 From: Dominic Cleal Date: Fri, 3 Feb 2017 12:37:27 +0000 Subject: Fix unsupported data type error with rspec-puppet master The symbol used in the value of the facts hash is not a valid type of value for facts, and results in the following error since rspec-puppet@d50acf0e. Puppet::Error: Unsupported data type: 'Symbol' # puppet/lib/puppet/parser/scope.rb:788:in `deep_freeze' # puppet/lib/puppet/parser/scope.rb:781:in `block in deep_freeze' # puppet/lib/puppet/parser/scope.rb:781:in `each' # puppet/lib/puppet/parser/scope.rb:781:in `deep_freeze' # puppet/lib/puppet/parser/scope.rb:764:in `set_facts' # puppet/lib/puppet/parser/compiler.rb:850:in `set_node_parameters' # puppet/lib/puppet/parser/compiler.rb:166:in `block (2 levels) in compile' # puppet/lib/puppet/util/profiler/around_profiler.rb:58:in `profile' # puppet/lib/puppet/util/profiler.rb:51:in `profile' # puppet/lib/puppet/parser/compiler.rb:166:in `block in compile' # puppet/lib/puppet/context.rb:65:in `override' # puppet/lib/puppet.rb:293:in `override' # puppet/lib/puppet/parser/compiler.rb:162:in `compile' # rspec-puppet/lib/rspec-puppet/example/function_example_group.rb:161:in `build_compiler' The fact's presence doesn't change the behaviour, so remove it. --- spec/functions/has_ip_network_spec.rb | 1 - 1 file changed, 1 deletion(-) (limited to 'spec/functions') diff --git a/spec/functions/has_ip_network_spec.rb b/spec/functions/has_ip_network_spec.rb index 7b5fe66..57cf613 100755 --- a/spec/functions/has_ip_network_spec.rb +++ b/spec/functions/has_ip_network_spec.rb @@ -9,7 +9,6 @@ describe 'has_ip_network' do let(:facts) do { :interfaces => 'eth0,lo', - :network => :undefined, :network_lo => '127.0.0.0', :network_eth0 => '10.0.0.0', } -- cgit v1.2.3 From c2a41352b0a0338fcbdc54c5d3e722beb65c4dce Mon Sep 17 00:00:00 2001 From: Dominic Cleal Date: Sat, 4 Feb 2017 16:45:03 +0100 Subject: Allow test module metadata.json to be read Since puppetlabs/puppet@f2e8e66, the test module's metadata.json is also read causing expectation failures. Like 5c51463, permit it to be read by Puppet. --- spec/functions/load_module_metadata_spec.rb | 4 ++-- spec/functions/loadjson_spec.rb | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) (limited to 'spec/functions') diff --git a/spec/functions/load_module_metadata_spec.rb b/spec/functions/load_module_metadata_spec.rb index 2ba41a5..841cd7d 100755 --- a/spec/functions/load_module_metadata_spec.rb +++ b/spec/functions/load_module_metadata_spec.rb @@ -7,8 +7,8 @@ describe 'load_module_metadata' do describe "when calling with valid arguments" do before :each do - allow(File).to receive(:read).with(/\/stdlib\/metadata.json/, {:encoding=>"utf-8"}).and_return('{"name": "puppetlabs-stdlib"}') - allow(File).to receive(:read).with(/\/stdlib\/metadata.json/).and_return('{"name": "puppetlabs-stdlib"}') + allow(File).to receive(:read).with(/\/(stdlib|test)\/metadata.json/, {:encoding=>"utf-8"}).and_return('{"name": "puppetlabs-stdlib"}') + allow(File).to receive(:read).with(/\/(stdlib|test)\/metadata.json/).and_return('{"name": "puppetlabs-stdlib"}') end it "should json parse the file" do if Puppet::Util::Platform.windows? diff --git a/spec/functions/loadjson_spec.rb b/spec/functions/loadjson_spec.rb index 9d26e93..26125bc 100644 --- a/spec/functions/loadjson_spec.rb +++ b/spec/functions/loadjson_spec.rb @@ -6,8 +6,8 @@ describe 'loadjson' do describe "when calling with valid arguments" do before :each do - allow(File).to receive(:read).with(/\/stdlib\/metadata.json/, {:encoding=>"utf-8"}).and_return('{"name": "puppetlabs-stdlib"}') - allow(File).to receive(:read).with(/\/stdlib\/metadata.json/).and_return('{"name": "puppetlabs-stdlib"}') + allow(File).to receive(:read).with(/\/(stdlib|test)\/metadata.json/, {:encoding=>"utf-8"}).and_return('{"name": "puppetlabs-stdlib"}') + allow(File).to receive(:read).with(/\/(stdlib|test)\/metadata.json/).and_return('{"name": "puppetlabs-stdlib"}') end context 'when a non-existing file is specified' do -- cgit v1.2.3 From 6092ede8d86746038df4a367191d232003652c55 Mon Sep 17 00:00:00 2001 From: Sascha Spreitzer Date: Sat, 4 Feb 2017 13:30:59 +0100 Subject: Add glob function --- spec/functions/glob_spec.rb | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100755 spec/functions/glob_spec.rb (limited to 'spec/functions') diff --git a/spec/functions/glob_spec.rb b/spec/functions/glob_spec.rb new file mode 100755 index 0000000..06439da --- /dev/null +++ b/spec/functions/glob_spec.rb @@ -0,0 +1,11 @@ +require 'spec_helper' + +describe 'glob' do + it { is_expected.not_to eq(nil) } + it { is_expected.to run.with_params().and_raise_error(Puppet::ParseError) } + it { is_expected.to run.with_params(1).and_raise_error(Puppet::ParseError) } + it { is_expected.to run.with_params('').and_return([]) } + it { is_expected.to run.with_params(['']).and_return([]) } + it { is_expected.to run.with_params(['', '']).and_return([]) } + it { is_expected.to run.with_params(['/etc/xyzxyzxyz', '/etcxyzxyzxyz']).and_return([]) } +end -- cgit v1.2.3 From 2cc0d66c76895583f5b0c7c38b88d2bc6af8b4f9 Mon Sep 17 00:00:00 2001 From: Paula McMaw Date: Tue, 21 Feb 2017 15:39:46 +0000 Subject: Adding unit test for i18n concat function --- spec/functions/concat_spec.rb | 1 + 1 file changed, 1 insertion(+) (limited to 'spec/functions') diff --git a/spec/functions/concat_spec.rb b/spec/functions/concat_spec.rb index eb76233..0e67a60 100755 --- a/spec/functions/concat_spec.rb +++ b/spec/functions/concat_spec.rb @@ -12,6 +12,7 @@ describe 'concat' do it { is_expected.to run.with_params(['1','2'],['3','4'],['5','6']).and_return(['1','2','3','4','5','6']) } it { is_expected.to run.with_params(['1','2'],'3','4',['5','6']).and_return(['1','2','3','4','5','6']) } it { is_expected.to run.with_params([{"a" => "b"}], {"c" => "d", "e" => "f"}).and_return([{"a" => "b"}, {"c" => "d", "e" => "f"}]) } + it { is_expected.to run.with_params(['ấ','β','c'],['đ','ể','ƒ']).and_return(['ấ','β','c','đ','ể','ƒ']) } it "should leave the original array intact" do argument1 = ['1','2','3'] -- cgit v1.2.3 From 68fa8d32511e770498118b9c1ccc1dfd1e89c860 Mon Sep 17 00:00:00 2001 From: Paula McMaw Date: Tue, 21 Feb 2017 15:40:04 +0000 Subject: Adding unit test for i18n count function --- spec/functions/count_spec.rb | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'spec/functions') diff --git a/spec/functions/count_spec.rb b/spec/functions/count_spec.rb index c8d1960..3854cb8 100755 --- a/spec/functions/count_spec.rb +++ b/spec/functions/count_spec.rb @@ -15,4 +15,9 @@ describe 'count' do it { is_expected.to run.with_params(["one", nil, "two"]).and_return(2) } it { is_expected.to run.with_params(["one", "", "two"]).and_return(2) } it { is_expected.to run.with_params(["one", :undef, "two"]).and_return(2) } + + it { is_expected.to run.with_params(["ổņ℮", "ŧщộ", "three"]).and_return(3) } + it { is_expected.to run.with_params(["ổņ℮", "ŧщộ", "ŧщộ"], "ŧщộ").and_return(2) } + it { is_expected.to run.with_params(["ổņ℮", nil, "ŧщộ"]).and_return(2) } + it { is_expected.to run.with_params(["ổņ℮", :undef, "ŧщộ"]).and_return(2) } end -- cgit v1.2.3 From 83d68fef749869dc917539f7f05592dc2f2ce642 Mon Sep 17 00:00:00 2001 From: Paula McMaw Date: Tue, 21 Feb 2017 15:51:59 +0000 Subject: Adding unit test for i18n delete function --- spec/functions/delete_spec.rb | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'spec/functions') diff --git a/spec/functions/delete_spec.rb b/spec/functions/delete_spec.rb index b44accf..4e37865 100755 --- a/spec/functions/delete_spec.rb +++ b/spec/functions/delete_spec.rb @@ -19,6 +19,7 @@ describe 'delete' do it { is_expected.to run.with_params(['one', 'two', 'three'], 'two').and_return(['one', 'three']) } it { is_expected.to run.with_params(['two', 'one', 'two', 'three', 'two'], 'two').and_return(['one', 'three']) } it { is_expected.to run.with_params(['one', 'two', 'three', 'two'], ['one', 'two']).and_return(['three']) } + it { is_expected.to run.with_params(['ồאּẻ', 'ŧẅơ', 'ŧңŗё℮', 'ŧẅơ'], ['ồאּẻ', 'ŧẅơ']).and_return(['ŧңŗё℮']) } end describe 'deleting from a string' do @@ -30,7 +31,8 @@ describe 'delete' do it { is_expected.to run.with_params('barfoobar', 'bar').and_return('foo') } it { is_expected.to run.with_params('foobarbabarz', 'bar').and_return('foobaz') } it { is_expected.to run.with_params('foobarbabarz', ['foo', 'bar']).and_return('baz') } - # this is so sick + it { is_expected.to run.with_params('ƒōōβậяβậβậяź', ['ƒōō', 'βậя']).and_return('βậź') } + it { is_expected.to run.with_params('barfoobar', ['barbar', 'foo']).and_return('barbar') } it { is_expected.to run.with_params('barfoobar', ['foo', 'barbar']).and_return('') } end @@ -47,6 +49,10 @@ describe 'delete' do .with_params({'key1' => 'value1', 'key2' => 'value2', 'key3' => 'value3'}, ['key1', 'key2']) \ .and_return( {'key3' => 'value3'}) } + it { is_expected.to run \ + .with_params({'ĸəұ1' => 'νãŀủĕ1', 'ĸəұ2' => 'νãŀủĕ2', 'ĸəұ3' => 'νãŀủĕ3'}, ['ĸəұ1', 'ĸəұ2']) \ + .and_return( {'ĸəұ3' => 'νãŀủĕ3'}) + } end it "should leave the original array intact" do -- cgit v1.2.3 From 846ddcd09e1a5bf27acb6cb5fd1e0854bb1538f6 Mon Sep 17 00:00:00 2001 From: Paula McMaw Date: Tue, 21 Feb 2017 16:01:06 +0000 Subject: Adding unit test for i18n delete_at function --- spec/functions/delete_at_spec.rb | 2 ++ 1 file changed, 2 insertions(+) (limited to 'spec/functions') diff --git a/spec/functions/delete_at_spec.rb b/spec/functions/delete_at_spec.rb index 0e19472..0471039 100755 --- a/spec/functions/delete_at_spec.rb +++ b/spec/functions/delete_at_spec.rb @@ -18,6 +18,8 @@ describe 'delete_at' do it { is_expected.to run.with_params([0, 1, 2], 1).and_return([0, 2]) } it { is_expected.to run.with_params([0, 1, 2], -1).and_return([0, 1]) } it { is_expected.to run.with_params([0, 1, 2], -4).and_return([0, 1, 2]) } + it { is_expected.to run.with_params(["ƒờở", "βāř", "ьầż"], 1).and_return(["ƒờở", "ьầż"]) } + it "should leave the original array intact" do argument = [1, 2, 3] -- cgit v1.2.3 From 150696a028d047321e9e53081d0922e039a66312 Mon Sep 17 00:00:00 2001 From: Paula McMaw Date: Tue, 21 Feb 2017 16:04:47 +0000 Subject: Adding unit test for i18n delete_value function --- spec/functions/delete_values_spec.rb | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'spec/functions') diff --git a/spec/functions/delete_values_spec.rb b/spec/functions/delete_values_spec.rb index 12907d4..329fa0b 100755 --- a/spec/functions/delete_values_spec.rb +++ b/spec/functions/delete_values_spec.rb @@ -19,7 +19,11 @@ describe 'delete_values' do .and_return({'key1' => 'value1'}) } it { is_expected.to run \ - .with_params({'key1' => 'value1', 'key2' => 'value to delete'}, 'value to delete') \ + .with_params({'ҝếỵ1 ' => 'νâĺūẹ1', 'ҝếỵ2' => 'value to delete'}, 'value to delete') \ + .and_return({'ҝếỵ1 ' => 'νâĺūẹ1'}) + } + it { is_expected.to run \ + .with_params({'key1' => 'value1', 'key2' => 'νǎŀữ℮ ťớ đêłểťė'}, 'νǎŀữ℮ ťớ đêłểťė') \ .and_return({'key1' => 'value1'}) } it { is_expected.to run \ -- cgit v1.2.3 From f4436af32c8f69469100dae36da9ef9c02966b40 Mon Sep 17 00:00:00 2001 From: Paula McMaw Date: Wed, 22 Feb 2017 14:01:35 +0000 Subject: (FM-6054) - Unit tests for low effort functions --- spec/functions/delete_undef_values_spec.rb | 1 + spec/functions/difference_spec.rb | 2 ++ spec/functions/flatten_spec.rb | 1 + spec/functions/fqdn_rand_string_spec.rb | 1 + spec/functions/fqdn_rotate_spec.rb | 1 + spec/functions/grep_spec.rb | 1 + spec/functions/hash_spec.rb | 1 + spec/functions/intersection_spec.rb | 1 + spec/functions/join_keys_to_values_spec.rb | 7 +++++++ spec/functions/join_spec.rb | 1 + spec/functions/lstrip_spec.rb | 1 + spec/functions/member_spec.rb | 2 ++ spec/functions/pick_default_spec.rb | 2 ++ spec/functions/prefix_spec.rb | 1 + spec/functions/reject_spec.rb | 1 + spec/functions/reverse_spec.rb | 2 ++ spec/functions/rstrip_spec.rb | 1 + spec/functions/size_spec.rb | 3 +++ spec/functions/strip_spec.rb | 1 + spec/functions/suffix_spec.rb | 2 ++ spec/functions/union_spec.rb | 1 + spec/functions/unique_spec.rb | 2 ++ 22 files changed, 36 insertions(+) (limited to 'spec/functions') diff --git a/spec/functions/delete_undef_values_spec.rb b/spec/functions/delete_undef_values_spec.rb index ec9fb9c..c20cee2 100755 --- a/spec/functions/delete_undef_values_spec.rb +++ b/spec/functions/delete_undef_values_spec.rb @@ -16,6 +16,7 @@ describe 'delete_undef_values' do end it { is_expected.to run.with_params([undef_value]).and_return([]) } it { is_expected.to run.with_params(['one',undef_value,'two','three']).and_return(['one','two','three']) } + it { is_expected.to run.with_params(['ớņέ',undef_value,'ŧשּׁō','ŧħґëə']).and_return(['ớņέ','ŧשּׁō','ŧħґëə']) } end it "should leave the original argument intact" do diff --git a/spec/functions/difference_spec.rb b/spec/functions/difference_spec.rb index d5e983d..0ae3689 100755 --- a/spec/functions/difference_spec.rb +++ b/spec/functions/difference_spec.rb @@ -12,8 +12,10 @@ describe 'difference' do it { is_expected.to run.with_params([], []).and_return([]) } it { is_expected.to run.with_params([], ['one']).and_return([]) } it { is_expected.to run.with_params(['one'], ['one']).and_return([]) } + it { is_expected.to run.with_params(['ớņέ'], ['']).and_return(['ớņέ']) } it { is_expected.to run.with_params(['one'], []).and_return(['one']) } it { is_expected.to run.with_params(['one', 'two', 'three'], ['two', 'three']).and_return(['one']) } + it { is_expected.to run.with_params(['ớņέ', 'ŧשּׁō', 'ŧħґëə', 2], ['ŧשּׁō', 'ŧħґëə']).and_return(['ớņέ', 2]) } it { is_expected.to run.with_params(['one', 'two', 'two', 'three'], ['two', 'three']).and_return(['one']) } it { is_expected.to run.with_params(['one', 'two', 'three'], ['two', 'two', 'three']).and_return(['one']) } it { is_expected.to run.with_params(['one', 'two', 'three'], ['two', 'three', 'four']).and_return(['one']) } diff --git a/spec/functions/flatten_spec.rb b/spec/functions/flatten_spec.rb index a4338be..b80f3c5 100755 --- a/spec/functions/flatten_spec.rb +++ b/spec/functions/flatten_spec.rb @@ -11,4 +11,5 @@ describe 'flatten' do it { is_expected.to run.with_params([['one']]).and_return(['one']) } it { is_expected.to run.with_params(["a","b","c","d","e","f","g"]).and_return(["a","b","c","d","e","f","g"]) } it { is_expected.to run.with_params([["a","b",["c",["d","e"],"f","g"]]]).and_return(["a","b","c","d","e","f","g"]) } + it { is_expected.to run.with_params(["ã","β",["ĉ",["đ","ẽ","ƒ","ġ"]]]).and_return(["ã","β","ĉ","đ","ẽ","ƒ","ġ"]) } end diff --git a/spec/functions/fqdn_rand_string_spec.rb b/spec/functions/fqdn_rand_string_spec.rb index e407084..861a59e 100644 --- a/spec/functions/fqdn_rand_string_spec.rb +++ b/spec/functions/fqdn_rand_string_spec.rb @@ -20,6 +20,7 @@ describe 'fqdn_rand_string' do it { is_expected.to run.with_params(100, '').and_return(default_charset) } it { is_expected.to run.with_params(100, 'a').and_return(/\Aa{100}\z/) } it { is_expected.to run.with_params(100, 'ab').and_return(/\A[ab]{100}\z/) } + it { is_expected.to run.with_params(100, 'ãβ').and_return(/\A[ãβ]{100}\z/) } it "provides the same 'random' value on subsequent calls for the same host" do expect(fqdn_rand_string(10)).to eql(fqdn_rand_string(10)) diff --git a/spec/functions/fqdn_rotate_spec.rb b/spec/functions/fqdn_rotate_spec.rb index db7a717..7c1038a 100755 --- a/spec/functions/fqdn_rotate_spec.rb +++ b/spec/functions/fqdn_rotate_spec.rb @@ -7,6 +7,7 @@ describe 'fqdn_rotate' do it { is_expected.to run.with_params({}).and_raise_error(Puppet::ParseError, /Requires either array or string to work with/) } it { is_expected.to run.with_params('').and_return('') } it { is_expected.to run.with_params('a').and_return('a') } + it { is_expected.to run.with_params('ã').and_return('ã') } it { is_expected.to run.with_params([]).and_return([]) } it { is_expected.to run.with_params(['a']).and_return(['a']) } diff --git a/spec/functions/grep_spec.rb b/spec/functions/grep_spec.rb index 6e0bd6e..d2152b1 100755 --- a/spec/functions/grep_spec.rb +++ b/spec/functions/grep_spec.rb @@ -16,4 +16,5 @@ describe 'grep' do it { is_expected.to run.with_params([], 'two').and_return([]) } it { is_expected.to run.with_params(['one', 'two', 'three'], 'two').and_return(['two']) } it { is_expected.to run.with_params(['one', 'two', 'three'], 't(wo|hree)').and_return(['two', 'three']) } + it { is_expected.to run.with_params(['ờאּê', 'ţשּׂỡ', 'ţһŗəè'], 'ţ(שּׂỡ|һŗəè)').and_return(['ţשּׂỡ', 'ţһŗəè']) } end diff --git a/spec/functions/hash_spec.rb b/spec/functions/hash_spec.rb index 4fe99ce..092474b 100755 --- a/spec/functions/hash_spec.rb +++ b/spec/functions/hash_spec.rb @@ -10,5 +10,6 @@ describe 'hash' do it { is_expected.to run.with_params(['one']).and_raise_error(Puppet::ParseError, /Unable to compute/) } it { is_expected.to run.with_params([]).and_return({}) } it { is_expected.to run.with_params(['key1', 'value1']).and_return({ 'key1' => 'value1' }) } + it { is_expected.to run.with_params(['κ℮ұ1', '√āĺűẻ1']).and_return({ 'κ℮ұ1' => '√āĺűẻ1' }) } it { is_expected.to run.with_params(['key1', 'value1', 'key2', 'value2']).and_return({ 'key1' => 'value1', 'key2' => 'value2' }) } end diff --git a/spec/functions/intersection_spec.rb b/spec/functions/intersection_spec.rb index c0f6086..ec368a5 100755 --- a/spec/functions/intersection_spec.rb +++ b/spec/functions/intersection_spec.rb @@ -14,6 +14,7 @@ describe 'intersection' do it { is_expected.to run.with_params(['one'], []).and_return([]) } it { is_expected.to run.with_params(['one'], ['one']).and_return(['one']) } it { is_expected.to run.with_params(['one', 'two', 'three'], ['two', 'three']).and_return(['two', 'three']) } + it { is_expected.to run.with_params(['ōŋể', 'ŧשợ', 'ţђŕẽё'], ['ŧשợ', 'ţђŕẽё']).and_return(['ŧשợ', 'ţђŕẽё']) } it { is_expected.to run.with_params(['one', 'two', 'two', 'three'], ['two', 'three']).and_return(['two', 'three']) } it { is_expected.to run.with_params(['one', 'two', 'three'], ['two', 'two', 'three']).and_return(['two', 'three']) } it { is_expected.to run.with_params(['one', 'two', 'three'], ['two', 'three', 'four']).and_return(['two', 'three']) } diff --git a/spec/functions/join_keys_to_values_spec.rb b/spec/functions/join_keys_to_values_spec.rb index c2bae5b..0a2a50c 100755 --- a/spec/functions/join_keys_to_values_spec.rb +++ b/spec/functions/join_keys_to_values_spec.rb @@ -11,6 +11,12 @@ describe 'join_keys_to_values' do it { is_expected.to run.with_params({}, ':').and_return([]) } it { is_expected.to run.with_params({ 'key' => 'value' }, '').and_return(['keyvalue']) } it { is_expected.to run.with_params({ 'key' => 'value' }, ':').and_return(['key:value']) } + + context 'should run with UTF8 and double byte characters' do + it { is_expected.to run.with_params({ 'ҝẽγ' => '√ạĺűē' }, ':').and_return(['ҝẽγ:√ạĺűē']) } + it { is_expected.to run.with_params({ 'ҝẽγ' => '√ạĺűē' }, '万').and_return(['ҝẽγ万√ạĺűē']) } + end + it { is_expected.to run.with_params({ 'key' => nil }, ':').and_return(['key:']) } it 'should run join_keys_to_values(, ":") and return the proper array' do result = subject.call([{ 'key1' => 'value1', 'key2' => 'value2' }, ':']) @@ -21,3 +27,4 @@ describe 'join_keys_to_values' do expect(result.sort).to eq(['key1 value1', 'key2 value2', 'key2 value3'].sort) end end + diff --git a/spec/functions/join_spec.rb b/spec/functions/join_spec.rb index a300571..98852d5 100755 --- a/spec/functions/join_spec.rb +++ b/spec/functions/join_spec.rb @@ -16,4 +16,5 @@ describe 'join' do it { is_expected.to run.with_params(['one'], ':').and_return('one') } it { is_expected.to run.with_params(['one', 'two', 'three']).and_return('onetwothree') } it { is_expected.to run.with_params(['one', 'two', 'three'], ':').and_return('one:two:three') } + it { is_expected.to run.with_params(['ōŋể', 'ŧשợ', 'ţђŕẽё'], ':').and_return('ōŋể:ŧשợ:ţђŕẽё') } end diff --git a/spec/functions/lstrip_spec.rb b/spec/functions/lstrip_spec.rb index 981794e..a5a09ed 100755 --- a/spec/functions/lstrip_spec.rb +++ b/spec/functions/lstrip_spec.rb @@ -22,6 +22,7 @@ describe 'lstrip' do it { is_expected.to run.with_params('one ').and_return('one ') } it { is_expected.to run.with_params(' one ').and_return('one ') } it { is_expected.to run.with_params(' one ').and_return('one ') } + it { is_expected.to run.with_params(' ǿňè ').and_return('ǿňè ') } it { is_expected.to run.with_params("\tone ").and_return('one ') } it { is_expected.to run.with_params("\t one ").and_return('one ') } it { is_expected.to run.with_params("one \t").and_return("one \t") } diff --git a/spec/functions/member_spec.rb b/spec/functions/member_spec.rb index 527f887..8988632 100755 --- a/spec/functions/member_spec.rb +++ b/spec/functions/member_spec.rb @@ -17,5 +17,7 @@ describe 'member' do it { is_expected.to run.with_params(['one'], 'one').and_return(true) } it { is_expected.to run.with_params(['one'], ['one']).and_return(true) } it { is_expected.to run.with_params(['one', 'two', 'three', 'four'], ['four', 'two']).and_return(true) } + it { is_expected.to run.with_params(['ọאּẹ', 'ŧẅồ', 'ţҺŗęē', 'ƒơџŕ'], ['ƒơџŕ', 'ŧẅồ']).and_return(true) } it { is_expected.to run.with_params(['one', 'two', 'three', 'four'], ['four', 'five']).and_return(false) } + it { is_expected.to run.with_params(['ọאּẹ', 'ŧẅồ', 'ţҺŗęē', 'ƒơџŕ'], ['ƒơџŕ', 'ƒί√ə']).and_return(false) } end diff --git a/spec/functions/pick_default_spec.rb b/spec/functions/pick_default_spec.rb index e2fc64a..a7ffc86 100755 --- a/spec/functions/pick_default_spec.rb +++ b/spec/functions/pick_default_spec.rb @@ -5,6 +5,7 @@ describe 'pick_default' do it { is_expected.to run.with_params().and_raise_error(Puppet::Error, /Must receive at least one argument/) } it { is_expected.to run.with_params('one', 'two').and_return('one') } + it { is_expected.to run.with_params('ớņệ', 'ťωơ').and_return('ớņệ') } it { is_expected.to run.with_params('', 'two').and_return('two') } it { is_expected.to run.with_params(:undef, 'two').and_return('two') } it { is_expected.to run.with_params(:undefined, 'two').and_return('two') } @@ -13,6 +14,7 @@ describe 'pick_default' do [ '', :undef, :undefined, nil, {}, [], 1, 'default' ].each do |value| describe "when providing #{value.inspect} as default" do it { is_expected.to run.with_params('one', value).and_return('one') } + it { is_expected.to run.with_params('ớņệ', value).and_return('ớņệ') } it { is_expected.to run.with_params([], value).and_return([]) } it { is_expected.to run.with_params({}, value).and_return({}) } it { is_expected.to run.with_params(value, value).and_return(value) } diff --git a/spec/functions/prefix_spec.rb b/spec/functions/prefix_spec.rb index 3761022..5510c58 100755 --- a/spec/functions/prefix_spec.rb +++ b/spec/functions/prefix_spec.rb @@ -11,6 +11,7 @@ describe 'prefix' do it { is_expected.to run.with_params([], 2).and_raise_error(Puppet::ParseError, /expected second argument to be a String/) } it { is_expected.to run.with_params([]).and_return([]) } it { is_expected.to run.with_params(['one', 2]).and_return(['one', '2']) } + it { is_expected.to run.with_params(['ớņệ', 2]).and_return(['ớņệ', '2']) } it { is_expected.to run.with_params([], '').and_return([]) } it { is_expected.to run.with_params([''], '').and_return(['']) } it { is_expected.to run.with_params(['one'], 'pre').and_return(['preone']) } diff --git a/spec/functions/reject_spec.rb b/spec/functions/reject_spec.rb index 4863050..86db7c7 100755 --- a/spec/functions/reject_spec.rb +++ b/spec/functions/reject_spec.rb @@ -16,4 +16,5 @@ describe 'reject' do it { is_expected.to run.with_params([], 'two').and_return([]) } it { is_expected.to run.with_params(['one', 'two', 'three'], 'two').and_return(['one', 'three']) } it { is_expected.to run.with_params(['one', 'two', 'three'], 't(wo|hree)').and_return(['one']) } + it { is_expected.to run.with_params(['όʼnệ', 'ţщồ', 'ţңяέέ'], 'ţ(щồ|ңяέέ)').and_return(['όʼnệ']) } end diff --git a/spec/functions/reverse_spec.rb b/spec/functions/reverse_spec.rb index e00dee9..79bc0ad 100755 --- a/spec/functions/reverse_spec.rb +++ b/spec/functions/reverse_spec.rb @@ -15,11 +15,13 @@ describe 'reverse' do it { is_expected.to run.with_params(['one']).and_return(['one']) } it { is_expected.to run.with_params(['one', 'two', 'three']).and_return(['three', 'two', 'one']) } it { is_expected.to run.with_params(['one', 'two', 'three', 'four']).and_return(['four', 'three', 'two', 'one']) } + it { is_expected.to run.with_params(['ổňë', 'ťŵọ', 'ŧңяəė', 'ƒŏůŗ']).and_return(['ƒŏůŗ', 'ŧңяəė', 'ťŵọ', 'ổňë']) } it { is_expected.to run.with_params('').and_return('') } it { is_expected.to run.with_params('a').and_return('a') } it { is_expected.to run.with_params('abc').and_return('cba') } it { is_expected.to run.with_params('abcd').and_return('dcba') } + it { is_expected.to run.with_params('āβćđ').and_return('đćβā') } context 'when using a class extending String' do it 'should call its reverse method' do diff --git a/spec/functions/rstrip_spec.rb b/spec/functions/rstrip_spec.rb index d2efac8..a7663e2 100755 --- a/spec/functions/rstrip_spec.rb +++ b/spec/functions/rstrip_spec.rb @@ -22,6 +22,7 @@ describe 'rstrip' do it { is_expected.to run.with_params('one ').and_return('one') } it { is_expected.to run.with_params(' one ').and_return(' one') } it { is_expected.to run.with_params(' one ').and_return(' one') } + it { is_expected.to run.with_params(' ǿňè ').and_return(' ǿňè') } it { is_expected.to run.with_params("\tone ").and_return("\tone") } it { is_expected.to run.with_params("\t one ").and_return("\t one") } it { is_expected.to run.with_params("one\t").and_return('one') } diff --git a/spec/functions/size_spec.rb b/spec/functions/size_spec.rb index c0047ee..2047423 100755 --- a/spec/functions/size_spec.rb +++ b/spec/functions/size_spec.rb @@ -19,11 +19,14 @@ describe 'size' do it { is_expected.to run.with_params({}).and_return(0) } it { is_expected.to run.with_params({'1' => '2'}).and_return(1) } it { is_expected.to run.with_params({'1' => '2', '4' => '4'}).and_return(2) } + it { is_expected.to run.with_params({'€' => '@', '竹' => 'ǿňè'}).and_return(2) } it { is_expected.to run.with_params('').and_return(0) } it { is_expected.to run.with_params('a').and_return(1) } it { is_expected.to run.with_params('abc').and_return(3) } it { is_expected.to run.with_params('abcd').and_return(4) } + it { is_expected.to run.with_params('万').and_return(1) } + it { is_expected.to run.with_params('āβćđ').and_return(4) } context 'when using a class extending String' do it 'should call its size method' do diff --git a/spec/functions/strip_spec.rb b/spec/functions/strip_spec.rb index 689b6dd..18e943d 100755 --- a/spec/functions/strip_spec.rb +++ b/spec/functions/strip_spec.rb @@ -30,5 +30,6 @@ describe 'strip' do it { is_expected.to run.with_params("\tone \t").and_return('one') } it { is_expected.to run.with_params("\t one \t").and_return('one') } it { is_expected.to run.with_params(' o n e ').and_return('o n e') } + it { is_expected.to run.with_params(' ỏŋέ ').and_return('ỏŋέ') } it { is_expected.to run.with_params(AlsoString.new(' one ')).and_return('one') } end diff --git a/spec/functions/suffix_spec.rb b/spec/functions/suffix_spec.rb index efba4ab..e0eafb1 100755 --- a/spec/functions/suffix_spec.rb +++ b/spec/functions/suffix_spec.rb @@ -15,6 +15,8 @@ describe 'suffix' do it { is_expected.to run.with_params([''], '').and_return(['']) } it { is_expected.to run.with_params(['one'], 'post').and_return(['onepost']) } it { is_expected.to run.with_params(['one', 'two', 'three'], 'post').and_return(['onepost', 'twopost', 'threepost']) } + it { is_expected.to run.with_params(['ỗńέ', 'ťשׂǿ', 'ŧҺř℮ə'], 'рổŝţ').and_return(['ỗńέрổŝţ', 'ťשׂǿрổŝţ', 'ŧҺř℮əрổŝţ']) } + it { is_expected.to run.with_params({}).and_return({}) } diff --git a/spec/functions/union_spec.rb b/spec/functions/union_spec.rb index cfd38b6..3f36f24 100755 --- a/spec/functions/union_spec.rb +++ b/spec/functions/union_spec.rb @@ -20,5 +20,6 @@ describe 'union' do it { is_expected.to run.with_params(['one', 'two', 'three'], ['two', 'two', 'three']).and_return(['one', 'two', 'three']) } it { is_expected.to run.with_params(['one', 'two'], ['two', 'three'], ['one', 'three']).and_return(['one', 'two', 'three']) } it { is_expected.to run.with_params(['one', 'two'], ['three', 'four'], ['one', 'two', 'three'], ['four']).and_return(['one', 'two', 'three', 'four']) } + it { is_expected.to run.with_params(['ốńə', 'ţשׂợ'], ['ŧĥяếệ', 'ƒởųŗ'], ['ốńə', 'ţשׂợ', 'ŧĥяếệ'], ['ƒởųŗ']).and_return(['ốńə', 'ţשׂợ', 'ŧĥяếệ', 'ƒởųŗ']) } it 'should not confuse types' do is_expected.to run.with_params(['1', '2', '3'], [1, 2]).and_return(['1', '2', '3', 1, 2]) end end diff --git a/spec/functions/unique_spec.rb b/spec/functions/unique_spec.rb index 24257a0..7955acb 100755 --- a/spec/functions/unique_spec.rb +++ b/spec/functions/unique_spec.rb @@ -17,11 +17,13 @@ describe 'unique' do it { is_expected.to run.with_params([]).and_return([]) } it { is_expected.to run.with_params(['a']).and_return(['a']) } it { is_expected.to run.with_params(['a', 'b', 'a']).and_return(['a', 'b']) } + it { is_expected.to run.with_params(['ã', 'ъ', 'ã']).and_return(['ã', 'ъ']) } end context 'when called with a string' do it { is_expected.to run.with_params('').and_return('') } it { is_expected.to run.with_params('a').and_return('a') } it { is_expected.to run.with_params('aaba').and_return('ab') } + it { is_expected.to run.with_params('ããъã').and_return('ãъ') } end end -- cgit v1.2.3 From b13af823335e6952c8494ecbdb6b2955fbd2d9eb Mon Sep 17 00:00:00 2001 From: Paula McMaw Date: Tue, 28 Feb 2017 12:03:01 +0000 Subject: (FM-6058) - Unit tests for med effort functions --- spec/functions/basename_spec.rb | 5 +++++ spec/functions/chomp_spec.rb | 5 +++++ spec/functions/chop_spec.rb | 5 +++++ spec/functions/deep_merge_spec.rb | 4 ++++ spec/functions/dirname_spec.rb | 5 +++++ spec/functions/fqdn_uuid_spec.rb | 1 - spec/functions/getvar_spec.rb | 15 +++++++++++++++ spec/functions/has_key_spec.rb | 5 +++++ spec/functions/is_a_spec.rb | 5 +++++ spec/functions/pick_spec.rb | 5 +++++ spec/functions/regexpescape_spec.rb | 5 +++++ spec/functions/shell_escape_spec.rb | 5 +++++ spec/functions/shell_join_spec.rb | 5 +++++ spec/functions/shell_split_spec.rb | 5 +++++ spec/functions/shuffle_spec.rb | 5 +++++ spec/functions/values_at_spec.rb | 5 +++++ spec/functions/values_spec.rb | 5 +++++ spec/functions/zip_spec.rb | 6 ++++++ 18 files changed, 95 insertions(+), 1 deletion(-) (limited to 'spec/functions') diff --git a/spec/functions/basename_spec.rb b/spec/functions/basename_spec.rb index c84e192..3e02b01 100755 --- a/spec/functions/basename_spec.rb +++ b/spec/functions/basename_spec.rb @@ -11,4 +11,9 @@ describe 'basename' do it { is_expected.to run.with_params('/path/to/a/file.ext', '.ext').and_return('file') } it { is_expected.to run.with_params('relative_path/to/a/file.ext', '.ext').and_return('file') } it { is_expected.to run.with_params('scheme:///path/to/a/file.ext').and_return('file.ext') } + + context 'should run with UTF8 and double byte characters' do + it { is_expected.to run.with_params('scheme:///√ạĺűē/竹.ext').and_return('竹.ext') } + it { is_expected.to run.with_params('ҝẽγ:/√ạĺűē/竹.ㄘ', '.ㄘ').and_return('竹') } + end end diff --git a/spec/functions/chomp_spec.rb b/spec/functions/chomp_spec.rb index 6878742..56bd9b1 100755 --- a/spec/functions/chomp_spec.rb +++ b/spec/functions/chomp_spec.rb @@ -17,4 +17,9 @@ describe 'chomp' do it { is_expected.to run.with_params(AlsoString.new("one\n")).and_return("one") } it { is_expected.to run.with_params(AlsoString.new("one\n\n")).and_return("one\n") } it { is_expected.to run.with_params([AlsoString.new("one\n"), AlsoString.new("two"), "three\n"]).and_return(["one", "two", "three"]) } + + context 'should run with UTF8 and double byte characters' do + it { is_expected.to run.with_params("ůťƒ8\n\n").and_return("ůťƒ8\n") } + it { is_expected.to run.with_params("ネット\n\n").and_return("ネット\n") } + end end diff --git a/spec/functions/chop_spec.rb b/spec/functions/chop_spec.rb index db7d18b..b70fc37 100755 --- a/spec/functions/chop_spec.rb +++ b/spec/functions/chop_spec.rb @@ -17,4 +17,9 @@ describe 'chop' do it { is_expected.to run.with_params(AlsoString.new("one\n")).and_return("one") } it { is_expected.to run.with_params(AlsoString.new("one\n\n")).and_return("one\n") } it { is_expected.to run.with_params([AlsoString.new("one\n"), AlsoString.new("two"), "three\n"]).and_return(["one", "tw", "three"]) } + + context 'should run with UTF8 and double byte characters' do + it { is_expected.to run.with_params("ůťƒ8\n\n").and_return("ůťƒ8\n") } + it { is_expected.to run.with_params("ネット\n\n").and_return("ネット\n") } + end end diff --git a/spec/functions/deep_merge_spec.rb b/spec/functions/deep_merge_spec.rb index 397e048..c91a07e 100755 --- a/spec/functions/deep_merge_spec.rb +++ b/spec/functions/deep_merge_spec.rb @@ -52,4 +52,8 @@ describe 'deep_merge' do expect(argument1).to eq(original1) expect(argument2).to eq(original2) end + + context 'should run with UTF8 and double byte characters' do + it { is_expected.to run.with_params({'ĸέỹ1' => 'ϋǻļủë1'}, {'この文字列' => '万' }).and_return({'ĸέỹ1' => 'ϋǻļủë1', 'この文字列' => '万'}) } + end end diff --git a/spec/functions/dirname_spec.rb b/spec/functions/dirname_spec.rb index 46c4c35..c494915 100755 --- a/spec/functions/dirname_spec.rb +++ b/spec/functions/dirname_spec.rb @@ -10,4 +10,9 @@ describe 'dirname' do it { is_expected.to run.with_params('/path/to/a/file.ext', []).and_raise_error(Puppet::ParseError) } it { is_expected.to run.with_params('/path/to/a/file.ext').and_return('/path/to/a') } it { is_expected.to run.with_params('relative_path/to/a/file.ext').and_return('relative_path/to/a') } + + context 'should run with UTF8 and double byte characters' do + it { is_expected.to run.with_params('scheme:///√ạĺűē/竹.ext').and_return('scheme:///√ạĺűē') } + it { is_expected.to run.with_params('ҝẽγ:/√ạĺűē/竹.ㄘ').and_return('ҝẽγ:/√ạĺűē') } + end end diff --git a/spec/functions/fqdn_uuid_spec.rb b/spec/functions/fqdn_uuid_spec.rb index a2d1618..d0c30d6 100644 --- a/spec/functions/fqdn_uuid_spec.rb +++ b/spec/functions/fqdn_uuid_spec.rb @@ -10,5 +10,4 @@ describe 'fqdn_uuid' do it { should run.with_params('puppetlabs.com').and_return('9c70320f-6815-5fc5-ab0f-debe68bf764c') } it { should run.with_params('google.com').and_return('64ee70a4-8cc1-5d25-abf2-dea6c79a09c8') } end - end diff --git a/spec/functions/getvar_spec.rb b/spec/functions/getvar_spec.rb index 54f1842..55789d8 100755 --- a/spec/functions/getvar_spec.rb +++ b/spec/functions/getvar_spec.rb @@ -20,4 +20,19 @@ describe 'getvar' do it { is_expected.to run.with_params('::site::data::foo').and_return('baz') } it { is_expected.to run.with_params('::site::data::bar').and_return(nil) } end + + context 'given variables in namespaces' do + let(:pre_condition) { + <<-'ENDofPUPPETcode' + class site::info { $lock = 'ŧҺîš íš ắ śţřĭŋĝ' } + class site::new { $item = '万Ü€‰' } + include site::info + include site::new + ENDofPUPPETcode + } + + it { is_expected.to run.with_params('site::info::lock').and_return('ŧҺîš íš ắ śţřĭŋĝ') } + it { is_expected.to run.with_params('::site::new::item').and_return('万Ü€‰') } + end end + diff --git a/spec/functions/has_key_spec.rb b/spec/functions/has_key_spec.rb index 965d5a6..0e0e1cc 100755 --- a/spec/functions/has_key_spec.rb +++ b/spec/functions/has_key_spec.rb @@ -12,4 +12,9 @@ describe 'has_key' do it { is_expected.to run.with_params({ 'key' => 'value' }, "key").and_return(true) } it { is_expected.to run.with_params({}, "key").and_return(false) } it { is_expected.to run.with_params({ 'key' => 'value'}, "not a key").and_return(false) } + + context 'should run with UTF8 and double byte characters' do + it { is_expected.to run.with_params({ 'κéỳ ' => '٧ậļųể' }, "κéỳ ").and_return(true) } + it { is_expected.to run.with_params({ 'キー' => '٧ậļųể' }, "キー").and_return(true) } + end end diff --git a/spec/functions/is_a_spec.rb b/spec/functions/is_a_spec.rb index 8dec13f..2d6cb46 100644 --- a/spec/functions/is_a_spec.rb +++ b/spec/functions/is_a_spec.rb @@ -21,5 +21,10 @@ if Puppet.version.to_f >= 4.0 it 'fails when comparing an integer and a string' do is_expected.to run.with_params(5, String).and_return(false) end + + it 'suceeds when comparing an UTF8 and double byte characters' do + is_expected.to run.with_params('このテキスト', String).and_return(true) + is_expected.to run.with_params('ŧћịś ŧêχŧ', String).and_return(true) + end end end diff --git a/spec/functions/pick_spec.rb b/spec/functions/pick_spec.rb index 2c7caa8..438553b 100755 --- a/spec/functions/pick_spec.rb +++ b/spec/functions/pick_spec.rb @@ -9,4 +9,9 @@ describe 'pick' do it { is_expected.to run.with_params(:undef, 'two').and_return('two') } it { is_expected.to run.with_params(:undefined, 'two').and_return('two') } it { is_expected.to run.with_params(nil, 'two').and_return('two') } + + context 'should run with UTF8 and double byte characters' do + it { is_expected.to run.with_params(nil, 'このテキスト').and_return('このテキスト') } + it { is_expected.to run.with_params('', 'ŝẳмрłề џţƒ8 ţẽם', 'このテキスト').and_return('ŝẳмрłề џţƒ8 ţẽם') } + end end diff --git a/spec/functions/regexpescape_spec.rb b/spec/functions/regexpescape_spec.rb index 6efa847..36dbe70 100644 --- a/spec/functions/regexpescape_spec.rb +++ b/spec/functions/regexpescape_spec.rb @@ -32,5 +32,10 @@ describe 'regexpescape' do it { is_expected.to run.with_params([]).and_return([]) } it { is_expected.to run.with_params(['one*', "two"]).and_return(['one\*', "two"]) } it { is_expected.to run.with_params(['one*', 1, true, {}, "two"]).and_return(['one\*', 1, true, {}, "two"]) } + + context 'should run with UTF8 and double byte characters' do + it { is_expected.to run.with_params(['ŏʼnε*']).and_return(['ŏʼnε\*']) } + it { is_expected.to run.with_params(['インターネット*']).and_return(['インターネット\*']) } + end end end diff --git a/spec/functions/shell_escape_spec.rb b/spec/functions/shell_escape_spec.rb index 3061dec..77917dd 100644 --- a/spec/functions/shell_escape_spec.rb +++ b/spec/functions/shell_escape_spec.rb @@ -19,4 +19,9 @@ describe 'shell_escape' do it { is_expected.to run.with_params('~`!@#$%^&*()_+-=[]\{}|;\':",./<>?') .and_return('\~\`\!@\#\$\%\^\&\*\(\)_\+-\=\[\]\\\\\{\}\|\;\\\':\",./\<\>\?') } end + + context 'should run with UTF8 and double byte characters' do + it { is_expected.to run.with_params('スペー スを含むテ キスト').and_return('\\ス\\ペ\\ー\\ \\ス\\を\\含\\む\\テ\\ \\ \\キ\\ス\\ト') } + it { is_expected.to run.with_params('μťƒ 8 ŧĕχť').and_return('\\μ\\ť\\ƒ\\ 8\\ \\ \\ŧ\\ĕ\\χ\\ť') } + end end diff --git a/spec/functions/shell_join_spec.rb b/spec/functions/shell_join_spec.rb index 6815f7c..46305bf 100644 --- a/spec/functions/shell_join_spec.rb +++ b/spec/functions/shell_join_spec.rb @@ -15,6 +15,11 @@ describe 'shell_join' do it { is_expected.to run.with_params(['foo', 'bar baz']).and_return('foo bar\ baz') } it { is_expected.to run.with_params(['~`!@#$', '%^&*()_+-=', '[]\{}|;\':"', ',./<>?']) .and_return('\~\`\!@\#\$ \%\^\&\*\(\)_\+-\= \[\]\\\\\{\}\|\;\\\':\" ,./\<\>\?') } + + context 'should run with UTF8 and double byte characters' do + it { is_expected.to run.with_params(['μťƒ', '8', 'ŧĕχť']).and_return('\\μ\\ť\\ƒ 8 \\ŧ\\ĕ\\χ\\ť') } + it { is_expected.to run.with_params(['スペー', 'スを含むテ', ' キスト']).and_return('\\ス\\ペ\\ー \\ス\\を\\含\\む\\テ \\ \\キ\\ス\\ト') } + end end describe 'stringification' do diff --git a/spec/functions/shell_split_spec.rb b/spec/functions/shell_split_spec.rb index beeb977..f8f9c90 100644 --- a/spec/functions/shell_split_spec.rb +++ b/spec/functions/shell_split_spec.rb @@ -20,5 +20,10 @@ describe 'shell_split' do .and_return(['~`!@#$%^&*()_+-=[]\{}|;\':",./<>?']) } it { is_expected.to run.with_params('\~\`\!@\#\$ \%\^\&\*\(\)_\+-\= \[\]\\\\\{\}\|\;\\\':\" ,./\<\>\?') .and_return(['~`!@#$', '%^&*()_+-=', '[]\{}|;\':"', ',./<>?']) } + + context 'should run with UTF8 and double byte characters' do + it { is_expected.to run.with_params('\\μ\\ť\\ƒ 8 \\ŧ\\ĕ\\χ\\ť').and_return(['μťƒ', '8', 'ŧĕχť']) } + it { is_expected.to run.with_params('\\ス\\ペ\\ー \\ス\\を\\含\\む\\テ \\ \\キ\\ス\\ト').and_return(['スペー', 'スを含むテ', ' キスト']) } + end end end diff --git a/spec/functions/shuffle_spec.rb b/spec/functions/shuffle_spec.rb index ebc3a73..4673daa 100755 --- a/spec/functions/shuffle_spec.rb +++ b/spec/functions/shuffle_spec.rb @@ -26,6 +26,11 @@ describe 'shuffle' do it { is_expected.to run.with_params('abc').and_return('bac') } it { is_expected.to run.with_params('abcd').and_return('dcba') } + context 'should run with UTF8 and double byte characters' do + it { is_expected.to run.with_params('ůţƒ8 ŧέχŧ şŧґíńģ').and_return('ģńş ůχţέƒŧí8ґŧŧ ') } + it { is_expected.to run.with_params('日本語の文字列').and_return('字本日語文列の') } + end + context 'when using a class extending String' do it { is_expected.to run.with_params(AlsoString.new('asdfghjkl')).and_return('lkhdsfajg') } end diff --git a/spec/functions/values_at_spec.rb b/spec/functions/values_at_spec.rb index a8348f3..681c101 100755 --- a/spec/functions/values_at_spec.rb +++ b/spec/functions/values_at_spec.rb @@ -30,6 +30,11 @@ describe 'values_at' do it { is_expected.to run.with_params([0, 1, 2], 3).and_raise_error(Puppet::ParseError, /index exceeds array size/) } end + context 'when requesting a single item using UTF8 and double byte characters' do + it { is_expected.to run.with_params(['ẩ', 'β', 'с', 'ď'], 0).and_return(['ẩ']) } + it { is_expected.to run.with_params(['文', '字', 'の', '値'], 2).and_return(['の']) } + end + context 'when requesting multiple items' do it { is_expected.to run.with_params([0, 1, 2], [1, -1]).and_raise_error(Puppet::ParseError, /Unknown format of given index/) } it { is_expected.to run.with_params([0, 1, 2], [0, 2]).and_return([0, 2]) } diff --git a/spec/functions/values_spec.rb b/spec/functions/values_spec.rb index 4abf0bd..26c6dfb 100755 --- a/spec/functions/values_spec.rb +++ b/spec/functions/values_spec.rb @@ -16,4 +16,9 @@ describe 'values' do result = subject.call([{ 'key1' => 'value1', 'key2' => 'value2', 'duplicate_value_key' => 'value2' }]) expect(result).to match_array(['value1', 'value2', 'value2']) end + + it 'should run with UTF8 and double byte characters' do + result = subject.call([{ 'かぎ' => '使用', 'ҝĕұ' => '√ẩŀứệ', 'ҝĕұďŭрļǐçằťè' => '√ẩŀứệ' }]) + expect(result).to match_array(['使用', '√ẩŀứệ', '√ẩŀứệ']) + end end diff --git a/spec/functions/zip_spec.rb b/spec/functions/zip_spec.rb index abca7ee..e1ae8ee 100755 --- a/spec/functions/zip_spec.rb +++ b/spec/functions/zip_spec.rb @@ -12,4 +12,10 @@ describe 'zip' do it { is_expected.to run.with_params([1,2,3], [4,5,6]).and_return([[1,4], [2,5], [3,6]]) } it { is_expected.to run.with_params([1,2,3], [4,5,6], false).and_return([[1,4], [2,5], [3,6]]) } it { is_expected.to run.with_params([1,2,3], [4,5,6], true).and_return([1, 4, 2, 5, 3, 6]) } + + context 'should run with UTF8 and double byte characters' do + it { is_expected.to run.with_params(['ầ', 'ь', 'ć'], ['đ', 'ề', 'ƒ']).and_return([['ầ','đ'], ['ь','ề'], ['ć', 'ƒ']]) } + it { is_expected.to run.with_params(['ペ', '含', '値'], ['ッ', '文', 'イ']).and_return([['ペ','ッ'], ['含','文'], ['値', 'イ']]) } + end end + -- cgit v1.2.3 From 496d19640cc239f59e456c381bd9912cde60a07e Mon Sep 17 00:00:00 2001 From: Peter Souter Date: Fri, 3 Mar 2017 11:43:12 +0000 Subject: (MODULES-4485) Improve ipv6 support for type * Improves regex to catch some valid (but less known) ipv6 strings, mostly those which are a mix of ipv6 strings and embedded ipv4 numbers * Regex inspired by the following: * https://github.com/sindresorhus/ip-regex * https://gist.github.com/cpetschnig/294476 * The original Dartware forum thread where someone originally created this beast of a regex, now lost except to archive.org * Whilst we're here, we can add the more tricky ipv6 strings to the existing functions to validate * Luckily, the `ipaddr` native ruby library used in the original functions already supports these --- spec/functions/validate_ipv6_address_spec.rb | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'spec/functions') diff --git a/spec/functions/validate_ipv6_address_spec.rb b/spec/functions/validate_ipv6_address_spec.rb index 78810d4..137db36 100755 --- a/spec/functions/validate_ipv6_address_spec.rb +++ b/spec/functions/validate_ipv6_address_spec.rb @@ -29,6 +29,13 @@ describe 'validate_ipv6_address' do it { is_expected.to run.with_params('3ffe:0505:0002::', '3ffe:0505:0002::2') } it { is_expected.to run.with_params('::1/64') } it { is_expected.to run.with_params('fe80::a00:27ff:fe94:44d6/64') } + it { is_expected.to run.with_params('fe80:0000:0000:0000:0204:61ff:fe9d:f156') } + it { is_expected.to run.with_params('fe80:0:0:0:204:61ff:fe9d:f156') } + it { is_expected.to run.with_params('fe80::204:61ff:fe9d:f156') } + it { is_expected.to run.with_params('fe80:0:0:0:0204:61ff:254.157.241.86') } + it { is_expected.to run.with_params('::1') } + it { is_expected.to run.with_params('fe80::') } + it { is_expected.to run.with_params('2001::') } end describe 'invalid inputs' do @@ -38,6 +45,9 @@ describe 'validate_ipv6_address' do it { is_expected.to run.with_params('0.0.0').and_raise_error(Puppet::ParseError, /is not a valid IPv6/) } it { is_expected.to run.with_params('0.0.0.256').and_raise_error(Puppet::ParseError, /is not a valid IPv6/) } it { is_expected.to run.with_params('0.0.0.0.0').and_raise_error(Puppet::ParseError, /is not a valid IPv6/) } + it { is_expected.to run.with_params('::ffff:2.3.4').and_raise_error(Puppet::ParseError, /is not a valid IPv6/) } + it { is_expected.to run.with_params('::ffff:257.1.2.3').and_raise_error(Puppet::ParseError, /is not a valid IPv6/) } + it { is_expected.to run.with_params('::ffff:12345678901234567890.1.26').and_raise_error(Puppet::ParseError, /is not a valid IPv6/) } it { is_expected.to run.with_params('affe:beef').and_raise_error(Puppet::ParseError, /is not a valid IPv6/) } it { is_expected.to run.with_params('::1', {}).and_raise_error(Puppet::ParseError, /is not a string/) } it { is_expected.to run.with_params('::1', true).and_raise_error(Puppet::ParseError, /is not a string/) } -- cgit v1.2.3 From 2f463600c2c0b6ac95ec71d3e5b17d1b2abdcd22 Mon Sep 17 00:00:00 2001 From: Paula McMaw Date: Fri, 3 Mar 2017 15:25:53 +0000 Subject: (FM-6063) - Unit tests for high effort functions --- spec/functions/concat_spec.rb | 5 ++++- spec/functions/defined_with_params_spec.rb | 5 +++++ spec/functions/dig44_spec.rb | 26 ++++++++++++++++++++++++++ spec/functions/dos2unix_spec.rb | 17 ++++++++++++----- spec/functions/ensure_packages_spec.rb | 7 +++++++ spec/functions/getparam_spec.rb | 8 ++++++++ spec/functions/is_mac_address_spec.rb | 6 ++++++ spec/functions/keys_spec.rb | 5 +++++ spec/functions/load_module_metadata_spec.rb | 10 ++++++++++ spec/functions/loadjson_spec.rb | 6 ++++-- spec/functions/loadyaml_spec.rb | 4 +++- spec/functions/parsejson_spec.rb | 11 ++++++++--- spec/functions/parseyaml_spec.rb | 11 ++++++++--- spec/functions/range_spec.rb | 8 ++++++++ spec/functions/seeded_rand_spec.rb | 5 +++++ spec/functions/squeeze_spec.rb | 6 ++++++ 16 files changed, 125 insertions(+), 15 deletions(-) (limited to 'spec/functions') diff --git a/spec/functions/concat_spec.rb b/spec/functions/concat_spec.rb index 0e67a60..6ab1b6e 100755 --- a/spec/functions/concat_spec.rb +++ b/spec/functions/concat_spec.rb @@ -11,8 +11,11 @@ describe 'concat' do it { is_expected.to run.with_params(['1','2','3'],[['4','5'],'6']).and_return(['1','2','3',['4','5'],'6']) } it { is_expected.to run.with_params(['1','2'],['3','4'],['5','6']).and_return(['1','2','3','4','5','6']) } it { is_expected.to run.with_params(['1','2'],'3','4',['5','6']).and_return(['1','2','3','4','5','6']) } + +context 'should run with UTF8 and double byte characters' do it { is_expected.to run.with_params([{"a" => "b"}], {"c" => "d", "e" => "f"}).and_return([{"a" => "b"}, {"c" => "d", "e" => "f"}]) } - it { is_expected.to run.with_params(['ấ','β','c'],['đ','ể','ƒ']).and_return(['ấ','β','c','đ','ể','ƒ']) } + it { is_expected.to run.with_params(['ấ','β','©'],['đ','ể','文字列']).and_return(['ấ','β','©','đ','ể','文字列']) } +end it "should leave the original array intact" do argument1 = ['1','2','3'] diff --git a/spec/functions/defined_with_params_spec.rb b/spec/functions/defined_with_params_spec.rb index e2f3abe..a0db0b7 100755 --- a/spec/functions/defined_with_params_spec.rb +++ b/spec/functions/defined_with_params_spec.rb @@ -11,6 +11,11 @@ describe 'defined_with_params' do it { is_expected.to run.with_params('User[dan]', {}).and_return(true) } it { is_expected.to run.with_params('User[bob]', {}).and_return(false) } it { is_expected.to run.with_params('User[dan]', {'foo' => 'bar'}).and_return(false) } + + context 'should run with UTF8 and double byte characters' do + it { is_expected.to run.with_params('User[ĵĭмოү]', {}).and_return(false) } + it { is_expected.to run.with_params('User[ポーラ]', {}).and_return(false) } + end end describe 'when compared against a resource with attributes' do diff --git a/spec/functions/dig44_spec.rb b/spec/functions/dig44_spec.rb index 4f7408d..a7b8a3d 100644 --- a/spec/functions/dig44_spec.rb +++ b/spec/functions/dig44_spec.rb @@ -25,6 +25,18 @@ describe 'dig44' do } end + let(:utf8_data) do + { + 'ẵ' => { + 'в' => [ + '©', + 'ĝ', + 'に', + ] + } + } + end + context 'single values' do it 'should exist' do is_expected.not_to be_nil @@ -100,6 +112,20 @@ describe 'dig44' do it 'should return "nil" if value is not found and no default value is provided' do is_expected.to run.with_params(data, %w(a 1)).and_return(nil) end + end + + context 'Internationalization (i18N) values' do + + it 'should be able to return a unicode character' do + is_expected.to run.with_params(utf8_data, ['ẵ', 'в', 0]).and_return('©') + end + it 'should be able to return a utf8 character' do + is_expected.to run.with_params(utf8_data, ['ẵ', 'в', 1]).and_return('ĝ') + end + + it 'should be able to return a double byte character' do + is_expected.to run.with_params(utf8_data, ['ẵ', 'в', 2]).and_return('に') + end end end diff --git a/spec/functions/dos2unix_spec.rb b/spec/functions/dos2unix_spec.rb index 9c84703..97abae7 100644 --- a/spec/functions/dos2unix_spec.rb +++ b/spec/functions/dos2unix_spec.rb @@ -29,12 +29,19 @@ describe 'dos2unix' do end end - context 'Converting from unix to unix format' do - sample_text = "Hello\nWorld\n" - desired_output = "Hello\nWorld\n" + context 'Internationalization (i18N) values' do + sample_text_utf8 = "Ħ℮ļłǿ\r\nשׁөŕłđ\r\n" + desired_output_utf8 = "Ħ℮ļłǿ\nשׁөŕłđ\n" - it 'should output unix format' do - should run.with_params(sample_text).and_return(desired_output) + sample_text_doublebyte = "こんにちは\r\n世界\r\n" + desired_output_doublebyte = "こんにちは\n世界\n" + + it 'should output uft8 string' do + should run.with_params(sample_text_utf8).and_return(desired_output_utf8) + end + + it 'should output double byte string' do + should run.with_params(sample_text_doublebyte).and_return(desired_output_doublebyte) end end end diff --git a/spec/functions/ensure_packages_spec.rb b/spec/functions/ensure_packages_spec.rb index 5d97684..6f94d72 100755 --- a/spec/functions/ensure_packages_spec.rb +++ b/spec/functions/ensure_packages_spec.rb @@ -36,9 +36,16 @@ describe 'ensure_packages' do context 'given hash of packages' do before { subject.call([{"foo" => { "provider" => "rpm" }, "bar" => { "provider" => "gem" }}, { "ensure" => "present"}]) } + before { subject.call([{"パッケージ" => { "ensure" => "absent"}}]) } + before { subject.call([{"ρǻ¢κầģẻ" => { "ensure" => "absent"}}]) } # this lambda is required due to strangeness within rspec-puppet's expectation handling it { expect(lambda { catalogue }).to contain_package('foo').with({'provider' => 'rpm', 'ensure' => 'present'}) } it { expect(lambda { catalogue }).to contain_package('bar').with({'provider' => 'gem', 'ensure' => 'present'}) } + + context 'should run with UTF8 and double byte characters' do + it { expect(lambda { catalogue }).to contain_package('パッケージ').with({'ensure' => 'absent'}) } + it { expect(lambda { catalogue }).to contain_package('ρǻ¢κầģẻ').with({'ensure' => 'absent'}) } + end end end diff --git a/spec/functions/getparam_spec.rb b/spec/functions/getparam_spec.rb index e4ef9e6..522ed3b 100755 --- a/spec/functions/getparam_spec.rb +++ b/spec/functions/getparam_spec.rb @@ -24,4 +24,12 @@ describe 'getparam' do it { is_expected.to run.with_params('User[one]', 'shell').and_return('/bin/sh') } it { is_expected.to run.with_params('User[one]', 'managehome').and_return(false) } end + + describe 'when compared against a user resource with UTF8 and double byte params' do + let(:pre_condition) { 'user { ["三", "ƒốưř"]: ensure => present }' } + + it { is_expected.to run.with_params('User[三]', 'ensure').and_return('present') } + it { is_expected.to run.with_params('User[ƒốưř]', 'ensure').and_return('present') } + + end end diff --git a/spec/functions/is_mac_address_spec.rb b/spec/functions/is_mac_address_spec.rb index 5f76a91..c1e33b8 100755 --- a/spec/functions/is_mac_address_spec.rb +++ b/spec/functions/is_mac_address_spec.rb @@ -9,6 +9,12 @@ describe 'is_mac_address' do it { is_expected.to run.with_params('00:00:00:00:00:0g').and_return(false) } it { is_expected.to run.with_params('').and_return(false) } it { is_expected.to run.with_params('one').and_return(false) } + + context 'function can handle UTF8 and double byte characters' do + it { is_expected.to run.with_params('ƒốưř').and_return(false) } + it { is_expected.to run.with_params('三+').and_return(false) } + end + it { pending "should properly typecheck its arguments" is_expected.to run.with_params(1).and_return(false) diff --git a/spec/functions/keys_spec.rb b/spec/functions/keys_spec.rb index 2e009dc..fc7d6d8 100755 --- a/spec/functions/keys_spec.rb +++ b/spec/functions/keys_spec.rb @@ -16,4 +16,9 @@ describe 'keys' do result = subject.call([{ 'key1' => 'value1', 'key2' => 'value2' }]) expect(result).to match_array(['key1', 'key2']) end + + it 'should run with UTF8 and double byte characters' do + result = subject.call([{ 'ҝểү' => '√ẳŀμệ', 'キー' => '値' }]) + expect(result).to match_array(['ҝểү', 'キー']) + end end diff --git a/spec/functions/load_module_metadata_spec.rb b/spec/functions/load_module_metadata_spec.rb index 841cd7d..9496fcb 100755 --- a/spec/functions/load_module_metadata_spec.rb +++ b/spec/functions/load_module_metadata_spec.rb @@ -10,6 +10,15 @@ describe 'load_module_metadata' do allow(File).to receive(:read).with(/\/(stdlib|test)\/metadata.json/, {:encoding=>"utf-8"}).and_return('{"name": "puppetlabs-stdlib"}') allow(File).to receive(:read).with(/\/(stdlib|test)\/metadata.json/).and_return('{"name": "puppetlabs-stdlib"}') end + + context "when calling with valid utf8 and double byte character arguments" do + before :each do + allow(File).to receive(:read).with(/\/(stdlib|test)\/metadata.json/, {:encoding=>"utf-8"}).and_return('{"ĭďèʼnţĩƒіểя": "ċơņťęאּť ỡƒ ţħíš - +この文字"}') + allow(File).to receive(:read).with(/\/(stdlib|test)\/metadata.json/).and_return('{"ĭďèʼnţĩƒіểя": "ċơņťęאּť ỡƒ ţħíš - +この文字"}') + end + it "should json parse the file" do if Puppet::Util::Platform.windows? allow(scope).to receive(:function_get_module_path).with(['science']).and_return('C:/path/to/module/') @@ -47,5 +56,6 @@ describe 'load_module_metadata' do result = subject.call(['science', true]) expect(result).to eq({}) end + end end end diff --git a/spec/functions/loadjson_spec.rb b/spec/functions/loadjson_spec.rb index 26125bc..dbef805 100644 --- a/spec/functions/loadjson_spec.rb +++ b/spec/functions/loadjson_spec.rb @@ -23,6 +23,8 @@ describe 'loadjson' do allow(PSON).to receive(:load).never } it { is_expected.to run.with_params(filename, {'default' => 'value'}).and_return({'default' => 'value'}) } + it { is_expected.to run.with_params(filename, {'đẽƒằưļŧ' => '٧ẵłựέ'}).and_return({'đẽƒằưļŧ' => '٧ẵłựέ'}) } + it { is_expected.to run.with_params(filename, {'デフォルト' => '値'}).and_return({'デフォルト' => '値'}) } end context 'when an existing file is specified' do @@ -33,8 +35,8 @@ describe 'loadjson' do '/tmp/doesexist' end } - let(:data) { { 'key' => 'value' } } - let(:json) { '{"key":"value"}' } + let(:data) { { 'key' => 'value', 'ķęŷ' => 'νậŀųề', 'キー' => '値'} } + let(:json) { '{"key":"value", {"ķęŷ":"νậŀųề" }, {"キー":"値" }' } before { allow(File).to receive(:exists?).with(filename).and_return(true).once allow(File).to receive(:read).with(filename).and_return(json).once diff --git a/spec/functions/loadyaml_spec.rb b/spec/functions/loadyaml_spec.rb index 9f16a1a..e9428e3 100755 --- a/spec/functions/loadyaml_spec.rb +++ b/spec/functions/loadyaml_spec.rb @@ -11,11 +11,13 @@ describe 'loadyaml' do YAML.expects(:load_file).never } it { is_expected.to run.with_params(filename, {'default' => 'value'}).and_return({'default' => 'value'}) } + it { is_expected.to run.with_params(filename, {'đẽƒằưļŧ' => '٧ẵłựέ'}).and_return({'đẽƒằưļŧ' => '٧ẵłựέ'}) } + it { is_expected.to run.with_params(filename, {'デフォルト' => '値'}).and_return({'デフォルト' => '値'}) } end context 'when an existing file is specified' do let(:filename) { '/tmp/doesexist' } - let(:data) { { 'key' => 'value' } } + let(:data) { { 'key' => 'value', 'ķęŷ' => 'νậŀųề', 'キー' => '値'} } before { File.expects(:exists?).with(filename).returns(true).once YAML.expects(:load_file).with(filename).returns(data).once diff --git a/spec/functions/parsejson_spec.rb b/spec/functions/parsejson_spec.rb index a01f1f6..7b07e49 100755 --- a/spec/functions/parsejson_spec.rb +++ b/spec/functions/parsejson_spec.rb @@ -12,12 +12,12 @@ describe 'parsejson' do context 'with correct JSON data' do - it 'should be able to parse a JSON data with a Hash' do + it 'should be able to parse JSON data with a Hash' do is_expected.to run.with_params('{"a":"1","b":"2"}'). and_return({'a'=>'1', 'b'=>'2'}) end - it 'should be able to parse a JSON data with an Array' do + it 'should be able to parse JSON data with an Array' do is_expected.to run.with_params('["a","b","c"]'). and_return(['a', 'b', 'c']) end @@ -29,11 +29,16 @@ describe 'parsejson' do and_return({}) end - it 'should be able to parse a JSON data with a mixed structure' do + it 'should be able to parse JSON data with a mixed structure' do is_expected.to run.with_params('{"a":"1","b":2,"c":{"d":[true,false]}}'). and_return({'a' =>'1', 'b' => 2, 'c' => { 'd' => [true, false] } }) end + it 'should be able to parse JSON data with a UTF8 and double byte characters' do + is_expected.to run.with_params('{"×":"これ","ý":"記号","です":{"©":["Á","ß"]}}'). + and_return({'×' =>'これ', 'ý' => '記号', 'です' => { '©' => ['Á', 'ß'] } }) + end + it 'should not return the default value if the data was parsed correctly' do is_expected.to run.with_params('{"a":"1"}', 'default_value'). and_return({'a' => '1'}) diff --git a/spec/functions/parseyaml_spec.rb b/spec/functions/parseyaml_spec.rb index fa947ca..c2a138c 100755 --- a/spec/functions/parseyaml_spec.rb +++ b/spec/functions/parseyaml_spec.rb @@ -18,21 +18,26 @@ describe 'parseyaml' do and_return('just a string') end - it 'should be able to parse a YAML data with a Hash' do + it 'should be able to parse YAML data with a Hash' do is_expected.to run.with_params("---\na: '1'\nb: '2'\n"). and_return({'a' => '1', 'b' => '2'}) end - it 'should be able to parse a YAML data with an Array' do + it 'should be able to parse YAML data with an Array' do is_expected.to run.with_params("---\n- a\n- b\n- c\n"). and_return(['a', 'b', 'c']) end - it 'should be able to parse a YAML data with a mixed structure' do + it 'should be able to parse YAML data with a mixed structure' do is_expected.to run.with_params("---\na: '1'\nb: 2\nc:\n d:\n - :a\n - true\n - false\n"). and_return({'a' => '1', 'b' => 2, 'c' => {'d' => [:a, true, false]}}) end + it 'should be able to parse YAML data with a UTF8 and double byte characters' do + is_expected.to run.with_params("---\na: ×\nこれ: 記号\nです:\n ©:\n - Á\n - ß\n"). + and_return({"a"=>"×", "これ"=>"記号", "です"=>{"©"=>["Á", "ß"]} }) + end + it 'should not return the default value if the data was parsed correctly' do is_expected.to run.with_params("---\na: '1'\n", 'default_value'). and_return({'a' => '1'}) diff --git a/spec/functions/range_spec.rb b/spec/functions/range_spec.rb index 492cad4..ca569d5 100755 --- a/spec/functions/range_spec.rb +++ b/spec/functions/range_spec.rb @@ -79,6 +79,14 @@ describe 'range' do it { is_expected.to run.with_params('01', '04').and_return([1, 2, 3, 4]) } end + context 'with prefixed numbers as utf8 strings as bounds' do + it { is_expected.to run.with_params('ħөŝŧ01', 'ħөŝŧ04').and_return(['ħөŝŧ01', 'ħөŝŧ02', 'ħөŝŧ03', 'ħөŝŧ04']) } + end + + context 'with prefixed numbers as double byte character strings as bounds' do + it { is_expected.to run.with_params('ホスト01', 'ホスト04').and_return(['ホスト01', 'ホスト02', 'ホスト03', 'ホスト04']) } + end + context 'with dash-range syntax' do it { is_expected.to run.with_params('4-1').and_return([]) } it { is_expected.to run.with_params('1-1').and_return([1]) } diff --git a/spec/functions/seeded_rand_spec.rb b/spec/functions/seeded_rand_spec.rb index 38e134e..ac108f4 100644 --- a/spec/functions/seeded_rand_spec.rb +++ b/spec/functions/seeded_rand_spec.rb @@ -50,4 +50,9 @@ describe 'seeded_rand' do scope.function_seeded_rand([max, seed]) end + + context 'should run with UTF8 and double byte characters' do + it { is_expected.to run.with_params(1000, 'ǿňè')} + it { is_expected.to run.with_params(1000, '文字列')} + end end diff --git a/spec/functions/squeeze_spec.rb b/spec/functions/squeeze_spec.rb index 7f09c30..b267d9a 100755 --- a/spec/functions/squeeze_spec.rb +++ b/spec/functions/squeeze_spec.rb @@ -16,6 +16,12 @@ describe 'squeeze' do it { is_expected.to run.with_params('aaaaaaaaabbbbbbbbbbcccccccccc', 'b-c').and_return('aaaaaaaaabc') } end + context 'should run with UTF8 and double byte characters' do + it { is_expected.to run.with_params('ậậậậậậậậậậậậậậậậậậậậ').and_return('ậ') } + it { is_expected.to run.with_params('語語語語語語語', '語').and_return('語') } + it { is_expected.to run.with_params('ậậậậậậậậậậậậậậậậậ語語語語©©©©©', '©').and_return('ậậậậậậậậậậậậậậậậậ語語語語©') } + end + context 'when squeezing values in an array' do it { is_expected.to run \ -- cgit v1.2.3 From 318dcfaec6ba6d0e4af1e32e55ea20b721679537 Mon Sep 17 00:00:00 2001 From: Dominic Cleal Date: Tue, 14 Mar 2017 11:16:07 +0000 Subject: (MODULES-4528) Use versioncmp to check Puppet version for 4.10.x compat `Puppet.version.to_f` on Puppet 4.10.0 will evaluate to `4.1`, causing test and behavioural changes when conditionals check that the version is equal or greater than versions such as `4.3`. Version comparisons that are vulnerable to this have been changed to use Puppet's versioncmp implementation, while most others only check for for major version boundaries which is safe. --- spec/functions/deprecation_spec.rb | 2 +- spec/functions/ensure_resource_spec.rb | 2 +- spec/functions/validate_legacy_spec.rb | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) (limited to 'spec/functions') diff --git a/spec/functions/deprecation_spec.rb b/spec/functions/deprecation_spec.rb index 8a65b69..bde4e89 100644 --- a/spec/functions/deprecation_spec.rb +++ b/spec/functions/deprecation_spec.rb @@ -1,6 +1,6 @@ require 'spec_helper' -if Puppet.version.to_f >= 4.5 +if Puppet::Util::Package.versioncmp(Puppet.version, '4.5.0') >= 0 describe 'deprecation' do before(:each) { # this is to reset the strict variable to default diff --git a/spec/functions/ensure_resource_spec.rb b/spec/functions/ensure_resource_spec.rb index fddc4c4..5366205 100755 --- a/spec/functions/ensure_resource_spec.rb +++ b/spec/functions/ensure_resource_spec.rb @@ -4,7 +4,7 @@ describe 'ensure_resource' do it { is_expected.not_to eq(nil) } it { is_expected.to run.with_params().and_raise_error(ArgumentError, /Must specify a type/) } it { is_expected.to run.with_params('type').and_raise_error(ArgumentError, /Must specify a title/) } - if Puppet.version.to_f >= 4.6 + if Puppet::Util::Package.versioncmp(Puppet.version, '4.6.0') >= 0 it { is_expected.to run.with_params('type', 'title', {}, 'extras').and_raise_error(ArgumentError) } else it { is_expected.to run.with_params('type', 'title', {}, 'extras').and_raise_error(Puppet::ParseError) } diff --git a/spec/functions/validate_legacy_spec.rb b/spec/functions/validate_legacy_spec.rb index 10b2aee..7b48f12 100644 --- a/spec/functions/validate_legacy_spec.rb +++ b/spec/functions/validate_legacy_spec.rb @@ -1,6 +1,6 @@ require 'spec_helper' -if Puppet.version.to_f >= 4.4 +if Puppet::Util::Package.versioncmp(Puppet.version, '4.4.0') >= 0 describe 'validate_legacy' do it { is_expected.not_to eq(nil) } it { is_expected.to run.with_params.and_raise_error(ArgumentError) } -- cgit v1.2.3 From 2d9a94ebe827d88222c46af33416ae333ae102b2 Mon Sep 17 00:00:00 2001 From: Helen Campbell Date: Mon, 13 Mar 2017 14:09:29 +0000 Subject: Addition of new length function --- spec/functions/length.rb | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100755 spec/functions/length.rb (limited to 'spec/functions') diff --git a/spec/functions/length.rb b/spec/functions/length.rb new file mode 100755 index 0000000..d1ab003 --- /dev/null +++ b/spec/functions/length.rb @@ -0,0 +1,35 @@ +require 'spec_helper' + +describe 'length' do + it { is_expected.not_to eq(nil) } + it { is_expected.to run.with_params().and_raise_error(ArgumentError, /'length' expects 1 argument, got none/) } + it { is_expected.to run.with_params([], 'extra').and_raise_error(ArgumentError, /'length' expects 1 argument, got 2/) } + it { is_expected.to run.with_params(1).and_raise_error(ArgumentError, /expects a value of type String, Array, or Hash, got Integer/) } + it { is_expected.to run.with_params(true).and_raise_error(ArgumentError, /expects a value of type String, Array, or Hash, got Boolean/) } + it { is_expected.to run.with_params('1').and_return(1) } + it { is_expected.to run.with_params('1.0').and_return(3) } + it { is_expected.to run.with_params([]).and_return(0) } + it { is_expected.to run.with_params(['a']).and_return(1) } + it { is_expected.to run.with_params(['one', 'two', 'three']).and_return(3) } + it { is_expected.to run.with_params(['one', 'two', 'three', 'four']).and_return(4) } + + it { is_expected.to run.with_params({}).and_return(0) } + it { is_expected.to run.with_params({'1' => '2'}).and_return(1) } + it { is_expected.to run.with_params({'1' => '2', '4' => '4'}).and_return(2) } + it { is_expected.to run.with_params({'€' => '@', '竹' => 'ǿňè'}).and_return(2) } + + it { is_expected.to run.with_params('').and_return(0) } + it { is_expected.to run.with_params('a').and_return(1) } + it { is_expected.to run.with_params('abc').and_return(3) } + it { is_expected.to run.with_params('abcd').and_return(4) } + it { is_expected.to run.with_params('万').and_return(1) } + it { is_expected.to run.with_params('āβćđ').and_return(4) } + + context 'when using a class extending String' do + it 'should call its size method' do + value = AlsoString.new('asdfghjkl') + value.expects(:length).returns('foo') + expect(subject).to run.with_params(value).and_return('foo') + end + end +end -- cgit v1.2.3 From c4d84d49069dc0b2bcf834f5aec93ed9f7a65bcb Mon Sep 17 00:00:00 2001 From: Hunter Haugen Date: Thu, 13 Apr 2017 16:36:59 -0700 Subject: (maint) Stdlib::Compat::Integer accepts numbers with newlines apparently --- spec/functions/is_integer_spec.rb | 3 +++ 1 file changed, 3 insertions(+) (limited to 'spec/functions') diff --git a/spec/functions/is_integer_spec.rb b/spec/functions/is_integer_spec.rb index b296830..8118ef4 100755 --- a/spec/functions/is_integer_spec.rb +++ b/spec/functions/is_integer_spec.rb @@ -11,6 +11,8 @@ describe 'is_integer' do it { is_expected.to run.with_params('3').and_return(true) } it { is_expected.to run.with_params(-3).and_return(true) } it { is_expected.to run.with_params('-3').and_return(true) } + it { is_expected.to run.with_params("123\nfoo").and_return(true) } + it { is_expected.to run.with_params("foo\n123").and_return(true) } it { is_expected.to run.with_params(3.7).and_return(false) } it { is_expected.to run.with_params('3.7').and_return(false) } @@ -24,6 +26,7 @@ describe 'is_integer' do it { is_expected.to run.with_params(true).and_return(false) } it { is_expected.to run.with_params(false).and_return(false) } it { is_expected.to run.with_params('0001234').and_return(false) } + it { is_expected.to run.with_params("foo\nbar").and_return(false) } context 'Checking for deprecation warning' do after(:all) do -- cgit v1.2.3 From 4f19c27137d6de29ae63bf73115f1e8fefd00b03 Mon Sep 17 00:00:00 2001 From: Hunter Haugen Date: Tue, 25 Apr 2017 12:08:46 -0700 Subject: (PE-20308) Pass a literal type and not a string to findresource - `defined_with_params` calls `findresource(reference.to_s)` - `findresource` is https://github.com/puppetlabs/puppet/blob/4.8.1/lib/puppet/parser/compiler.rb#L407 and points to https://github.com/puppetlabs/puppet/blob/4.8.1/lib/puppet/resource/catalog.rb#L352 - This calls `Puppet::Resource.new` with the type https://github.com/puppetlabs/puppet/blob/4.8.1/lib/puppet/resource/catalog.rb#L366 - This ends up calling `resource_type` via https://github.com/puppetlabs/puppet/blob/4.8.1/lib/puppet/resource.rb#L317-L319 and that ends up declaring the type via the autoloader api at https://github.com/puppetlabs/puppet/blob/4.8.1/lib/puppet/resource.rb#L390 - But why does the autoloader API fail to find it in the current environment? - Okay, so when the autoloader is trying to find the type, it uses the typeloader to look it up in the current environment https://github.com/puppetlabs/puppet/blob/4.8.1/lib/puppet/metatype/manager.rb#L171 - this calls `get_file` and `mark_loaded` https://github.com/puppetlabs/puppet/blob/4.8.1/lib/puppet/util/autoload.rb#L64-L67 Suggested workaround is to pass a literal type instead of a string to `findresource` to fix in stdlib, and also to fix loading/requiring of type in core puppet. This seems to affect more recent versions of puppet, so fallback to original behavior on pre-4.5 --- spec/functions/defined_with_params_spec.rb | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'spec/functions') diff --git a/spec/functions/defined_with_params_spec.rb b/spec/functions/defined_with_params_spec.rb index a0db0b7..979e25a 100755 --- a/spec/functions/defined_with_params_spec.rb +++ b/spec/functions/defined_with_params_spec.rb @@ -37,4 +37,22 @@ describe 'defined_with_params' do it { is_expected.to run.with_params('File[/tmp/a]', {}).and_return(true) } it { is_expected.to run.with_params('File[/tmp/a]', { 'ensure' => 'present', 'owner' => :undef }).and_return(true) } end + + describe 'when the reference is a' do + let :pre_condition do + 'user { "dan": }' + end + context 'reference' do + it { is_expected.to run.with_params(Puppet::Resource.new('User[dan]'), {}).and_return(true) } + end + if Puppet::Util::Package.versioncmp(Puppet.version, '4.5.0') >= 0 + context 'array' do + it 'fails' do + expect { + subject.call([['User[dan]'], {}]) + }.to raise_error ArgumentError, /not understood: 'Array'/ + end + end + end + end end -- cgit v1.2.3 From ccabfd3e1f4617a583546efaa4303bc24e53b89c Mon Sep 17 00:00:00 2001 From: Hunter Haugen Date: Wed, 26 Apr 2017 09:18:43 -0700 Subject: (PE-20308) Correct boundary for 4.5 vs 4.6 --- spec/functions/defined_with_params_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'spec/functions') diff --git a/spec/functions/defined_with_params_spec.rb b/spec/functions/defined_with_params_spec.rb index 979e25a..7118d85 100755 --- a/spec/functions/defined_with_params_spec.rb +++ b/spec/functions/defined_with_params_spec.rb @@ -45,7 +45,7 @@ describe 'defined_with_params' do context 'reference' do it { is_expected.to run.with_params(Puppet::Resource.new('User[dan]'), {}).and_return(true) } end - if Puppet::Util::Package.versioncmp(Puppet.version, '4.5.0') >= 0 + if Puppet::Util::Package.versioncmp(Puppet.version, '4.6.0') >= 0 context 'array' do it 'fails' do expect { -- cgit v1.2.3 From 9244c67206363f8e887531b164fc24cef729f3d8 Mon Sep 17 00:00:00 2001 From: Dominic Cleal Date: Thu, 27 Apr 2017 10:00:04 +0100 Subject: Test for defined_with_params() returning false for defined types defined_with_params() now returns false for defined types, causing duplicate resources when using ensure_resources(). Introduced by 4f19c27 in PE-20308. --- spec/functions/defined_with_params_spec.rb | 8 ++++++++ spec/functions/ensure_resource_spec.rb | 18 ++++++++++++++++++ 2 files changed, 26 insertions(+) (limited to 'spec/functions') diff --git a/spec/functions/defined_with_params_spec.rb b/spec/functions/defined_with_params_spec.rb index 7118d85..775fa74 100755 --- a/spec/functions/defined_with_params_spec.rb +++ b/spec/functions/defined_with_params_spec.rb @@ -55,4 +55,12 @@ describe 'defined_with_params' do end end end + + describe 'when passed a defined type' do + let :pre_condition do + 'test::deftype { "foo": }' + end + it { is_expected.to run.with_params('Test::Deftype[foo]', {}).and_return(true) } + it { is_expected.to run.with_params('Test::Deftype[bar]', {}).and_return(false) } + end end diff --git a/spec/functions/ensure_resource_spec.rb b/spec/functions/ensure_resource_spec.rb index 5366205..c847bf7 100755 --- a/spec/functions/ensure_resource_spec.rb +++ b/spec/functions/ensure_resource_spec.rb @@ -38,6 +38,13 @@ describe 'ensure_resource' do it { expect(lambda { catalogue }).to contain_user('username1').with_ensure('present') } it { expect(lambda { catalogue }).to contain_user('username1').without_gid } end + + describe 'after running ensure_resource("test::deftype", "foo", {})' do + before { subject.call(['test::deftype', 'foo', {}]) } + + # this lambda is required due to strangeness within rspec-puppet's expectation handling + it { expect(lambda { catalogue }).to contain_test__deftype('foo').without_ensure } + end end context 'given a catalog with UTF8 chars' do @@ -114,4 +121,15 @@ describe 'ensure_resource' do } end end + + context 'given a catalog with "test::deftype { foo: }"' do + let(:pre_condition) { 'test::deftype { "foo": }' } + + describe 'after running ensure_resource("test::deftype", "foo", {})' do + before { subject.call(['test::deftype', 'foo', {}]) } + + # this lambda is required due to strangeness within rspec-puppet's expectation handling + it { expect(lambda { catalogue }).to contain_test__deftype('foo').without_ensure } + end + end end -- cgit v1.2.3 From 32e5a87bb3b8c1d0fabc1e8c2687e4a750173cb5 Mon Sep 17 00:00:00 2001 From: Hunter Haugen Date: Fri, 28 Apr 2017 15:48:56 -0700 Subject: (PE-20308) Also fix defined type strings & references --- spec/functions/defined_with_params_spec.rb | 2 ++ 1 file changed, 2 insertions(+) (limited to 'spec/functions') diff --git a/spec/functions/defined_with_params_spec.rb b/spec/functions/defined_with_params_spec.rb index 775fa74..491a03b 100755 --- a/spec/functions/defined_with_params_spec.rb +++ b/spec/functions/defined_with_params_spec.rb @@ -62,5 +62,7 @@ describe 'defined_with_params' do end it { is_expected.to run.with_params('Test::Deftype[foo]', {}).and_return(true) } it { is_expected.to run.with_params('Test::Deftype[bar]', {}).and_return(false) } + it { is_expected.to run.with_params(Puppet::Resource.new('Test::Deftype[foo]'), {}).and_return(true) } + it { is_expected.to run.with_params(Puppet::Resource.new('Test::Deftype[bar]'), {}).and_return(false) } end end -- cgit v1.2.3 From 51fd72ca4accb2760a364d65dfe6f9b672f68d83 Mon Sep 17 00:00:00 2001 From: Hunter Haugen Date: Fri, 28 Apr 2017 13:47:47 -0700 Subject: add tests --- spec/functions/ensure_packages_spec.rb | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'spec/functions') diff --git a/spec/functions/ensure_packages_spec.rb b/spec/functions/ensure_packages_spec.rb index 6f94d72..1f89785 100755 --- a/spec/functions/ensure_packages_spec.rb +++ b/spec/functions/ensure_packages_spec.rb @@ -34,6 +34,14 @@ describe 'ensure_packages' do end end + context 'given an empty packages array' do + let(:pre_condition) { 'notify { "hi": } -> Package <| |>; $somearray = ["vim",""]; ensure_packages($somearray)' } + + describe 'after running ensure_package(["vim", ""])' do + it { expect { catalogue }.to raise_error(Puppet::ParseError, /Empty String provided/) } + end + end + context 'given hash of packages' do before { subject.call([{"foo" => { "provider" => "rpm" }, "bar" => { "provider" => "gem" }}, { "ensure" => "present"}]) } before { subject.call([{"パッケージ" => { "ensure" => "absent"}}]) } -- cgit v1.2.3 From 085496fd19c21bf2d02b8ad871d7cab850b92b93 Mon Sep 17 00:00:00 2001 From: tphoney Date: Thu, 6 Jul 2017 12:02:58 +0100 Subject: (MODULES-5186) move test to correct location --- spec/functions/ensure_resources_spec.rb | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 spec/functions/ensure_resources_spec.rb (limited to 'spec/functions') diff --git a/spec/functions/ensure_resources_spec.rb b/spec/functions/ensure_resources_spec.rb new file mode 100644 index 0000000..aea723e --- /dev/null +++ b/spec/functions/ensure_resources_spec.rb @@ -0,0 +1,22 @@ +require 'spec_helper' + +describe 'test::ensure_resources', type: :class do + let(:params) {{ resource_type: 'user', title_hash: title_param, attributes_hash: {'ensure' => 'present'} }} + + describe 'given a title hash of multiple resources' do + + let(:title_param) { {'dan' => { 'gid' => 'mygroup', 'uid' => '600' }, 'alex' => { 'gid' => 'mygroup', 'uid' => '700'}} } + + it { is_expected.to compile } + it { is_expected.to contain_user('dan').with({ 'gid' => 'mygroup', 'uid' => '600', 'ensure' => 'present'}) } + it { is_expected.to contain_user('alex').with({ 'gid' => 'mygroup', 'uid' => '700', 'ensure' => 'present'}) } + end + + describe 'given a title hash of a single resource' do + + let(:title_param) { {'dan' => { 'gid' => 'mygroup', 'uid' => '600' }} } + + it { is_expected.to compile } + it { is_expected.to contain_user('dan').with({ 'gid' => 'mygroup', 'uid' => '600', 'ensure' => 'present'}) } + end +end -- cgit v1.2.3 From fe7ccd8b89556cc6cc1f5ea7f58b5ac2aedb23ec Mon Sep 17 00:00:00 2001 From: Frank de Jong Date: Sat, 8 Jul 2017 09:43:40 +0200 Subject: Add validate_domain_name function --- spec/functions/validate_domain_name_spec.rb | 35 +++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 spec/functions/validate_domain_name_spec.rb (limited to 'spec/functions') diff --git a/spec/functions/validate_domain_name_spec.rb b/spec/functions/validate_domain_name_spec.rb new file mode 100644 index 0000000..69fcae4 --- /dev/null +++ b/spec/functions/validate_domain_name_spec.rb @@ -0,0 +1,35 @@ +require 'spec_helper' + +describe 'validate_domain_name' do + describe 'signature validation' do + it { is_expected.not_to eq(nil) } + it { is_expected.to run.with_params().and_raise_error(Puppet::ParseError, /wrong number of arguments/i) } + end + + describe 'valid inputs' do + it { is_expected.to run.with_params('com', 'com.') } + it { is_expected.to run.with_params('x.com', 'x.com.') } + it { is_expected.to run.with_params('foo.example.com', 'foo.example.com.') } + it { is_expected.to run.with_params('2foo.example.com', '2foo.example.com.') } + it { is_expected.to run.with_params('www.2foo.example.com', 'www.2foo.example.com.') } + it { is_expected.to run.with_params('domain.tld', 'puppet.com') } + end + + describe 'invalid inputs' do + it { is_expected.to run.with_params([]).and_raise_error(Puppet::ParseError, /is not a string/) } + it { is_expected.to run.with_params({}).and_raise_error(Puppet::ParseError, /is not a string/) } + it { is_expected.to run.with_params(1).and_raise_error(Puppet::ParseError, /is not a string/) } + it { is_expected.to run.with_params(true).and_raise_error(Puppet::ParseError, /is not a string/) } + + it { is_expected.to run.with_params('foo.example.com', []).and_raise_error(Puppet::ParseError, /is not a string/) } + it { is_expected.to run.with_params('foo.example.com', {}).and_raise_error(Puppet::ParseError, /is not a string/) } + it { is_expected.to run.with_params('foo.example.com', 1).and_raise_error(Puppet::ParseError, /is not a string/) } + it { is_expected.to run.with_params('foo.example.com', true).and_raise_error(Puppet::ParseError, /is not a string/) } + + it { is_expected.to run.with_params('').and_raise_error(Puppet::ParseError, /is not a syntactically correct domain name/) } + it { is_expected.to run.with_params('invalid domain').and_raise_error(Puppet::ParseError, /is not a syntactically correct domain name/) } + it { is_expected.to run.with_params('-foo.example.com').and_raise_error(Puppet::ParseError, /is not a syntactically correct domain name/) } + it { is_expected.to run.with_params('www.example.2com').and_raise_error(Puppet::ParseError, /is not a syntactically correct domain name/) } + it { is_expected.to run.with_params('192.168.1.1').and_raise_error(Puppet::ParseError, /is not a syntactically correct domain name/) } + end +end -- cgit v1.2.3 From 2220810c4ad8ea22b2cdc58bc0b9c7392a388b01 Mon Sep 17 00:00:00 2001 From: Alexander Fisher Date: Sun, 14 May 2017 14:16:28 +0100 Subject: Fix filenames of two function spec tests The tests weren't being run. Total tests increase from 2742 to 2769. Also fix 'when using a class extending String' test. It had been failing with... ``` RuntimeError: can't modify frozen AlsoString ``` --- spec/functions/is_function_available.rb | 9 ------- spec/functions/is_function_available_spec.rb | 9 +++++++ spec/functions/length.rb | 35 ---------------------------- spec/functions/length_spec.rb | 31 ++++++++++++++++++++++++ 4 files changed, 40 insertions(+), 44 deletions(-) delete mode 100755 spec/functions/is_function_available.rb create mode 100755 spec/functions/is_function_available_spec.rb delete mode 100755 spec/functions/length.rb create mode 100755 spec/functions/length_spec.rb (limited to 'spec/functions') diff --git a/spec/functions/is_function_available.rb b/spec/functions/is_function_available.rb deleted file mode 100755 index 44f08c0..0000000 --- a/spec/functions/is_function_available.rb +++ /dev/null @@ -1,9 +0,0 @@ -require 'spec_helper' - -describe 'is_function_available' do - it { is_expected.not_to eq(nil) } - it { is_expected.to run.with_params().and_raise_error(Puppet::ParseError, /wrong number of arguments/i) } - it { is_expected.to run.with_params('one', 'two').and_raise_error(Puppet::ParseError, /wrong number of arguments/i) } - it { is_expected.to run.with_params('include').and_return(true) } - it { is_expected.to run.with_params('no_such_function').and_return(false) } -end diff --git a/spec/functions/is_function_available_spec.rb b/spec/functions/is_function_available_spec.rb new file mode 100755 index 0000000..44f08c0 --- /dev/null +++ b/spec/functions/is_function_available_spec.rb @@ -0,0 +1,9 @@ +require 'spec_helper' + +describe 'is_function_available' do + it { is_expected.not_to eq(nil) } + it { is_expected.to run.with_params().and_raise_error(Puppet::ParseError, /wrong number of arguments/i) } + it { is_expected.to run.with_params('one', 'two').and_raise_error(Puppet::ParseError, /wrong number of arguments/i) } + it { is_expected.to run.with_params('include').and_return(true) } + it { is_expected.to run.with_params('no_such_function').and_return(false) } +end diff --git a/spec/functions/length.rb b/spec/functions/length.rb deleted file mode 100755 index d1ab003..0000000 --- a/spec/functions/length.rb +++ /dev/null @@ -1,35 +0,0 @@ -require 'spec_helper' - -describe 'length' do - it { is_expected.not_to eq(nil) } - it { is_expected.to run.with_params().and_raise_error(ArgumentError, /'length' expects 1 argument, got none/) } - it { is_expected.to run.with_params([], 'extra').and_raise_error(ArgumentError, /'length' expects 1 argument, got 2/) } - it { is_expected.to run.with_params(1).and_raise_error(ArgumentError, /expects a value of type String, Array, or Hash, got Integer/) } - it { is_expected.to run.with_params(true).and_raise_error(ArgumentError, /expects a value of type String, Array, or Hash, got Boolean/) } - it { is_expected.to run.with_params('1').and_return(1) } - it { is_expected.to run.with_params('1.0').and_return(3) } - it { is_expected.to run.with_params([]).and_return(0) } - it { is_expected.to run.with_params(['a']).and_return(1) } - it { is_expected.to run.with_params(['one', 'two', 'three']).and_return(3) } - it { is_expected.to run.with_params(['one', 'two', 'three', 'four']).and_return(4) } - - it { is_expected.to run.with_params({}).and_return(0) } - it { is_expected.to run.with_params({'1' => '2'}).and_return(1) } - it { is_expected.to run.with_params({'1' => '2', '4' => '4'}).and_return(2) } - it { is_expected.to run.with_params({'€' => '@', '竹' => 'ǿňè'}).and_return(2) } - - it { is_expected.to run.with_params('').and_return(0) } - it { is_expected.to run.with_params('a').and_return(1) } - it { is_expected.to run.with_params('abc').and_return(3) } - it { is_expected.to run.with_params('abcd').and_return(4) } - it { is_expected.to run.with_params('万').and_return(1) } - it { is_expected.to run.with_params('āβćđ').and_return(4) } - - context 'when using a class extending String' do - it 'should call its size method' do - value = AlsoString.new('asdfghjkl') - value.expects(:length).returns('foo') - expect(subject).to run.with_params(value).and_return('foo') - end - end -end diff --git a/spec/functions/length_spec.rb b/spec/functions/length_spec.rb new file mode 100755 index 0000000..487cf21 --- /dev/null +++ b/spec/functions/length_spec.rb @@ -0,0 +1,31 @@ +require 'spec_helper' + +describe 'length' do + it { is_expected.not_to eq(nil) } + it { is_expected.to run.with_params().and_raise_error(ArgumentError, /'length' expects 1 argument, got none/) } + it { is_expected.to run.with_params([], 'extra').and_raise_error(ArgumentError, /'length' expects 1 argument, got 2/) } + it { is_expected.to run.with_params(1).and_raise_error(ArgumentError, /expects a value of type String, Array, or Hash, got Integer/) } + it { is_expected.to run.with_params(true).and_raise_error(ArgumentError, /expects a value of type String, Array, or Hash, got Boolean/) } + it { is_expected.to run.with_params('1').and_return(1) } + it { is_expected.to run.with_params('1.0').and_return(3) } + it { is_expected.to run.with_params([]).and_return(0) } + it { is_expected.to run.with_params(['a']).and_return(1) } + it { is_expected.to run.with_params(['one', 'two', 'three']).and_return(3) } + it { is_expected.to run.with_params(['one', 'two', 'three', 'four']).and_return(4) } + + it { is_expected.to run.with_params({}).and_return(0) } + it { is_expected.to run.with_params({'1' => '2'}).and_return(1) } + it { is_expected.to run.with_params({'1' => '2', '4' => '4'}).and_return(2) } + it { is_expected.to run.with_params({'€' => '@', '竹' => 'ǿňè'}).and_return(2) } + + it { is_expected.to run.with_params('').and_return(0) } + it { is_expected.to run.with_params('a').and_return(1) } + it { is_expected.to run.with_params('abc').and_return(3) } + it { is_expected.to run.with_params('abcd').and_return(4) } + it { is_expected.to run.with_params('万').and_return(1) } + it { is_expected.to run.with_params('āβćđ').and_return(4) } + + context 'when using a class extending String' do + it { is_expected.to run.with_params(AlsoString.new('asdfghjkl')).and_return(9) } + end +end -- cgit v1.2.3 From 715c40dc9083068598387ab67396136e87eb553d Mon Sep 17 00:00:00 2001 From: Eric Putnam Date: Tue, 11 Jul 2017 15:43:37 -0700 Subject: (MODULES-5187) fix spec tests for puppet 5 changes --- spec/functions/merge_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'spec/functions') diff --git a/spec/functions/merge_spec.rb b/spec/functions/merge_spec.rb index 7b53363..3b2e3ef 100755 --- a/spec/functions/merge_spec.rb +++ b/spec/functions/merge_spec.rb @@ -4,7 +4,7 @@ describe 'merge' do it { is_expected.not_to eq(nil) } it { is_expected.to run.with_params().and_raise_error(Puppet::ParseError, /wrong number of arguments/i) } it { is_expected.to run.with_params({}, 'two').and_raise_error(Puppet::ParseError, /unexpected argument type String/) } - it { is_expected.to run.with_params({}, 1).and_raise_error(Puppet::ParseError, /unexpected argument type Fixnum/) } + it { is_expected.to run.with_params({}, 1).and_raise_error(Puppet::ParseError, /unexpected argument type (Fixnum|Integer)/) } it { pending 'should not special case this' is_expected.to run.with_params({}).and_return({}) -- cgit v1.2.3 From 01d3004f0a6a1c662aea90edd5b1524139706c61 Mon Sep 17 00:00:00 2001 From: tphoney Date: Thu, 13 Jul 2017 16:12:08 +0100 Subject: (FM-6239) rewrite of test following std patterns --- spec/functions/ensure_resources_spec.rb | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) (limited to 'spec/functions') diff --git a/spec/functions/ensure_resources_spec.rb b/spec/functions/ensure_resources_spec.rb index aea723e..7cca671 100644 --- a/spec/functions/ensure_resources_spec.rb +++ b/spec/functions/ensure_resources_spec.rb @@ -1,22 +1,25 @@ require 'spec_helper' -describe 'test::ensure_resources', type: :class do - let(:params) {{ resource_type: 'user', title_hash: title_param, attributes_hash: {'ensure' => 'present'} }} +describe 'ensure_resources' do + it { is_expected.not_to eq(nil) } + it { is_expected.to run.with_params().and_raise_error(ArgumentError, /Must specify a type/) } + it { is_expected.to run.with_params('type').and_raise_error(ArgumentError, /Must specify a title/) } describe 'given a title hash of multiple resources' do + before { subject.call(['user', {'dan' => { 'gid' => 'mygroup', 'uid' => '600' }, 'alex' => { 'gid' => 'mygroup', 'uid' => '700'}}, {'ensure' => 'present'}]) } - let(:title_param) { {'dan' => { 'gid' => 'mygroup', 'uid' => '600' }, 'alex' => { 'gid' => 'mygroup', 'uid' => '700'}} } - - it { is_expected.to compile } - it { is_expected.to contain_user('dan').with({ 'gid' => 'mygroup', 'uid' => '600', 'ensure' => 'present'}) } - it { is_expected.to contain_user('alex').with({ 'gid' => 'mygroup', 'uid' => '700', 'ensure' => 'present'}) } + # this lambda is required due to strangeness within rspec-puppet's expectation handling + it { expect(lambda { catalogue }).to contain_user('dan').with_ensure('present') } + it { expect(lambda { catalogue }).to contain_user('alex').with_ensure('present') } + it { expect(lambda { catalogue }).to contain_user('dan').with({ 'gid' => 'mygroup', 'uid' => '600'}) } + it { expect(lambda { catalogue }).to contain_user('alex').with({ 'gid' => 'mygroup', 'uid' => '700'}) } end describe 'given a title hash of a single resource' do + before { subject.call(['user', {'dan' => { 'gid' => 'mygroup', 'uid' => '600' }}, {'ensure' => 'present'}]) } - let(:title_param) { {'dan' => { 'gid' => 'mygroup', 'uid' => '600' }} } - - it { is_expected.to compile } - it { is_expected.to contain_user('dan').with({ 'gid' => 'mygroup', 'uid' => '600', 'ensure' => 'present'}) } + # this lambda is required due to strangeness within rspec-puppet's expectation handling + it { expect(lambda { catalogue }).to contain_user('dan').with_ensure('present') } + it { expect(lambda { catalogue }).to contain_user('dan').with({ 'gid' => 'mygroup', 'uid' => '600'}) } end end -- cgit v1.2.3 From 33922a4ec7a8c204a17e0c3017eea21faa220f39 Mon Sep 17 00:00:00 2001 From: tphoney Date: Fri, 14 Jul 2017 10:14:04 +0100 Subject: FM-6239 clean up for puppet 5.tests/deprecation --- spec/functions/deep_merge_spec.rb | 2 +- spec/functions/strftime_spec.rb | 4 ++-- spec/functions/unique_spec.rb | 46 ++++++++++++++++++++------------------- 3 files changed, 27 insertions(+), 25 deletions(-) (limited to 'spec/functions') diff --git a/spec/functions/deep_merge_spec.rb b/spec/functions/deep_merge_spec.rb index c91a07e..819e025 100755 --- a/spec/functions/deep_merge_spec.rb +++ b/spec/functions/deep_merge_spec.rb @@ -4,7 +4,7 @@ describe 'deep_merge' do it { is_expected.to run.with_params().and_raise_error(Puppet::ParseError, /wrong number of arguments/i) } it { is_expected.to run.with_params({ 'key' => 'value' }).and_raise_error(Puppet::ParseError, /wrong number of arguments/i) } it { is_expected.to run.with_params({}, '2').and_raise_error(Puppet::ParseError, /unexpected argument type String/) } - it { is_expected.to run.with_params({}, 2).and_raise_error(Puppet::ParseError, /unexpected argument type Fixnum/) } + it { is_expected.to run.with_params({}, 2).and_raise_error(Puppet::ParseError, /unexpected argument/) } it { is_expected.to run.with_params({}, '').and_return({}) } it { is_expected.to run.with_params({}, {}).and_return({}) } it { is_expected.to run.with_params({}, {}, {}).and_return({}) } diff --git a/spec/functions/strftime_spec.rb b/spec/functions/strftime_spec.rb index e76774a..41cda6a 100755 --- a/spec/functions/strftime_spec.rb +++ b/spec/functions/strftime_spec.rb @@ -14,9 +14,9 @@ describe 'strftime' do expect(result.to_i).to(be > 1311953157) end - it "using %s should be lower then 1.5 trillion" do + it "using %s should be greater than 1.5 trillion" do result = scope.function_strftime(["%s"]) - expect(result.to_i).to(be < 1500000000) + expect(result.to_i).to(be > 1500000000) end it "should return a date when given %Y-%m-%d" do diff --git a/spec/functions/unique_spec.rb b/spec/functions/unique_spec.rb index 7955acb..76932ec 100755 --- a/spec/functions/unique_spec.rb +++ b/spec/functions/unique_spec.rb @@ -1,29 +1,31 @@ require 'spec_helper' describe 'unique' do - describe 'signature validation' do - it { is_expected.not_to eq(nil) } - it { is_expected.to run.with_params().and_raise_error(Puppet::ParseError, /wrong number of arguments/i) } - it { - pending("Current implementation ignores parameters after the first.") - is_expected.to run.with_params([], 'extra').and_raise_error(Puppet::ParseError, /wrong number of arguments/i) - } - it { is_expected.to run.with_params({}).and_raise_error(Puppet::ParseError, /Requires either array or string to work/) } - it { is_expected.to run.with_params(1).and_raise_error(Puppet::ParseError, /Requires either array or string to work/) } - it { is_expected.to run.with_params(true).and_raise_error(Puppet::ParseError, /Requires either array or string to work/) } - end + if Puppet.version.to_f < 5.0 + describe 'signature validation' do + it { is_expected.not_to eq(nil) } + it { is_expected.to run.with_params().and_raise_error(Puppet::ParseError, /wrong number of arguments/i) } + it { + pending("Current implementation ignores parameters after the first.") + is_expected.to run.with_params([], 'extra').and_raise_error(Puppet::ParseError, /wrong number of arguments/i) + } + it { is_expected.to run.with_params({}).and_raise_error(Puppet::ParseError, /Requires either array or string to work/) } + it { is_expected.to run.with_params(1).and_raise_error(Puppet::ParseError, /Requires either array or string to work/) } + it { is_expected.to run.with_params(true).and_raise_error(Puppet::ParseError, /Requires either array or string to work/) } + end - context 'when called with an array' do - it { is_expected.to run.with_params([]).and_return([]) } - it { is_expected.to run.with_params(['a']).and_return(['a']) } - it { is_expected.to run.with_params(['a', 'b', 'a']).and_return(['a', 'b']) } - it { is_expected.to run.with_params(['ã', 'ъ', 'ã']).and_return(['ã', 'ъ']) } - end + context 'when called with an array' do + it { is_expected.to run.with_params([]).and_return([]) } + it { is_expected.to run.with_params(['a']).and_return(['a']) } + it { is_expected.to run.with_params(['a', 'b', 'a']).and_return(['a', 'b']) } + it { is_expected.to run.with_params(['ã', 'ъ', 'ã']).and_return(['ã', 'ъ']) } + end - context 'when called with a string' do - it { is_expected.to run.with_params('').and_return('') } - it { is_expected.to run.with_params('a').and_return('a') } - it { is_expected.to run.with_params('aaba').and_return('ab') } - it { is_expected.to run.with_params('ããъã').and_return('ãъ') } + context 'when called with a string' do + it { is_expected.to run.with_params('').and_return('') } + it { is_expected.to run.with_params('a').and_return('a') } + it { is_expected.to run.with_params('aaba').and_return('ab') } + it { is_expected.to run.with_params('ããъã').and_return('ãъ') } + end end end -- cgit v1.2.3 From 42d4ea7af9197f77a3062727eb166c719ca6296a Mon Sep 17 00:00:00 2001 From: Eric Putnam Date: Fri, 7 Jul 2017 17:30:17 -0700 Subject: (MODULES-4908) adds support for sensitive data type to pw_hash Also includes a small fix to integer_spec so tests pass. --- spec/functions/pw_hash_spec.rb | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'spec/functions') diff --git a/spec/functions/pw_hash_spec.rb b/spec/functions/pw_hash_spec.rb index df5348c..9e03464 100644 --- a/spec/functions/pw_hash_spec.rb +++ b/spec/functions/pw_hash_spec.rb @@ -65,5 +65,13 @@ describe 'pw_hash' do it { is_expected.to run.with_params('password', 'sha-256', 'salt').and_return('$5$salt$Gcm6FsVtF/Qa77ZKD.iwsJlCVPY0XSMgLJL0Hnww/c1') } it { is_expected.to run.with_params('password', 'sha-512', 'salt').and_return('$6$salt$IxDD3jeSOb5eB1CX5LBsqZFVkJdido3OUILO5Ifz5iwMuTS4XMS130MTSuDDl3aCI6WouIL9AjRbLCelDCy.g.') } end + + if Puppet::Util::Package.versioncmp(Puppet.version, '4.7.0') >= 0 + describe 'when arguments are sensitive' do + it { is_expected.to run.with_params(Puppet::Pops::Types::PSensitiveType::Sensitive.new('password'), 'md5', 'salt').and_return('$1$salt$qJH7.N4xYta3aEG/dfqo/0') } + it { is_expected.to run.with_params(Puppet::Pops::Types::PSensitiveType::Sensitive.new('password'), 'md5', Puppet::Pops::Types::PSensitiveType::Sensitive.new('salt')).and_return('$1$salt$qJH7.N4xYta3aEG/dfqo/0') } + it { is_expected.to run.with_params('password', 'md5', Puppet::Pops::Types::PSensitiveType::Sensitive.new('salt')).and_return('$1$salt$qJH7.N4xYta3aEG/dfqo/0') } + end + end end end -- cgit v1.2.3 From 39ea2c0bc49d812f41dcbbed6635e25607f80970 Mon Sep 17 00:00:00 2001 From: Nick Walker Date: Tue, 28 Mar 2017 13:16:26 -0700 Subject: Add a round function to complement ceiling and floor --- spec/functions/round_spec.rb | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100755 spec/functions/round_spec.rb (limited to 'spec/functions') diff --git a/spec/functions/round_spec.rb b/spec/functions/round_spec.rb new file mode 100755 index 0000000..5aa801c --- /dev/null +++ b/spec/functions/round_spec.rb @@ -0,0 +1,11 @@ +require 'spec_helper' + +describe 'stdlib::round' do + it { is_expected.not_to eq(nil) } + it { is_expected.to run.with_params(34.3).and_return(34) } + it { is_expected.to run.with_params(-34.3).and_return(-34) } + it { is_expected.to run.with_params(34.5).and_return(35) } + it { is_expected.to run.with_params(-34.5).and_return(-35) } + it { is_expected.to run.with_params(34.7).and_return(35) } + it { is_expected.to run.with_params(-34.7).and_return(-35) } +end -- cgit v1.2.3 From 772a2d2f406b65ef65161a04455865b37a1c8456 Mon Sep 17 00:00:00 2001 From: Eric Putnam Date: Thu, 27 Jul 2017 09:24:52 -0700 Subject: (maint) move/rewrite round() as ruby function --- spec/functions/round_spec.rb | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'spec/functions') diff --git a/spec/functions/round_spec.rb b/spec/functions/round_spec.rb index 5aa801c..8b13478 100755 --- a/spec/functions/round_spec.rb +++ b/spec/functions/round_spec.rb @@ -1,6 +1,6 @@ require 'spec_helper' -describe 'stdlib::round' do +describe 'round' do it { is_expected.not_to eq(nil) } it { is_expected.to run.with_params(34.3).and_return(34) } it { is_expected.to run.with_params(-34.3).and_return(-34) } @@ -8,4 +8,7 @@ describe 'stdlib::round' do it { is_expected.to run.with_params(-34.5).and_return(-35) } it { is_expected.to run.with_params(34.7).and_return(35) } it { is_expected.to run.with_params(-34.7).and_return(-35) } + it { is_expected.to run.with_params("test").and_raise_error Puppet::ParseError } + it { is_expected.to run.with_params("test", "best").and_raise_error Puppet::ParseError } + it { is_expected.to run.with_params(3, 4).and_raise_error Puppet::ParseError } end -- cgit v1.2.3 From bd324f9d86a79eb3a7a1a781c82eede8a4a447b8 Mon Sep 17 00:00:00 2001 From: WhatsARanjit Date: Fri, 25 Aug 2017 01:11:35 +0000 Subject: Added to_json function with tests and README --- spec/functions/to_json_pretty_spec.rb | 11 +++++++++++ spec/functions/to_json_spec.rb | 19 +++++++++++++++++++ spec/functions/to_yaml_spec.rb | 17 +++++++++++++++++ 3 files changed, 47 insertions(+) create mode 100755 spec/functions/to_json_pretty_spec.rb create mode 100755 spec/functions/to_json_spec.rb create mode 100755 spec/functions/to_yaml_spec.rb (limited to 'spec/functions') diff --git a/spec/functions/to_json_pretty_spec.rb b/spec/functions/to_json_pretty_spec.rb new file mode 100755 index 0000000..abbcc2c --- /dev/null +++ b/spec/functions/to_json_pretty_spec.rb @@ -0,0 +1,11 @@ +require 'spec_helper' + +describe 'to_json_pretty' do + it { is_expected.not_to eq(nil) } + it { is_expected.to run.with_params([]).and_return("[\n\n]") } + it { is_expected.to run.with_params(['one']).and_return("[\n \"one\"\n]") } + it { is_expected.to run.with_params(['one', 'two']).and_return("[\n \"one\",\n \"two\"\n]") } + it { is_expected.to run.with_params({}).and_return("{\n}") } + it { is_expected.to run.with_params({ 'key' => 'value' }).and_return("{\n \"key\": \"value\"\n}") } + it { is_expected.to run.with_params({"one" => {"oneA" => "A","oneB" => {"oneB1" => "1","oneB2" => "2"}},"two" => ["twoA","twoB"]}).and_return("{\n \"one\": {\n \"oneA\": \"A\",\n \"oneB\": {\n \"oneB1\": \"1\",\n \"oneB2\": \"2\"\n }\n },\n \"two\": [\n \"twoA\",\n \"twoB\"\n ]\n}") } +end diff --git a/spec/functions/to_json_spec.rb b/spec/functions/to_json_spec.rb new file mode 100755 index 0000000..925523c --- /dev/null +++ b/spec/functions/to_json_spec.rb @@ -0,0 +1,19 @@ +require 'spec_helper' + +describe 'to_json' do + it { is_expected.not_to eq(nil) } + it { is_expected.to run.with_params('').and_return("\"\"") } + it { is_expected.to run.with_params(true).and_return("true") } + it { is_expected.to run.with_params('one').and_return("\"one\"") } + it { is_expected.to run.with_params([]).and_return("[]") } + it { is_expected.to run.with_params(['one']).and_return("[\"one\"]") } + it { is_expected.to run.with_params(['one', 'two']).and_return("[\"one\",\"two\"]") } + it { is_expected.to run.with_params({}).and_return("{}") } + it { is_expected.to run.with_params({ 'key' => 'value' }).and_return("{\"key\":\"value\"}") } + it { is_expected.to run.with_params({"one" => {"oneA" => "A","oneB" => {"oneB1" => "1","oneB2" => "2"}},"two" => ["twoA","twoB"]}).and_return("{\"one\":{\"oneA\":\"A\",\"oneB\":{\"oneB1\":\"1\",\"oneB2\":\"2\"}},\"two\":[\"twoA\",\"twoB\"]}") } + + it { is_expected.to run.with_params('‰').and_return('"‰"') } + it { is_expected.to run.with_params('竹').and_return('"竹"') } + it { is_expected.to run.with_params('Ü').and_return('"Ü"') } + it { is_expected.to run.with_params('∇').and_return('"∇"') } +end diff --git a/spec/functions/to_yaml_spec.rb b/spec/functions/to_yaml_spec.rb new file mode 100755 index 0000000..3f69a70 --- /dev/null +++ b/spec/functions/to_yaml_spec.rb @@ -0,0 +1,17 @@ +require 'spec_helper' + +describe 'to_yaml' do + it { is_expected.not_to eq(nil) } + it { is_expected.to run.with_params('').and_return("--- ''\n") } + it { is_expected.to run.with_params(true).and_return("--- true\n...\n") } + it { is_expected.to run.with_params('one').and_return("--- one\n...\n") } + it { is_expected.to run.with_params([]).and_return("--- []\n") } + it { is_expected.to run.with_params(['one']).and_return("---\n- one\n") } + it { is_expected.to run.with_params(['one', 'two']).and_return("---\n- one\n- two\n") } + it { is_expected.to run.with_params({}).and_return("--- {}\n") } + it { is_expected.to run.with_params({ 'key' => 'value' }).and_return("---\nkey: value\n") } + it { is_expected.to run.with_params({"one" => {"oneA" => "A","oneB" => {"oneB1" => "1","oneB2" => "2"}},"two" => ["twoA","twoB"]}).and_return("---\none:\n oneA: A\n oneB:\n oneB1: '1'\n oneB2: '2'\ntwo:\n- twoA\n- twoB\n") } + + it { is_expected.to run.with_params('‰').and_return("--- \"‰\"\n") } + it { is_expected.to run.with_params('∇').and_return("--- \"∇\"\n") } +end -- cgit v1.2.3