Adding more tests

This commit is contained in:
Hunter Haugen 2014-04-09 14:35:34 -07:00
parent 8a269c6722
commit 90222959b1
8 changed files with 280 additions and 1 deletions

View file

@ -0,0 +1,33 @@
require 'spec_helper_acceptance'
describe 'parsejson function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do
describe 'success' do
it 'parses valid json' do
pp = <<-EOS
$a = '{"hunter": "washere", "tests": "passing"}'
$ao = parsejson($a)
$tests = $ao['tests']
notice(inline_template('tests are <%= @tests.inspect %>'))
EOS
apply_manifest(pp, :catch_failures => true) do |r|
expect(r.stdout).to match(/tests are "passing"/)
end
end
end
describe 'failure' do
it 'raises error on incorrect json' do
pp = <<-EOS
$a = '{"hunter": "washere", "tests": "passing",}'
$ao = parsejson($a)
notice(inline_template('a is <%= @ao.inspect %>'))
EOS
apply_manifest(pp, :expect_failures => true) do |r|
expect(r.stderr).to match(/expected next name/)
end
end
it 'raises error on incorrect number of arguments'
end
end

View file

@ -0,0 +1,34 @@
require 'spec_helper_acceptance'
describe 'parseyaml function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do
describe 'success' do
it 'parses valid yaml' do
pp = <<-EOS
$a = "---\nhunter: washere\ntests: passing\n"
$o = parseyaml($a)
$tests = $o['tests']
notice(inline_template('tests are <%= @tests.inspect %>'))
EOS
apply_manifest(pp, :catch_failures => true) do |r|
expect(r.stdout).to match(/tests are "passing"/)
end
end
end
describe 'failure' do
it 'raises error on incorrect yaml' do
pp = <<-EOS
$a = "---\nhunter: washere\ntests: passing\n:"
$o = parseyaml($a)
$tests = $o['tests']
notice(inline_template('tests are <%= @tests.inspect %>'))
EOS
apply_manifest(pp, :expect_failures => true) do |r|
expect(r.stderr).to match(/syntax error/)
end
end
it 'raises error on incorrect number of arguments'
end
end

View file

@ -0,0 +1,43 @@
require 'spec_helper_acceptance'
describe 'pick function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do
describe 'success' do
it 'picks a default value' do
pp = <<-EOS
$a = undef
$o = pick($a, 'default')
notice(inline_template('picked is <%= @o.inspect %>'))
EOS
apply_manifest(pp, :catch_failures => true) do |r|
expect(r.stdout).to match(/picked is "default"/)
end
end
it 'picks the first set value' do
pp = <<-EOS
$a = "something"
$b = "long"
$o = pick($a, $b, 'default')
notice(inline_template('picked is <%= @o.inspect %>'))
EOS
apply_manifest(pp, :catch_failures => true) do |r|
expect(r.stdout).to match(/picked is "something"/)
end
end
end
describe 'failure' do
it 'raises error with all undef values' do
pp = <<-EOS
$a = undef
$b = undef
$o = pick($a, $b)
notice(inline_template('picked is <%= @o.inspect %>'))
EOS
apply_manifest(pp, :expect_failures => true) do |r|
expect(r.stderr).to match(/must receive at least one non empty value/)
end
end
end
end

View file

@ -0,0 +1,41 @@
require 'spec_helper_acceptance'
describe 'prefix function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do
describe 'success' do
it 'prefixes array of values' do
pp = <<-EOS
$o = prefix(['a','b','c'],'p')
notice(inline_template('prefix is <%= @o.inspect %>'))
EOS
apply_manifest(pp, :catch_failures => true) do |r|
expect(r.stdout).to match(/prefix is \["pa", "pb", "pc"\]/)
end
end
it 'prefixs with empty array' do
pp = <<-EOS
$o = prefix([],'p')
notice(inline_template('prefix is <%= @o.inspect %>'))
EOS
apply_manifest(pp, :catch_failures => true) do |r|
expect(r.stdout).to match(/prefix is \[\]/)
end
end
it 'prefixs array of values with undef' do
pp = <<-EOS
$o = prefix(['a','b','c'], undef)
notice(inline_template('prefix is <%= @o.inspect %>'))
EOS
apply_manifest(pp, :catch_failures => true) do |r|
expect(r.stdout).to match(/prefix is \["a", "b", "c"\]/)
end
end
end
describe 'failure' do
it 'fails with no arguments'
it 'fails when first argument is not array'
it 'fails when second argument is not string'
end
end

