Skip to content

Commit 890ef5c

Browse files
committed
Adding more spec coverage
1 parent 176ff3a commit 890ef5c

42 files changed

Lines changed: 1751 additions & 11 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#! /usr/bin/env ruby -S rspec
2+
require 'spec_helper_acceptance'
3+
4+
describe 'delete_values function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do
5+
describe 'success' do
6+
it 'should delete elements of the hash' do
7+
pp = <<-EOS
8+
$a = { 'a' => 'A', 'b' => 'B', 'B' => 'C', 'd' => 'B' }
9+
$b = { 'a' => 'A', 'B' => 'C' }
10+
$o = delete_values($a, 'B')
11+
if $o == $b {
12+
notify { 'output correct': }
13+
}
14+
EOS
15+
16+
apply_manifest(pp, :catch_failures => true) do |r|
17+
expect(r.stdout).to match(/Notice: output correct/)
18+
end
19+
end
20+
end
21+
describe 'failure' do
22+
it 'handles non-hash arguments'
23+
it 'handles improper argument counts'
24+
end
25+
end

spec/acceptance/difference_spec.rb

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#! /usr/bin/env ruby -S rspec
2+
require 'spec_helper_acceptance'
3+
4+
describe 'difference function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do
5+
describe 'success' do
6+
it 'returns non-duplicates in the first array' do
7+
pp = <<-EOS
8+
$a = ['a','b','c']
9+
$b = ['b','c','d']
10+
$c = ['a']
11+
$o = difference($a, $b)
12+
if $o == $c {
13+
notify { 'output correct': }
14+
}
15+
EOS
16+
17+
apply_manifest(pp, :catch_failures => true) do |r|
18+
expect(r.stdout).to match(/Notice: output correct/)
19+
end
20+
end
21+
end
22+
describe 'failure' do
23+
it 'handles non-array arguments'
24+
it 'handles improper argument counts'
25+
end
26+
end

spec/acceptance/dirname_spec.rb

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
#! /usr/bin/env ruby -S rspec
2+
require 'spec_helper_acceptance'
3+
4+
describe 'dirname function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do
5+
describe 'success' do
6+
context 'absolute path' do
7+
it 'returns the dirname' do
8+
pp = <<-EOS
9+
$a = '/path/to/a/file.txt'
10+
$b = '/path/to/a'
11+
$o = dirname($a)
12+
if $o == $b {
13+
notify { 'output correct': }
14+
}
15+
EOS
16+
17+
apply_manifest(pp, :catch_failures => true) do |r|
18+
expect(r.stdout).to match(/Notice: output correct/)
19+
end
20+
end
21+
end
22+
context 'relative path' do
23+
it 'returns the dirname' do
24+
pp = <<-EOS
25+
$a = 'path/to/a/file.txt'
26+
$b = 'path/to/a'
27+
$o = dirname($a)
28+
if $o == $b {
29+
notify { 'output correct': }
30+
}
31+
EOS
32+
33+
apply_manifest(pp, :catch_failures => true) do |r|
34+
expect(r.stdout).to match(/Notice: output correct/)
35+
end
36+
end
37+
end
38+
end
39+
describe 'failure' do
40+
it 'handles improper argument counts'
41+
end
42+
end

spec/acceptance/downcase_spec.rb

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#! /usr/bin/env ruby -S rspec
2+
require 'spec_helper_acceptance'
3+
4+
describe 'downcase function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do
5+
describe 'success' do
6+
it 'returns the downcase' do
7+
pp = <<-EOS
8+
$a = 'AOEU'
9+
$b = 'aoeu'
10+
$o = downcase($a)
11+
if $o == $b {
12+
notify { 'output correct': }
13+
}
14+
EOS
15+
16+
apply_manifest(pp, :catch_failures => true) do |r|
17+
expect(r.stdout).to match(/Notice: output correct/)
18+
end
19+
end
20+
it 'doesn\'t affect lowercase words' do
21+
pp = <<-EOS
22+
$a = 'aoeu aoeu'
23+
$b = 'aoeu aoeu'
24+
$o = downcase($a)
25+
if $o == $b {
26+
notify { 'output correct': }
27+
}
28+
EOS
29+
30+
apply_manifest(pp, :catch_failures => true) do |r|
31+
expect(r.stdout).to match(/Notice: output correct/)
32+
end
33+
end
34+
end
35+
describe 'failure' do
36+
it 'handles improper argument counts'
37+
it 'handles non-strings'
38+
end
39+
end

