]> gitweb.fluxo.info Git - puppet-stdlib.git/commitdiff
Adding more tests
authorHunter Haugen <hunter@puppetlabs.com>
Wed, 9 Apr 2014 21:35:34 +0000 (14:35 -0700)
committerHunter Haugen <hunter@puppetlabs.com>
Wed, 9 Apr 2014 21:35:34 +0000 (14:35 -0700)
spec/acceptance/parsejson_spec.rb [new file with mode: 0644]
spec/acceptance/parseyaml_spec.rb [new file with mode: 0644]
spec/acceptance/pick_spec.rb [new file with mode: 0644]
spec/acceptance/prefix_spec.rb [new file with mode: 0644]
spec/acceptance/reject_spec.rb [new file with mode: 0644]
spec/acceptance/size_spec.rb [new file with mode: 0644]
spec/acceptance/sort_spec.rb [new file with mode: 0644]
spec/spec_helper_acceptance.rb

diff --git a/spec/acceptance/parsejson_spec.rb b/spec/acceptance/parsejson_spec.rb
new file mode 100644 (file)
index 0000000..b2ae030
--- /dev/null
@@ -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
diff --git a/spec/acceptance/parseyaml_spec.rb b/spec/acceptance/parseyaml_spec.rb
new file mode 100644 (file)
index 0000000..01e0988
--- /dev/null
@@ -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
diff --git a/spec/acceptance/pick_spec.rb b/spec/acceptance/pick_spec.rb
new file mode 100644 (file)
index 0000000..8a768a9
--- /dev/null
@@ -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
diff --git a/spec/acceptance/prefix_spec.rb b/spec/acceptance/prefix_spec.rb
new file mode 100644 (file)
index 0000000..d7b80a8
--- /dev/null
@@ -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
diff --git a/spec/acceptance/reject_spec.rb b/spec/acceptance/reject_spec.rb
new file mode 100644 (file)
index 0000000..5333f36
--- /dev/null
@@ -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
diff --git a/spec/acceptance/size_spec.rb b/spec/acceptance/size_spec.rb
new file mode 100644 (file)
index 0000000..2aacf0b
--- /dev/null
@@ -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
diff --git a/spec/acceptance/sort_spec.rb b/spec/acceptance/sort_spec.rb
new file mode 100644 (file)
index 0000000..1868a03
--- /dev/null
@@ -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
index 4cefa752fe5f013d83c34d31bb3ad55d6b3a9656..e9d0be87c7746557b39542eac9ee9ee4c8ae579b 100644 (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?