Sha256: 7e63df777c6ad5dd2f5556d56d139920d30d7e19422a3b7a5dba2f50d17a5ff8

Contents?: true

Size: 1.72 KB

Versions: 19

Compression:

Stored size: 1.72 KB

Contents

#!/usr/bin/env ruby

require File.dirname(__FILE__) + '/../../../spec_helper'

describe "the 'defined' function" do

  before :each do
    Puppet::Node::Environment.stubs(:current).returns(nil)
    @compiler = Puppet::Parser::Compiler.new(Puppet::Node.new("foo"))
    @scope = Puppet::Parser::Scope.new(:compiler => @compiler)
  end

  it "should exist" do
    Puppet::Parser::Functions.function("defined").should == "function_defined"
  end

  it "should be true when the name is defined as a class" do
    @scope.known_resource_types.add Puppet::Resource::Type.new(:hostclass, "yayness")
    @scope.function_defined("yayness").should be_true
  end

  it "should be true when the name is defined as a definition" do
    @scope.known_resource_types.add Puppet::Resource::Type.new(:definition, "yayness")
    @scope.function_defined("yayness").should be_true
  end

  it "should be true when the name is defined as a builtin type" do
    @scope.function_defined("file").should be_true
  end


  it "should be true when any of the provided names are defined" do
    @scope.known_resource_types.add Puppet::Resource::Type.new(:definition, "yayness")
    @scope.function_defined(["meh", "yayness", "booness"]).should be_true
  end

  it "should be false when a single given name is not defined" do
    @scope.function_defined("meh").should be_false
  end

  it "should be false when none of the names are defined" do
    @scope.function_defined(["meh", "yayness", "booness"]).should be_false
  end

  it "should be true when a resource reference is provided and the resource is in the catalog" do
    resource = Puppet::Resource.new("file", "/my/file")
    @compiler.add_resource(@scope, resource)
    @scope.function_defined(resource).should be_true
  end
end

Version data entries

19 entries across 19 versions & 1 rubygems

Version Path
puppet-2.6.18 spec/unit/parser/functions/defined_spec.rb
puppet-2.6.17 spec/unit/parser/functions/defined_spec.rb
puppet-2.6.16 spec/unit/parser/functions/defined_spec.rb
puppet-2.6.15 spec/unit/parser/functions/defined_spec.rb
puppet-2.6.14 spec/unit/parser/functions/defined_spec.rb
puppet-2.6.13 spec/unit/parser/functions/defined_spec.rb
puppet-2.6.12 spec/unit/parser/functions/defined_spec.rb
puppet-2.6.11 spec/unit/parser/functions/defined_spec.rb
puppet-2.6.10 spec/unit/parser/functions/defined_spec.rb
puppet-2.6.9 spec/unit/parser/functions/defined_spec.rb
puppet-2.6.8 spec/unit/parser/functions/defined_spec.rb
puppet-2.6.7 spec/unit/parser/functions/defined_spec.rb
puppet-2.6.6 spec/unit/parser/functions/defined_spec.rb
puppet-2.6.5 spec/unit/parser/functions/defined_spec.rb
puppet-2.6.4 spec/unit/parser/functions/defined_spec.rb
puppet-2.6.3 spec/unit/parser/functions/defined_spec.rb
puppet-2.6.2 spec/unit/parser/functions/defined_spec.rb
puppet-2.6.1 spec/unit/parser/functions/defined_spec.rb
puppet-2.6.0 spec/unit/parser/functions/defined_spec.rb