spec/acceptance/empty_spec.rb

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#! /usr/bin/env ruby -S rspec
2+
require 'spec_helper_acceptance'
3+
4+
describe 'empty function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do
5+
describe 'success' do
6+
it 'recognizes empty strings' do
7+
pp = <<-EOS
8+
$a = ''
9+
$b = true
10+
$o = empty($a)
11+
if $o == $b {
12+
notify { 'output correct': }
13+
}
14+
EOS
15+
16+
apply_manifest(pp, :catch_failures => true) do |r|
17+
expect(r.stdout).to match(/Notice: output correct/)
18+
end
19+
end
20+
it 'recognizes non-empty strings' do
21+
pp = <<-EOS
22+
$a = 'aoeu'
23+
$b = false
24+
$o = empty($a)
25+
if $o == $b {
26+
notify { 'output correct': }
27+
}
28+
EOS
29+
30+
apply_manifest(pp, :catch_failures => true) do |r|
31+
expect(r.stdout).to match(/Notice: output correct/)
32+
end
33+
end
34+
end
35+
describe 'failure' do
36+
it 'handles improper argument counts'
37+
it 'handles non-strings'
38+
end
39+
end
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#! /usr/bin/env ruby -S rspec
2+
require 'spec_helper_acceptance'
3+
4+
describe 'ensure_packages function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do
5+
describe 'success' do
6+
it 'ensure_packages a package' do
7+
apply_manifest('package { "zsh": ensure => absent, }')
8+
pp = <<-EOS
9+
$a = "zsh"
10+
ensure_packages($a)
11+
EOS
12+
13+
apply_manifest(pp, :expect_changes => true) do |r|
14+
expect(r.stdout).to match(/Package\[zsh\]\/ensure: created/)
15+
end
16+
end
17+
it 'ensures a package already declared'
18+
it 'takes defaults arguments'
19+
end
20+
describe 'failure' do
21+
it 'handles no arguments'
22+
it 'handles non strings'
23+
end
24+
end
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#! /usr/bin/env ruby -S rspec
2+
require 'spec_helper_acceptance'
3+
4+
describe 'ensure_resource function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do
5+
describe 'success' do
6+
it 'ensure_resource a package' do
7+
apply_manifest('package { "zsh": ensure => absent, }')
8+
pp = <<-EOS
9+
$a = "zsh"
10+
ensure_resource('package', $a)
11+
EOS
12+
13+
apply_manifest(pp, :expect_changes => true) do |r|
14+
expect(r.stdout).to match(/Package\[zsh\]\/ensure: created/)
15+
end
16+
end
17+
it 'ensures a resource already declared'
18+
it 'takes defaults arguments'
19+
end
20+
describe 'failure' do
21+
it 'handles no arguments'
22+
it 'handles non strings'
23+
end
24+
end

spec/acceptance/flatten_spec.rb

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#! /usr/bin/env ruby -S rspec
2+
require 'spec_helper_acceptance'
3+
4+
describe 'flatten function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do
5+
describe 'success' do
6+
it 'flattens arrays' do
7+
pp = <<-EOS
8+
$a = ["a","b",["c",["d","e"],"f","g"]]
9+
$b = ["a","b","c","d","e","f","g"]
10+
$o = flatten($a)
11+
if $o == $b {
12+
notify { 'output correct': }
13+
}
14+
EOS
15+
16+
apply_manifest(pp, :catch_failures => true) do |r|
17+
expect(r.stdout).to match(/Notice: output correct/)
18+
end
19+
end
20+
it 'does not affect flat arrays' do
21+
pp = <<-EOS
22+
$a = ["a","b","c","d","e","f","g"]
23+
$b = ["a","b","c","d","e","f","g"]
24+
$o = flatten($a)
25+
if $o == $b {
26+
notify { 'output correct': }
27+
}
28+
EOS
29+
30+
apply_manifest(pp, :catch_failures => true) do |r|
31+
expect(r.stdout).to match(/Notice: output correct/)
32+
end
33+
end
34+
end
35+
describe 'failure' do
36+
it 'handles improper argument counts'
37+
it 'handles non-strings'
38+
end
39+
end

spec/acceptance/floor_spec.rb

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#! /usr/bin/env ruby -S rspec
2+
require 'spec_helper_acceptance'
3+
4+
describe 'floor function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do
5+
describe 'success' do
6+
it 'floors floats' do
7+
pp = <<-EOS
8+
$a = 12.8
9+
$b = 12
10+
$o = floor($a)
11+
if $o == $b {
12+
notify { 'output correct': }
13+
}
14+
EOS
15+
16+
apply_manifest(pp, :catch_failures => true) do |r|
17+
expect(r.stdout).to match(/Notice: output correct/)
18+
end
19+
end
20+
it 'floors integers' do
21+
pp = <<-EOS
22+
$a = 7
23+
$b = 7
24+
$o = floor($a)
25+
if $o == $b {
26+
notify { 'output correct': }
27+
}
28+
EOS
29+
30+
apply_manifest(pp, :catch_failures => true) do |r|
31+
expect(r.stdout).to match(/Notice: output correct/)
32+
end
33+
end
34+
end
35+
describe 'failure' do
36+
it 'handles improper argument counts'
37+
it 'handles non-numbers'
38+
end
39+
end
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#! /usr/bin/env ruby -S rspec
2+
require 'spec_helper_acceptance'
3+
4+
describe 'fqdn_rotate function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do
5+
describe 'success' do
6+
let(:facts_d) do
7+
if fact('is_pe') == "true"
8+
'/etc/puppetlabs/facter/facts.d'
9+
else
10+
'/etc/facter/facts.d'
11+
end
12+
end
13+
after :each do
14+
shell("if [ -f #{facts_d}/fqdn.txt ] ; then rm #{facts_d}/fqdn.txt ; fi")
15+
end
16+
it 'fqdn_rotates floats' do
17+
shell("echo 'fqdn=fakehost.localdomain' > #{facts_d}/fqdn.txt")
18+
pp = <<-EOS
19+
$a = ['a','b','c','d']
20+
$o = fqdn_rotate($a)
21+
notice(inline_template('fqdn_rotate is <%= @o.inspect %>'))
22+
EOS
23+
24+
apply_manifest(pp, :catch_failures => true) do |r|
25+
expect(r.stdout).to match(/fqdn_rotate is \["c", "d", "a", "b"\]/)
26+
end
27+
end
28+
end
29+
describe 'failure' do
30+
it 'handles improper argument counts'
31+
it 'handles non-numbers'
32+
end
33+
end

0 commit comments

Comments
 (0)