[Pkg-puppet-devel] [SCM] Puppet packaging for Debian branch, master, updated. debian/0.24.6-1-356-g5718585

James Turnbull james at lovedthanlost.net
Fri Jan 23 14:20:58 UTC 2009


The following commit has been merged in the master branch:
commit 7a3a38f58c099244c2a8b490f0b69c2fa63f3e16
Author: Brice Figureau <brice-puppet at daysofwonder.com>
Date:   Sat Sep 20 14:14:44 2008 +0200

    Add rspec unit test for the append operator
    
    Signed-off-by: Brice Figureau <brice-puppet at daysofwonder.com>

diff --git a/CHANGELOG b/CHANGELOG
index 74c8a93..cbbc257 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -1,4 +1,6 @@
 0.24.x
+    Fixed #1584 - Added support for appended variables
+
     Fixed #1554 - Added support for multiple template directories
 
     Fixed #1500 - puppetrun not working
diff --git a/spec/unit/parser/ast/vardef.rb b/spec/unit/parser/ast/vardef.rb
new file mode 100755
index 0000000..6bd355c
--- /dev/null
+++ b/spec/unit/parser/ast/vardef.rb
@@ -0,0 +1,47 @@
+#!/usr/bin/env ruby
+
+require File.dirname(__FILE__) + '/../../../spec_helper'
+
+describe Puppet::Parser::AST::VarDef do
+    before :each do
+        @scope = Puppet::Parser::Scope.new()
+    end
+
+    describe "when evaluating" do
+
+        it "should evaluate arguments" do
+            name = mock 'name'
+            value = mock 'value'
+            
+            name.expects(:safeevaluate).with(@scope)
+            value.expects(:safeevaluate).with(@scope)
+
+            vardef = Puppet::Parser::AST::VarDef.new :name => name, :value => value, :file => nil,  
+                                                     :line => nil
+            vardef.evaluate(@scope)
+        end
+
+        it "should be in append=false mode if called without append" do
+            name = stub 'name', :safeevaluate => "var"
+            value = stub 'value', :safeevaluate => "1"
+            
+            @scope.expects(:setvar).with { |name,value,file,line,append| append == nil }
+            
+            vardef = Puppet::Parser::AST::VarDef.new :name => name, :value => value, :file => nil,  
+                                                     :line => nil
+            vardef.evaluate(@scope)
+        end
+        
+        it "should call scope in append mode if append is true" do
+            name = stub 'name', :safeevaluate => "var"
+            value = stub 'value', :safeevaluate => "1"
+            
+            @scope.expects(:setvar).with { |name,value,file,line,append| append == true }
+            
+            vardef = Puppet::Parser::AST::VarDef.new :name => name, :value => value, :file => nil,  
+                                                     :line => nil, :append => true
+            vardef.evaluate(@scope)
+        end
+
+    end
+end
diff --git a/spec/unit/parser/lexer.rb b/spec/unit/parser/lexer.rb
index fb66605..fed1ade 100755
--- a/spec/unit/parser/lexer.rb
+++ b/spec/unit/parser/lexer.rb
@@ -135,7 +135,8 @@ describe Puppet::Parser::Lexer::TOKENS do
         :QMARK => '?',
         :BACKSLASH => '\\',
         :FARROW => '=>',
-        :PARROW => '+>'
+        :PARROW => '+>',
+        :APPENDS => '+='
     }.each do |name, string|
         it "should have a token named #{name.to_s}" do
             Puppet::Parser::Lexer::TOKENS[name].should_not be_nil
diff --git a/spec/unit/parser/parser.rb b/spec/unit/parser/parser.rb
new file mode 100755
index 0000000..94b19be
--- /dev/null
+++ b/spec/unit/parser/parser.rb
@@ -0,0 +1,34 @@
+#!/usr/bin/env ruby
+
+require File.dirname(__FILE__) + '/../../spec_helper'
+
+describe Puppet::Parser do
+
+    AST = Puppet::Parser::AST
+
+    before :each do
+        @parser = Puppet::Parser::Parser.new :environment => "development"
+    end
+
+    describe "when parsing append operator" do
+
+        it "should not raise syntax errors" do
+            lambda { @parser.parse("$var += something") }.should_not raise_error
+        end
+
+        it "shouldraise syntax error on incomplete syntax " do
+            lambda { @parser.parse("$var += ") }.should raise_error
+        end
+
+        it "should call AST::VarDef with append=true" do
+            AST::VarDef.expects(:new).with { |h| h[:append] == true }
+            @parser.parse("$var += 2")
+        end
+
+        it "should work with arrays too" do
+            AST::VarDef.expects(:new).with { |h| h[:append] == true }
+            @parser.parse("$var += ['test']")
+        end
+
+    end
+end
diff --git a/spec/unit/parser/scope.rb b/spec/unit/parser/scope.rb
new file mode 100755
index 0000000..ec8ab6d
--- /dev/null
+++ b/spec/unit/parser/scope.rb
@@ -0,0 +1,37 @@
+#!/usr/bin/env ruby
+
+require File.dirname(__FILE__) + '/../../spec_helper'
+
+describe Puppet::Parser::Scope do
+    before :each do
+        @scope = Puppet::Parser::Scope.new()
+        @topscope = Puppet::Parser::Scope.new()
+        @scope.stubs(:parent).returns(@topscope)
+    end
+
+    describe Puppet::Parser::Scope, "when setvar is called with append=true" do
+
+        it "should raise error if the variable is already defined in this scope" do
+            @scope.setvar("var","1",nil,nil,false)
+            lambda { @scope.setvar("var","1",nil,nil,true) }.should raise_error(Puppet::ParseError)
+        end
+
+        it "it should lookup current variable value" do
+            @scope.expects(:lookupvar).with("var").returns("2")
+            @scope.setvar("var","1",nil,nil,true)
+        end
+
+        it "it should store the concatenated string '42'" do
+            @topscope.setvar("var","4",nil,nil,false)
+            @scope.setvar("var","2",nil,nil,true)
+            @scope.lookupvar("var").should == "42"
+        end
+
+        it "it should store the concatenated array [4,2]" do
+            @topscope.setvar("var",[4],nil,nil,false)
+            @scope.setvar("var",[2],nil,nil,true)
+            @scope.lookupvar("var").should == [4,2]
+        end
+
+    end
+end
diff --git a/test/data/snippets/append.pp b/test/data/snippets/append.pp
new file mode 100644
index 0000000..28edeb1
--- /dev/null
+++ b/test/data/snippets/append.pp
@@ -0,0 +1,11 @@
+$var=['/tmp/file1','/tmp/file2']
+
+class arraytest {
+	$var += ['/tmp/file3', '/tmp/file4']
+	file {
+		$var:
+			content => "test"
+	}
+}
+
+include arraytest

-- 
Puppet packaging for Debian



More information about the Pkg-puppet-devel mailing list