Sha256: 2669e9d9bff9c59016b1e6a0a00998a88ab32cbbe18d74b6fa89c61952c6b7c4

Contents?: true

Size: 1.85 KB

Versions: 35

Compression:

Stored size: 1.85 KB

Contents

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

describe Puppet::Parser::AST::ResourceReference do

  ast = Puppet::Parser::AST

  before :each do
    @scope = Puppet::Parser::Scope.new
  end

  def ast_name(value)
    Puppet::Parser::AST::Name.new(:value => value)
  end

  def newref(type, title)
    title_array = Puppet::Parser::AST::ASTArray.new(:children => [title])
    ref = Puppet::Parser::AST::ResourceReference.new(:type => type, :title => title_array)
  end

  it "should correctly produce reference strings" do
    newref("File", ast_name("/tmp/yay")).evaluate(@scope).to_s.should == "File[/tmp/yay]"
  end

  it "should produce a single resource when the title evaluates to a string" do
    newref("File", ast_name("/tmp/yay")).evaluate(@scope).should == Puppet::Resource.new("file", "/tmp/yay")
  end

  it "should return an array of resources if given an array of titles" do
    titles = Puppet::Parser::AST::ASTArray.new(:children => [ast_name("title1"), ast_name("title2")])
    ref = ast::ResourceReference.new( :title => titles, :type => "File" )
    ref.evaluate(@scope).should == [
      Puppet::Resource.new("file", "title1"),
      Puppet::Resource.new("file", "title2")
    ]
  end

  it "should return an array of resources if given a variable containing an array of titles" do
    @scope.setvar("my_files", ["foo", "bar"])
    titles = Puppet::Parser::AST::Variable.new(:value => "my_files")
    ref = newref('File', titles)
    ref.evaluate(@scope).should == [
      Puppet::Resource.new("file", "foo"),
      Puppet::Resource.new("file", "bar")
    ]
  end

  it "should return a correct representation when converting to string" do
    type = stub 'type', :is_a? => true, :to_s => "file"
    title = stub 'title', :is_a? => true, :to_s => "[/tmp/a, /tmp/b]"

    ast::ResourceReference.new( :type => type, :title => title ).to_s.should == "File[/tmp/a, /tmp/b]"
  end
end

Version data entries

35 entries across 35 versions & 3 rubygems

Version Path
puppet-2.7.26 spec/unit/parser/ast/resource_reference_spec.rb
puppet-2.7.25 spec/unit/parser/ast/resource_reference_spec.rb
puppet-2.7.24 spec/unit/parser/ast/resource_reference_spec.rb
puppet-2.7.23 spec/unit/parser/ast/resource_reference_spec.rb
puppet-2.7.22 spec/unit/parser/ast/resource_reference_spec.rb
puppet-2.7.21 spec/unit/parser/ast/resource_reference_spec.rb
puppet-2.7.20 spec/unit/parser/ast/resource_reference_spec.rb
puppet-2.7.20.rc1 spec/unit/parser/ast/resource_reference_spec.rb
librarian-puppet-0.9.4 vendor/gems/ruby/1.8/gems/puppet-2.7.18/spec/unit/parser/ast/resource_reference_spec.rb
puppet-2.7.19 spec/unit/parser/ast/resource_reference_spec.rb
supply_drop-0.11.0 examples/vendored-puppet/vendor/puppet-2.7.8/spec/unit/parser/ast/resource_reference_spec.rb
librarian-puppet-0.9.3 vendor/gems/ruby/1.8/gems/puppet-2.7.18/spec/unit/parser/ast/resource_reference_spec.rb
supply_drop-0.10.2 examples/vendored-puppet/vendor/puppet-2.7.8/spec/unit/parser/ast/resource_reference_spec.rb
puppet-2.7.18 spec/unit/parser/ast/resource_reference_spec.rb
supply_drop-0.10.1 examples/vendored-puppet/vendor/puppet-2.7.8/spec/unit/parser/ast/resource_reference_spec.rb
supply_drop-0.10.0 examples/vendored-puppet/vendor/puppet-2.7.8/spec/unit/parser/ast/resource_reference_spec.rb
puppet-2.7.17 spec/unit/parser/ast/resource_reference_spec.rb
puppet-2.7.16 spec/unit/parser/ast/resource_reference_spec.rb
puppet-2.7.14 spec/unit/parser/ast/resource_reference_spec.rb
puppet-2.7.13 spec/unit/parser/ast/resource_reference_spec.rb