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.8.7 spec/unit/mcollective/rpc/helpers_spec.rb
mcollective-client-2.8.5 spec/unit/mcollective/rpc/helpers_spec.rb
mcollective-client-2.8.8 spec/unit/mcollective/rpc/helpers_spec.rb
mcollective-client-2.8.6 spec/unit/mcollective/rpc/helpers_spec.rb
mcollective-client-2.9.1 spec/unit/mcollective/rpc/helpers_spec.rb
mcollective-client-2.9.0 spec/unit/mcollective/rpc/helpers_spec.rb
mcollective-client-2.8.9 spec/unit/mcollective/rpc/helpers_spec.rb
mcollective-client-2.8.4 spec/unit/mcollective/rpc/helpers_spec.rb
mcollective-client-2.8.3 spec/unit/mcollective/rpc/helpers_spec.rb
mcollective-client-2.8.2 spec/unit/mcollective/rpc/helpers_spec.rb
mcollective-client-2.8.1 spec/unit/mcollective/rpc/helpers_spec.rb
mcollective-client-2.8.0 spec/unit/mcollective/rpc/helpers_spec.rb
mcollective-client-2.7.0 spec/unit/rpc/helpers_spec.rb
mcollective-client-2.6.1 spec/unit/rpc/helpers_spec.rb
mcollective-client-2.6.0 spec/unit/rpc/helpers_spec.rb
mcollective-client-2.5.3 spec/unit/rpc/helpers_spec.rb
mcollective-client-2.5.2 spec/unit/rpc/helpers_spec.rb
mcollective-client-2.5.1 spec/unit/rpc/helpers_spec.rb
mcollective-client-2.5.0 spec/unit/rpc/helpers_spec.rb
mcollective-client-2.5.0.rc1 spec/unit/rpc/helpers_spec.rb