Skip to content

Commit

Permalink
Adding more spec coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
hunner committed May 7, 2014
1 parent 176ff3a commit 890ef5c
Show file tree
Hide file tree
Showing 42 changed files with 1,751 additions and 11 deletions.
25 changes: 25 additions & 0 deletions spec/acceptance/delete_values_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#! /usr/bin/env ruby -S rspec
require 'spec_helper_acceptance'

describe 'delete_values function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do
describe 'success' do
it 'should delete elements of the hash' do
pp = <<-EOS
$a = { 'a' => 'A', 'b' => 'B', 'B' => 'C', 'd' => 'B' }
$b = { 'a' => 'A', 'B' => 'C' }
$o = delete_values($a, 'B')
if $o == $b {
notify { 'output correct': }
}
EOS

apply_manifest(pp, :catch_failures => true) do |r|
expect(r.stdout).to match(/Notice: output correct/)
end
end
end
describe 'failure' do
it 'handles non-hash arguments'
it 'handles improper argument counts'
end
end
26 changes: 26 additions & 0 deletions spec/acceptance/difference_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#! /usr/bin/env ruby -S rspec
require 'spec_helper_acceptance'

describe 'difference function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do
describe 'success' do
it 'returns non-duplicates in the first array' do
pp = <<-EOS
$a = ['a','b','c']
$b = ['b','c','d']
$c = ['a']
$o = difference($a, $b)
if $o == $c {
notify { 'output correct': }
}
EOS

apply_manifest(pp, :catch_failures => true) do |r|
expect(r.stdout).to match(/Notice: output correct/)
end
end
end
describe 'failure' do
it 'handles non-array arguments'
it 'handles improper argument counts'
end
end
42 changes: 42 additions & 0 deletions spec/acceptance/dirname_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#! /usr/bin/env ruby -S rspec
require 'spec_helper_acceptance'

describe 'dirname function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do
describe 'success' do
context 'absolute path' do
it 'returns the dirname' do
pp = <<-EOS
$a = '/path/to/a/file.txt'
$b = '/path/to/a'
$o = dirname($a)
if $o == $b {
notify { 'output correct': }
}
EOS

apply_manifest(pp, :catch_failures => true) do |r|
expect(r.stdout).to match(/Notice: output correct/)
end
end
end
context 'relative path' do
it 'returns the dirname' do
pp = <<-EOS
$a = 'path/to/a/file.txt'
$b = 'path/to/a'
$o = dirname($a)
if $o == $b {
notify { 'output correct': }
}
EOS

apply_manifest(pp, :catch_failures => true) do |r|
expect(r.stdout).to match(/Notice: output correct/)
end
end
end
end
describe 'failure' do
it 'handles improper argument counts'
end
end
39 changes: 39 additions & 0 deletions spec/acceptance/downcase_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#! /usr/bin/env ruby -S rspec
require 'spec_helper_acceptance'

describe 'downcase function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do
describe 'success' do
it 'returns the downcase' do
pp = <<-EOS
$a = 'AOEU'
$b = 'aoeu'
$o = downcase($a)
if $o == $b {
notify { 'output correct': }
}
EOS

apply_manifest(pp, :catch_failures => true) do |r|
expect(r.stdout).to match(/Notice: output correct/)
end
end
it 'doesn\'t affect lowercase words' do
pp = <<-EOS
$a = 'aoeu aoeu'
$b = 'aoeu aoeu'
$o = downcase($a)
if $o == $b {
notify { 'output correct': }
}
EOS

apply_manifest(pp, :catch_failures => true) do |r|
expect(r.stdout).to match(/Notice: output correct/)
end
end
end
describe 'failure' do
it 'handles improper argument counts'
it 'handles non-strings'
end
end
39 changes: 39 additions & 0 deletions spec/acceptance/empty_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#! /usr/bin/env ruby -S rspec
require 'spec_helper_acceptance'

describe 'empty function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do
describe 'success' do
it 'recognizes empty strings' do
pp = <<-EOS
$a = ''
$b = true
$o = empty($a)
if $o == $b {
notify { 'output correct': }
}
EOS

apply_manifest(pp, :catch_failures => true) do |r|
expect(r.stdout).to match(/Notice: output correct/)
end
end
it 'recognizes non-empty strings' do
pp = <<-EOS
$a = 'aoeu'
$b = false
$o = empty($a)
if $o == $b {
notify { 'output correct': }
}
EOS

apply_manifest(pp, :catch_failures => true) do |r|
expect(r.stdout).to match(/Notice: output correct/)
end
end
end
describe 'failure' do
it 'handles improper argument counts'
it 'handles non-strings'
end
end
24 changes: 24 additions & 0 deletions spec/acceptance/ensure_packages_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#! /usr/bin/env ruby -S rspec
require 'spec_helper_acceptance'

describe 'ensure_packages function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do
describe 'success' do
it 'ensure_packages a package' do
apply_manifest('package { "zsh": ensure => absent, }')
pp = <<-EOS
$a = "zsh"
ensure_packages($a)
EOS

