Sha256: a172b29d9cdeb542f9701a9fc54ec54d85eabe34f54e49051da6048d0c3f7e74

Contents?: true

Size: 1.88 KB

Versions: 13

Compression:

Stored size: 1.88 KB

Contents

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

describe "the fqdn_rand function" do
  before :all do
    Puppet::Parser::Functions.autoloader.loadall
  end

  before :each do
    node     = Puppet::Node.new('localhost')
    compiler = Puppet::Parser::Compiler.new(node)
    @scope   = Puppet::Parser::Scope.new(compiler)
    @scope["fqdn"] = "127.0.0.1"
  end

  it "should exist" do
    Puppet::Parser::Functions.function("fqdn_rand").should == "function_fqdn_rand"
  end

  it "should handle 0 arguments" do
    lambda { @scope.function_fqdn_rand([]) }.should_not raise_error(Puppet::ParseError)
  end

  it "should handle 1 argument'}" do
    lambda { @scope.function_fqdn_rand([3]) }.should_not raise_error(Puppet::ParseError)
  end


  (1..10).each { |n|
    it "should handle #{n} additional arguments" do
      lambda { @scope.function_fqdn_rand([3,1,2,3,4,5,6,7,8,9,10][0..n]) }.should_not raise_error(Puppet::ParseError)
    end
    it "should handle #{n} additional string arguments" do
      lambda { @scope.function_fqdn_rand([3,%w{ 1 2 3 4 5 6 7 8 9 10}].flatten[0..n]) }.should_not raise_error(Puppet::ParseError)
    end
  }

  it "should return a value less than max" do
    @scope.function_fqdn_rand([3]).should satisfy {|n| n.to_i < 3 }
  end

  it "should return the same values on subsequent invocations for the same host" do
    @scope.function_fqdn_rand([3,4]).should eql(@scope.function_fqdn_rand([3, 4]))
  end

  it "should return different sequences of value for different hosts" do
    val1 = @scope.function_fqdn_rand([10000000,4])
    @scope.expects(:[]).with("::fqdn").returns("127.0.0.2")
    val2 = @scope.function_fqdn_rand([10000000,4])
    val1.should_not eql(val2)
  end

  it "should return different values for the same hosts with different seeds" do
    val1 = @scope.function_fqdn_rand([10000000,4])
    val2 = @scope.function_fqdn_rand([10000000,42])
    val1.should_not eql(val2)
  end
end

Version data entries

13 entries across 13 versions & 2 rubygems

Version Path
librarian-puppet-0.9.9 vendor/gems/ruby/1.9.1/gems/puppet-3.1.0/spec/unit/parser/functions/fqdn_rand_spec.rb
puppet-3.1.1 spec/unit/parser/functions/fqdn_rand_spec.rb
librarian-puppet-0.9.8 vendor/gems/ruby/1.9.1/gems/puppet-3.1.0/spec/unit/parser/functions/fqdn_rand_spec.rb
puppet-3.1.0 spec/unit/parser/functions/fqdn_rand_spec.rb
puppet-3.1.0.rc2 spec/unit/parser/functions/fqdn_rand_spec.rb
puppet-3.1.0.rc1 spec/unit/parser/functions/fqdn_rand_spec.rb
puppet-3.0.2 spec/unit/parser/functions/fqdn_rand_spec.rb
puppet-3.0.2.rc3 spec/unit/parser/functions/fqdn_rand_spec.rb
puppet-3.0.2.rc2 spec/unit/parser/functions/fqdn_rand_spec.rb
puppet-3.0.2.rc1 spec/unit/parser/functions/fqdn_rand_spec.rb
puppet-3.0.1 spec/unit/parser/functions/fqdn_rand_spec.rb
puppet-3.0.1.rc1 spec/unit/parser/functions/fqdn_rand_spec.rb
puppet-3.0.0 spec/unit/parser/functions/fqdn_rand_spec.rb