Sha256: 5448e08574ed2bb258d93fd1b9a831916c2461095e4242ac822f3e5d7697e6cc

Contents?: true

Size: 1.69 KB

Versions: 28

Compression:

Stored size: 1.69 KB

Contents

#!/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

Version data entries

28 entries across 28 versions & 1 rubygems

Version Path
mcollective-client-2.4.1 spec/unit/rpc/helpers_spec.rb
mcollective-client-2.4.0 spec/unit/rpc/helpers_spec.rb
mcollective-client-2.2.4 spec/unit/rpc/helpers_spec.rb
mcollective-client-2.2.3 spec/unit/rpc/helpers_spec.rb
mcollective-client-2.2.2 spec/unit/rpc/helpers_spec.rb
mcollective-client-2.2.1 spec/unit/rpc/helpers_spec.rb
mcollective-client-2.2.0 spec/unit/rpc/helpers_spec.rb
mcollective-client-2.0.0 spec/unit/rpc/helpers_spec.rb