Sha256: 016fd88e737d3afe5bd4dc65294739c145b32d6818114771ef3447a65a5c4191

Contents?: true

Size: 1.95 KB

Versions: 16

Compression:

Stored size: 1.95 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

        it "should support puppet query output" do
          senders = [{"certname" => "sender1"}, {"certname" => "sender3"}, {"certname" => "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

16 entries across 16 versions & 1 rubygems

Version Path
mcollective-client-2.12.5 spec/unit/mcollective/rpc/helpers_spec.rb
mcollective-client-2.12.4 spec/unit/mcollective/rpc/helpers_spec.rb
mcollective-client-2.12.3 spec/unit/mcollective/rpc/helpers_spec.rb
mcollective-client-2.12.1 spec/unit/mcollective/rpc/helpers_spec.rb
mcollective-client-2.12.0 spec/unit/mcollective/rpc/helpers_spec.rb
mcollective-client-2.10.6 spec/unit/mcollective/rpc/helpers_spec.rb
mcollective-client-2.11.4 spec/unit/mcollective/rpc/helpers_spec.rb
mcollective-client-2.11.3 spec/unit/mcollective/rpc/helpers_spec.rb
mcollective-client-2.11.2 spec/unit/mcollective/rpc/helpers_spec.rb
mcollective-client-2.11.1 spec/unit/mcollective/rpc/helpers_spec.rb
mcollective-client-2.11.0 spec/unit/mcollective/rpc/helpers_spec.rb
mcollective-client-2.10.4 spec/unit/mcollective/rpc/helpers_spec.rb
mcollective-client-2.10.3 spec/unit/mcollective/rpc/helpers_spec.rb
mcollective-client-2.10.2 spec/unit/mcollective/rpc/helpers_spec.rb
mcollective-client-2.10.1 spec/unit/mcollective/rpc/helpers_spec.rb
mcollective-client-2.10.0 spec/unit/mcollective/rpc/helpers_spec.rb