Sha256: d46d36056913cf5238b151d0e184dade38b7035a1913156db66f4c9d88cdd2e9

Contents?: true

Size: 1.43 KB

Versions: 17

Compression:

Stored size: 1.43 KB

Contents

#! /usr/bin/env ruby
require 'spec_helper'

describe "the fqdn_rand function" do
  it "provides a random number strictly less than the given max" do
    fqdn_rand(3).should satisfy {|n| n.to_i < 3 }
  end

  it "provides the same 'random' value on subsequent calls for the same host" do
    fqdn_rand(3).should eql(fqdn_rand(3))
  end

  it "considers the same host and same extra arguments to have the same random sequence" do
    first_random = fqdn_rand(3, :extra_identifier => [1, "same", "host"])
    second_random = fqdn_rand(3, :extra_identifier => [1, "same", "host"])

    first_random.should eql(second_random)
  end

  it "allows extra arguments to control the random value on a single host" do
    first_random = fqdn_rand(10000, :extra_identifier => [1, "different", "host"])
    second_different_random = fqdn_rand(10000, :extra_identifier => [2, "different", "host"])

    first_random.should_not eql(second_different_random)
  end

  it "should return different sequences of value for different hosts" do
    val1 = fqdn_rand(1000000000, :host => "first.host.com")
    val2 = fqdn_rand(1000000000, :host => "second.host.com")

    val1.should_not eql(val2)
  end

  def fqdn_rand(max, args = {})
    host = args[:host] || '127.0.0.1'
    extra = args[:extra_identifier] || []

    scope = Puppet::Parser::Scope.new_for_test_harness('localhost')
    scope.stubs(:[]).with("::fqdn").returns(host)

    scope.function_fqdn_rand([max] + extra)
  end
end

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
puppet-3.4.3 spec/unit/parser/functions/fqdn_rand_spec.rb
puppet-3.4.2 spec/unit/parser/functions/fqdn_rand_spec.rb
puppet-3.4.1 spec/unit/parser/functions/fqdn_rand_spec.rb
puppet-3.4.0 spec/unit/parser/functions/fqdn_rand_spec.rb
puppet-3.4.0.rc2 spec/unit/parser/functions/fqdn_rand_spec.rb
puppet-3.4.0.rc1 spec/unit/parser/functions/fqdn_rand_spec.rb
puppet-3.3.2 spec/unit/parser/functions/fqdn_rand_spec.rb
puppet-3.3.1 spec/unit/parser/functions/fqdn_rand_spec.rb
puppet-3.3.1.rc3 spec/unit/parser/functions/fqdn_rand_spec.rb
puppet-3.3.1.rc2 spec/unit/parser/functions/fqdn_rand_spec.rb
puppet-3.3.1.rc1 spec/unit/parser/functions/fqdn_rand_spec.rb
puppet-3.3.0 spec/unit/parser/functions/fqdn_rand_spec.rb
puppet-3.3.0.rc3 spec/unit/parser/functions/fqdn_rand_spec.rb
puppet-3.3.0.rc2 spec/unit/parser/functions/fqdn_rand_spec.rb
puppet-3.2.4 spec/unit/parser/functions/fqdn_rand_spec.rb
puppet-3.2.3 spec/unit/parser/functions/fqdn_rand_spec.rb
puppet-3.2.3.rc1 spec/unit/parser/functions/fqdn_rand_spec.rb