1 | #! /usr/bin/env ruby -S rspec
|
---|
2 | require 'spec_helper_acceptance'
|
---|
3 |
|
---|
4 | describe 'any2array function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do
|
---|
5 | describe 'success' do
|
---|
6 | it 'should create an empty array' do
|
---|
7 | pp = <<-EOS
|
---|
8 | $input = ''
|
---|
9 | $output = any2array($input)
|
---|
10 | validate_array($output)
|
---|
11 | notify { "Output: ${output}": }
|
---|
12 | EOS
|
---|
13 |
|
---|
14 | apply_manifest(pp, :catch_failures => true) do |r|
|
---|
15 | expect(r.stdout).to match(/Notice: Output: /)
|
---|
16 | end
|
---|
17 | end
|
---|
18 |
|
---|
19 | it 'should leave arrays modified' do
|
---|
20 | pp = <<-EOS
|
---|
21 | $input = ['test', 'array']
|
---|
22 | $output = any2array($input)
|
---|
23 | validate_array($output)
|
---|
24 | notify { "Output: ${output}": }
|
---|
25 | EOS
|
---|
26 |
|
---|
27 | apply_manifest(pp, :catch_failures => true) do |r|
|
---|
28 | expect(r.stdout).to match(/Notice: Output: (\[|)test(,\s|)array(\]|)/)
|
---|
29 | end
|
---|
30 | end
|
---|
31 |
|
---|
32 | it 'should turn a hash into an array' do
|
---|
33 | pp = <<-EOS
|
---|
34 | $input = {'test' => 'array'}
|
---|
35 | $output = any2array($input)
|
---|
36 |
|
---|
37 | validate_array($output)
|
---|
38 | # Check each element of the array is a plain string.
|
---|
39 | validate_string($output[0])
|
---|
40 | validate_string($output[1])
|
---|
41 | notify { "Output: ${output}": }
|
---|
42 | EOS
|
---|
43 |
|
---|
44 | apply_manifest(pp, :catch_failures => true) do |r|
|
---|
45 | expect(r.stdout).to match(/Notice: Output: (\[|)test(,\s|)array(\]|)/)
|
---|
46 | end
|
---|
47 | end
|
---|
48 | end
|
---|
49 | end
|
---|