apply_manifest(pp, :expect_changes => true) do |r|
expect(r.stdout).to match(/Package\[zsh\]\/ensure: created/)
end
end
it 'ensures a package already declared'
it 'takes defaults arguments'
end
describe 'failure' do
it 'handles no arguments'
it 'handles non strings'
end
end
24 changes: 24 additions & 0 deletions spec/acceptance/ensure_resource_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#! /usr/bin/env ruby -S rspec
require 'spec_helper_acceptance'

describe 'ensure_resource function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do
describe 'success' do
it 'ensure_resource a package' do
apply_manifest('package { "zsh": ensure => absent, }')
pp = <<-EOS
$a = "zsh"
ensure_resource('package', $a)
EOS

apply_manifest(pp, :expect_changes => true) do |r|
expect(r.stdout).to match(/Package\[zsh\]\/ensure: created/)
end
end
it 'ensures a resource already declared'
it 'takes defaults arguments'
end
describe 'failure' do
it 'handles no arguments'
it 'handles non strings'
end
end
39 changes: 39 additions & 0 deletions spec/acceptance/flatten_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#! /usr/bin/env ruby -S rspec
require 'spec_helper_acceptance'

describe 'flatten function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do
describe 'success' do
it 'flattens arrays' do
pp = <<-EOS
$a = ["a","b",["c",["d","e"],"f","g"]]
$b = ["a","b","c","d","e","f","g"]
$o = flatten($a)
if $o == $b {
notify { 'output correct': }
}
EOS

apply_manifest(pp, :catch_failures => true) do |r|
expect(r.stdout).to match(/Notice: output correct/)
end
end
it 'does not affect flat arrays' do
pp = <<-EOS
$a = ["a","b","c","d","e","f","g"]
$b = ["a","b","c","d","e","f","g"]
$o = flatten($a)
if $o == $b {
notify { 'output correct': }
}
EOS

apply_manifest(pp, :catch_failures => true) do |r|
expect(r.stdout).to match(/Notice: output correct/)
end
end
end
describe 'failure' do
it 'handles improper argument counts'
it 'handles non-strings'
end
end
39 changes: 39 additions & 0 deletions spec/acceptance/floor_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#! /usr/bin/env ruby -S rspec
require 'spec_helper_acceptance'

describe 'floor function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do
describe 'success' do
it 'floors floats' do
pp = <<-EOS
$a = 12.8
$b = 12
$o = floor($a)
if $o == $b {
notify { 'output correct': }
}
EOS

apply_manifest(pp, :catch_failures => true) do |r|
expect(r.stdout).to match(/Notice: output correct/)
end
end
it 'floors integers' do
pp = <<-EOS
$a = 7
$b = 7
$o = floor($a)
if $o == $b {
notify { 'output correct': }
}
EOS

apply_manifest(pp, :catch_failures => true) do |r|
expect(r.stdout).to match(/Notice: output correct/)
end
end
end
describe 'failure' do
it 'handles improper argument counts'
it 'handles non-numbers'
end
end
33 changes: 33 additions & 0 deletions spec/acceptance/fqdn_rotate_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#! /usr/bin/env ruby -S rspec
require 'spec_helper_acceptance'

describe 'fqdn_rotate function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do
describe 'success' do
let(:facts_d) do
if fact('is_pe') == "true"
'/etc/puppetlabs/facter/facts.d'
else
'/etc/facter/facts.d'
end
end
after :each do
shell("if [ -f #{facts_d}/fqdn.txt ] ; then rm #{facts_d}/fqdn.txt ; fi")
end
it 'fqdn_rotates floats' do
shell("echo 'fqdn=fakehost.localdomain' > #{facts_d}/fqdn.txt")
pp = <<-EOS
$a = ['a','b','c','d']
$o = fqdn_rotate($a)
notice(inline_template('fqdn_rotate is <%= @o.inspect %>'))
EOS

apply_manifest(pp, :catch_failures => true) do |r|
expect(r.stdout).to match(/fqdn_rotate is \["c", "d", "a", "b"\]/)
end
end
end
describe 'failure' do
it 'handles improper argument counts'
it 'handles non-numbers'
end
end
41 changes: 41 additions & 0 deletions spec/acceptance/get_module_path_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#! /usr/bin/env ruby -S rspec
require 'spec_helper_acceptance'

describe 'get_module_path function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do
describe 'success' do
it 'get_module_paths stdlib' do
pp = <<-EOS
$a = $::is_pe ? {
'true' => '/opt/puppet/share/puppet/modules/stdlib',
'false' => '/etc/puppet/modules/stdlib',
}
$o = get_module_path('stdlib')
if $o == $a {
notify { 'output correct': }
}
EOS

apply_manifest(pp, :catch_failures => true) do |r|
expect(r.stdout).to match(/Notice: output correct/)
end
end
it 'get_module_paths dne' do
pp = <<-EOS
$a = $::is_pe ? {
'true' => '/etc/puppetlabs/puppet/modules/dne',
'false' => '/etc/puppet/modules/dne',
}
$o = get_module_path('dne')
if $o == $a {
notify { 'output correct': }
}
EOS

apply_manifest(pp, :expect_failures => true)
end
end
describe 'failure' do
it 'handles improper argument counts'
it 'handles non-numbers'
end
end
Loading

0 comments on commit 890ef5c

Please sign in to comment.