summaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
authorHailee Kenney <hailee@puppet.com>2017-03-03 16:40:32 +0000
committerGitHub <noreply@github.com>2017-03-03 16:40:32 +0000
commit01b951b4966c1fe150a160fdc8f4196b6e21ee51 (patch)
tree1643609784f5b46f3ef7ff1ca1c16e08b8c24d5f /spec
parent9e28f8f80ab512efff5eba4fecbaadb4220ca01c (diff)
parent2f463600c2c0b6ac95ec71d3e5b17d1b2abdcd22 (diff)
Merge pull request #732 from pmcmaw/FM-6063-unitTests
(FM-6063) - Unit tests for high effort functions
Diffstat (limited to 'spec')
-rwxr-xr-xspec/functions/concat_spec.rb5
-rwxr-xr-xspec/functions/defined_with_params_spec.rb5
-rw-r--r--spec/functions/dig44_spec.rb26
-rw-r--r--spec/functions/dos2unix_spec.rb17
-rwxr-xr-xspec/functions/ensure_packages_spec.rb7
-rwxr-xr-xspec/functions/getparam_spec.rb8
-rwxr-xr-xspec/functions/is_mac_address_spec.rb6
-rwxr-xr-xspec/functions/keys_spec.rb5
-rwxr-xr-xspec/functions/load_module_metadata_spec.rb10
-rw-r--r--spec/functions/loadjson_spec.rb6
-rwxr-xr-xspec/functions/loadyaml_spec.rb4
-rwxr-xr-xspec/functions/parsejson_spec.rb11
-rwxr-xr-xspec/functions/parseyaml_spec.rb11
-rwxr-xr-xspec/functions/range_spec.rb8
-rw-r--r--spec/functions/seeded_rand_spec.rb5
-rwxr-xr-xspec/functions/squeeze_spec.rb6
16 files changed, 125 insertions, 15 deletions
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 \