[icinga-checkins] icinga.org: chef-icinga2/master: Add unit tests for formatting output
git at icinga.org
git at icinga.org
Tue Jul 19 18:01:46 CEST 2016
Module: chef-icinga2
Branch: master
Commit: fe5b40c7cab3446e1bb337dc26db9cdc588faaee
URL: https://git.icinga.org/?p=chef-icinga2.git;a=commit;h=fe5b40c7cab3446e1bb337dc26db9cdc588faaee
Author: Henry Finucane <henry.finucane at illumio.com>
Date: Thu Mar 24 12:21:35 2016 -0700
Add unit tests for formatting output
---
spec/unit/helper_spec.rb | 44 ++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 44 insertions(+)
diff --git a/spec/unit/helper_spec.rb b/spec/unit/helper_spec.rb
new file mode 100644
index 0000000..720e74c
--- /dev/null
+++ b/spec/unit/helper_spec.rb
@@ -0,0 +1,44 @@
+
+# This seems wrong, but I don't actually know how to do this
+require_relative '../../libraries/icinga2.rb'
+
+describe "#icinga_format" do
+ subject { icinga_format }
+
+ it "handles hashes" do
+ expect(icinga_format({:foo => :bar})).to eq('{ "foo" = "bar" }')
+ end
+
+ it "handles arrays" do
+ expect(icinga_format([1,3,5])).to eq('[ 1, 3, 5 ]')
+ end
+
+ it "handles strings" do
+ expect(icinga_format("foo")).to eq('"foo"')
+ end
+
+ it "handles floats" do
+ expect(icinga_format(1.2)).to eq('1.2')
+ end
+
+ it "handles fixnums" do
+ expect(icinga_format(10)).to eq('10')
+ end
+
+ it "handles nulls" do
+ expect(icinga_format(nil)).to eq("null")
+ end
+
+ it "handles nesting" do
+ expect(icinga_format({:foo => [:bar, {1=>2}, {1=>[:a,:b,:c]}]})).to eq('{ "foo" = [ "bar", { 1 = 2 }, { 1 = [ "a", "b", "c" ] } ] }')
+ end
+
+ it "handles arbitrary objects by stringifying them" do
+ expect(icinga_format(StandardError.new)).to eq('"#<StandardError: StandardError>"')
+ end
+
+ it "Arbitrary stringifying works with nesting" do
+ expect(icinga_format({"err"=>StandardError.new, "list"=>[{"err"=>IOError.new}]})).to eq('{ "err" = "#<StandardError: StandardError>", "list" = [ { "err" = "#<IOError: IOError>" } ] }')
+ end
+
+end
More information about the icinga-checkins
mailing list