View file

@ -0,0 +1,41 @@
require 'spec_helper_acceptance'
describe 'reject function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do
describe 'success' do
it 'rejects array of values' do
pp = <<-EOS
$o = reject(['aaa','bbb','ccc','aaaddd'], 'aaa')
notice(inline_template('reject is <%= @o.inspect %>'))
EOS
apply_manifest(pp, :catch_failures => true) do |r|
expect(r.stdout).to match(/reject is \["bbb", "ccc"\]/)
end
end
it 'rejects with empty array' do
pp = <<-EOS
$o = reject([],'aaa')
notice(inline_template('reject is <%= @o.inspect %>'))
EOS
apply_manifest(pp, :catch_failures => true) do |r|
expect(r.stdout).to match(/reject is \[\]/)
end
end
it 'rejects array of values with undef' do
pp = <<-EOS
$o = reject(['aaa','bbb','ccc','aaaddd'], undef)
notice(inline_template('reject is <%= @o.inspect %>'))
EOS
apply_manifest(pp, :catch_failures => true) do |r|
expect(r.stdout).to match(/reject is \["aaa", "bbb", "ccc", "aaaddd"\]/)
end
end
end
describe 'failure' do
it 'fails with no arguments'
it 'fails when first argument is not array'
it 'fails when second argument is not string'
end
end

View file

@ -0,0 +1,54 @@
require 'spec_helper_acceptance'
describe 'size function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do
describe 'success' do
it 'single string size' do
pp = <<-EOS
$a = 'discombobulate'
$o =size($a)
notice(inline_template('size is <%= @o.inspect %>'))
EOS
apply_manifest(pp, :catch_failures => true) do |r|
expect(r.stdout).to match(/size is 14/)
end
end
it 'with empty string' do
pp = <<-EOS
$a = ''
$o =size($a)
notice(inline_template('size is <%= @o.inspect %>'))
EOS
apply_manifest(pp, :catch_failures => true) do |r|
expect(r.stdout).to match(/size is 0/)
end
end
it 'with undef' do
pp = <<-EOS
$a = undef
$o =size($a)
notice(inline_template('size is <%= @o.inspect %>'))
EOS
apply_manifest(pp, :catch_failures => true) do |r|
expect(r.stdout).to match(/size is 0/)
end
end
it 'strings in array' do
pp = <<-EOS
$a = ['discombobulate', 'moo']
$o =size($a)
notice(inline_template('size is <%= @o.inspect %>'))
EOS
apply_manifest(pp, :catch_failures => true) do |r|
expect(r.stdout).to match(/size is 2/)
end
end
end
describe 'failure' do
it 'handles no arguments'
it 'handles non strings or arrays'
end
end

View file

@ -0,0 +1,33 @@
require 'spec_helper_acceptance'
describe 'sort function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do
describe 'success' do
it 'sorts arrays' do
pp = <<-EOS
$a = ["the","public","art","galleries"]
# Anagram: Large picture halls, I bet
$o =sort($a)
notice(inline_template('sort is <%= @o.inspect %>'))
EOS
apply_manifest(pp, :catch_failures => true) do |r|
expect(r.stdout).to match(/sort is \["art", "galleries", "public", "the"\]/)
end
end
it 'sorts strings' do
pp = <<-EOS
$a = "blowzy night-frumps vex'd jack q"
$o =sort($a)
notice(inline_template('sort is <%= @o.inspect %>'))
EOS
apply_manifest(pp, :catch_failures => true) do |r|
expect(r.stdout).to match(/sort is " '-abcdefghijklmnopqrstuvwxyz"/)
end
end
end
describe 'failure' do
it 'handles no arguments'
it 'handles non strings or arrays'
end
end

View file

@ -2,7 +2,7 @@ require 'beaker-rspec'
UNSUPPORTED_PLATFORMS = []
unless ENV['RS_PROVISION'] == 'no'
unless ENV['RS_PROVISION'] == 'no' or ENV['BEAKER_provision'] == 'no'
hosts.each do |host|
# Install Puppet
if host.is_pe?