X-Git-Url: https://review.fuel-infra.org/gitweb?a=blobdiff_plain;f=spec%2Funit%2Frpc%2Fhelpers_spec.rb;fp=spec%2Funit%2Frpc%2Fhelpers_spec.rb;h=f2c56ee5ebef678f4c55ec1ba742ff35a467b22e;hb=b87d2f4e68281062df1913440ca5753ae63314a9;hp=0000000000000000000000000000000000000000;hpb=ab0ea530b8ac956091f17b104ab2311336cfc250;p=packages%2Fprecise%2Fmcollective.git diff --git a/spec/unit/rpc/helpers_spec.rb b/spec/unit/rpc/helpers_spec.rb new file mode 100755 index 0000000..f2c56ee --- /dev/null +++ b/spec/unit/rpc/helpers_spec.rb @@ -0,0 +1,55 @@ +#!/usr/bin/env rspec + +require 'spec_helper' + +module MCollective + module RPC + describe Helpers do + describe "#extract_hosts_from_json" do + it "should fail for non array data" do + expect { + Helpers.extract_hosts_from_json("{}") + }.to raise_error("JSON hosts list is not an array") + end + + it "should fail for non hash array members" do + senders = [{"sender" => "sender1"}, {"sender" => "sender3"}, ""].to_json + + expect { + Helpers.extract_hosts_from_json(senders) + }.to raise_error("JSON host list is not an array of Hashes") + end + + it "should fail for hashes without senders" do + senders = [{"sender" => "sender1"}, {"sender" => "sender3"}, {}].to_json + + expect { + Helpers.extract_hosts_from_json(senders) + }.to raise_error("JSON host list does not have senders in it") + end + + it "should return all found unique senders" do + senders = [{"sender" => "sender1"}, {"sender" => "sender3"}, {"sender" => "sender1"}].to_json + + Helpers.extract_hosts_from_json(senders).should == ["sender1", "sender3"] + end + end + + describe "#extract_hosts_from_array" do + it "should support single string lists" do + Helpers.extract_hosts_from_array("foo").should == ["foo"] + end + + it "should support arrays" do + Helpers.extract_hosts_from_array(["foo", "bar"]).should == ["foo", "bar"] + end + + it "should fail for non string array members" do + expect { + Helpers.extract_hosts_from_array(["foo", 1]) + }.to raise_error("1 should be a string") + end + end + end + end +end