Sha256: d4ef61746387f73ae04370aa0d7be9ad85186a21296893a6a43b34993cd635e7

Contents?: true

Size: 1.56 KB

Versions: 189

Compression:

Stored size: 1.56 KB

Contents

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

describe "the fqdn_rand function" do
  include PuppetSpec::Scope

  it "returns an integer" do
    expect(fqdn_rand(3)).to be_an(Integer)
  end

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

  it "provides the same 'random' value on subsequent calls for the same host" do
    expect(fqdn_rand(3)).to 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"])

    expect(first_random).to 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"])

    expect(first_random).not_to 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")

    expect(val1).not_to eql(val2)
  end

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

    scope = create_test_scope_for_node('localhost')
    scope.stubs(:[]).with("::fqdn").returns(host)

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

Version data entries

189 entries across 189 versions & 1 rubygems

Version Path
puppet-5.3.7 spec/unit/parser/functions/fqdn_rand_spec.rb
puppet-5.3.7-x86-mingw32 spec/unit/parser/functions/fqdn_rand_spec.rb
puppet-5.3.7-x64-mingw32 spec/unit/parser/functions/fqdn_rand_spec.rb
puppet-5.3.7-universal-darwin spec/unit/parser/functions/fqdn_rand_spec.rb
puppet-4.10.12 spec/unit/parser/functions/fqdn_rand_spec.rb
puppet-4.10.12-x86-mingw32 spec/unit/parser/functions/fqdn_rand_spec.rb
puppet-4.10.12-x64-mingw32 spec/unit/parser/functions/fqdn_rand_spec.rb
puppet-4.10.12-universal-darwin spec/unit/parser/functions/fqdn_rand_spec.rb
puppet-4.10.11 spec/unit/parser/functions/fqdn_rand_spec.rb
puppet-4.10.11-x86-mingw32 spec/unit/parser/functions/fqdn_rand_spec.rb
puppet-4.10.11-x64-mingw32 spec/unit/parser/functions/fqdn_rand_spec.rb
puppet-4.10.11-universal-darwin spec/unit/parser/functions/fqdn_rand_spec.rb
puppet-5.3.6 spec/unit/parser/functions/fqdn_rand_spec.rb
puppet-5.3.6-x86-mingw32 spec/unit/parser/functions/fqdn_rand_spec.rb
puppet-5.3.6-x64-mingw32 spec/unit/parser/functions/fqdn_rand_spec.rb
puppet-5.3.6-universal-darwin spec/unit/parser/functions/fqdn_rand_spec.rb
puppet-5.4.0 spec/unit/parser/functions/fqdn_rand_spec.rb
puppet-5.4.0-x86-mingw32 spec/unit/parser/functions/fqdn_rand_spec.rb
puppet-5.4.0-x64-mingw32 spec/unit/parser/functions/fqdn_rand_spec.rb
puppet-5.4.0-universal-darwin spec/unit/parser/functions/fqdn_rand_spec.rb