diff options
| author | Matt Robinson <matt@puppetlabs.com> | 2011-05-19 21:18:55 -0700 |
|---|---|---|
| committer | Matt Robinson <matt@puppetlabs.com> | 2011-05-19 21:18:55 -0700 |
| commit | eeeab02fd97a625ec0e21ecd5d0ed7f0067027ef (patch) | |
| tree | 704477b4d8c2b255707e65135b3bb0d10253e06c /spec/unit/parser | |
| parent | be2f20899d76621db4cf574d074f0ae89777272e (diff) | |
| parent | 99bf07e76bab47760b9eb3dc42f08582c568388f (diff) | |
| download | puppet-eeeab02fd97a625ec0e21ecd5d0ed7f0067027ef.tar.gz puppet-eeeab02fd97a625ec0e21ecd5d0ed7f0067027ef.tar.xz puppet-eeeab02fd97a625ec0e21ecd5d0ed7f0067027ef.zip | |
Merge branch '2.7.next' into 2.7.x
* 2.7.next: (42 commits)
(#6395) Add extpuppet help, eval, and interfaces
Adding a sleep state post starting master
maint: fix spec_helper inclusions again.
(#7523) Refactor the grammar to reduce duplication
(#7114) Fix specs for ssh authorized key parsed provider
(#7114) Target returns correct value
(#7114) Add integration tests for authorized_key
(#7114) Improve unit tests for ssh_authorized_key
(#7114) Improve value validation for authorized_key
(#7300) Fix instances method of mount provider
(#7259) Remove ActiveRecord requirement from indirector face spec
(#7259) Do not try to load all Terminus classes when configuring the Indirector
(#3836) External nodes should only capture stdout
Revert "(#7220) Add the ability to "inherit" options."
maint: sync 'authconfig' to 'rest_authconfig' setting
adding test for ticket 7139
(#7139) Accept '/' as a valid path in filesets
(#7300) Add specs for the mount provider
case seems needless here as there is only two opts, also the rest of the file seems to use if so this should make things more consistant
(#6845) Mount writes incorrect vfstab entries
...
Diffstat (limited to 'spec/unit/parser')
| -rwxr-xr-x | spec/unit/parser/compiler_spec.rb | 54 | ||||
| -rwxr-xr-x | spec/unit/parser/lexer_spec.rb | 44 | ||||
| -rwxr-xr-x | spec/unit/parser/resource_spec.rb | 64 | ||||
| -rwxr-xr-x | spec/unit/parser/scope_spec.rb | 6 |
4 files changed, 101 insertions, 67 deletions
diff --git a/spec/unit/parser/compiler_spec.rb b/spec/unit/parser/compiler_spec.rb index 9ad754ad8..fcce9f6f4 100755 --- a/spec/unit/parser/compiler_spec.rb +++ b/spec/unit/parser/compiler_spec.rb @@ -32,6 +32,14 @@ class CompilerTestResource def evaluate end + + def file + "/fake/file/goes/here" + end + + def line + "42" + end end describe Puppet::Parser::Compiler do @@ -420,52 +428,6 @@ describe Puppet::Parser::Compiler do @compiler.catalog.should be_edge(@scope.resource, resource) end - it "should add an edge to any specified stage for class resources" do - other_stage = resource(:stage, "other") - @compiler.add_resource(@scope, other_stage) - resource = resource(:class, "foo") - resource[:stage] = 'other' - - @compiler.add_resource(@scope, resource) - - @compiler.catalog.edge?(other_stage, resource).should be_true - end - - it "should fail if a non-class resource attempts to set a stage" do - other_stage = resource(:stage, "other") - @compiler.add_resource(@scope, other_stage) - resource = resource(:file, "foo") - resource[:stage] = 'other' - - lambda { @compiler.add_resource(@scope, resource) }.should raise_error(ArgumentError) - end - - it "should fail if an unknown stage is specified" do - resource = resource(:class, "foo") - resource[:stage] = 'other' - - lambda { @compiler.add_resource(@scope, resource) }.should raise_error(ArgumentError) - end - - it "should add edges from the class resources to the parent's stage if no stage is specified" do - main = @compiler.catalog.resource(:stage, :main) - foo_stage = resource(:stage, :foo_stage) - @compiler.add_resource(@scope, foo_stage) - resource = resource(:class, "foo") - @scope.stubs(:resource).returns(:stage => :foo_stage) - @compiler.add_resource(@scope, resource) - - @compiler.catalog.should be_edge(foo_stage, resource) - end - - it "should add edges from top-level class resources to the main stage if no stage is specified" do - main = @compiler.catalog.resource(:stage, :main) - resource = resource(:class, "foo") - @compiler.add_resource(@scope, resource) - - @compiler.catalog.should be_edge(main, resource) - end - it "should not add non-class resources that don't specify a stage to the 'main' stage" do main = @compiler.catalog.resource(:stage, :main) resource = resource(:file, "foo") diff --git a/spec/unit/parser/lexer_spec.rb b/spec/unit/parser/lexer_spec.rb index 6cdb0553a..48f7304b4 100755 --- a/spec/unit/parser/lexer_spec.rb +++ b/spec/unit/parser/lexer_spec.rb @@ -230,22 +230,6 @@ describe Puppet::Parser::Lexer::TOKENS do end end -describe Puppet::Parser::Lexer::TOKENS[:CLASSNAME] do - before { @token = Puppet::Parser::Lexer::TOKENS[:CLASSNAME] } - - it "should match against lower-case alpha-numeric terms separated by double colons" do - @token.regex.should =~ "one::two" - end - - it "should match against many lower-case alpha-numeric terms separated by double colons" do - @token.regex.should =~ "one::two::three::four::five" - end - - it "should match against lower-case alpha-numeric terms prefixed by double colons" do - @token.regex.should =~ "::one" - end -end - describe Puppet::Parser::Lexer::TOKENS[:CLASSREF] do before { @token = Puppet::Parser::Lexer::TOKENS[:CLASSREF] } @@ -295,6 +279,22 @@ describe Puppet::Parser::Lexer::TOKENS[:NAME] do Puppet::Parser::Lexer::KEYWORDS.expects(:lookup).returns(keyword) @token.convert(stub('lexer'), "false").should == [Puppet::Parser::Lexer::TOKENS[:BOOLEAN], false] end + + it "should match against lower-case alpha-numeric terms separated by double colons" do + @token.regex.should =~ "one::two" + end + + it "should match against many lower-case alpha-numeric terms separated by double colons" do + @token.regex.should =~ "one::two::three::four::five" + end + + it "should match against lower-case alpha-numeric terms prefixed by double colons" do + @token.regex.should =~ "::one" + end + + it "should match against nested terms starting with numbers" do + @token.regex.should =~ "::1one::2two::3three" + end end describe Puppet::Parser::Lexer::TOKENS[:NUMBER] do @@ -445,6 +445,9 @@ describe Puppet::Parser::Lexer,"when lexing strings" do %q["foo$bar$"] => [[:DQPRE,"foo"],[:VARIABLE,"bar"],[:DQPOST,"$"]], %q["foo$$bar"] => [[:DQPRE,"foo$"],[:VARIABLE,"bar"],[:DQPOST,""]], %q[""] => [[:STRING,""]], + %q["123 456 789 0"] => [[:STRING,"123 456 789 0"]], + %q["${123} 456 $0"] => [[:DQPRE,""],[:VARIABLE,"123"],[:DQMID," 456 "],[:VARIABLE,"0"],[:DQPOST,""]], + %q["$foo::::bar"] => [[:DQPRE,""],[:VARIABLE,"foo"],[:DQPOST,"::::bar"]] }.each { |src,expected_result| it "should handle #{src} correctly" do tokens_scanned_from(src).should be_like(*expected_result) @@ -660,10 +663,17 @@ describe "Puppet::Parser::Lexer in the old tests" do end it "should correctly lex variables" do - ["$variable", "$::variable", "$qualified::variable", "$further::qualified::variable"].each do |string| + ["$variable", "$::variable", "$qualified::variable", "$further::qualified::variable", "$hyphenated-variable", "$-variable-with-leading-dash"].each do |string| tokens_scanned_from(string).should be_like([:VARIABLE,string.sub(/^\$/,'')]) end end + + it "should not include whitespace in a variable" do + tokens_scanned_from("$foo bar").should_not be_like([:VARIABLE, "foo bar"]) + end + it "should not include excess colons in a variable" do + tokens_scanned_from("$foo::::bar").should_not be_like([:VARIABLE, "foo::::bar"]) + end end describe "Puppet::Parser::Lexer in the old tests when lexing example files" do diff --git a/spec/unit/parser/resource_spec.rb b/spec/unit/parser/resource_spec.rb index 064f27514..365c4e9c5 100755 --- a/spec/unit/parser/resource_spec.rb +++ b/spec/unit/parser/resource_spec.rb @@ -131,9 +131,19 @@ describe Puppet::Parser::Resource do end describe "when evaluating" do + before do + @node = Puppet::Node.new "test-node" + @compiler = Puppet::Parser::Compiler.new @node + @catalog = Puppet::Resource::Catalog.new + source = stub('source') + source.stubs(:module_name) + @scope = Puppet::Parser::Scope.new(:compiler => @compiler, :source => source) + @catalog.add_resource(Puppet::Parser::Resource.new("stage", :main, :scope => @scope)) + end + it "should evaluate the associated AST definition" do definition = newdefine "mydefine" - res = Puppet::Parser::Resource.new("mydefine", "whatever", :scope => @scope, :source => @source) + res = Puppet::Parser::Resource.new("mydefine", "whatever", :scope => @scope, :source => @source, :catalog => @catalog) definition.expects(:evaluate_code).with(res) res.evaluate @@ -141,17 +151,65 @@ describe Puppet::Parser::Resource do it "should evaluate the associated AST class" do @class = newclass "myclass" - res = Puppet::Parser::Resource.new("class", "myclass", :scope => @scope, :source => @source) + res = Puppet::Parser::Resource.new("class", "myclass", :scope => @scope, :source => @source, :catalog => @catalog) @class.expects(:evaluate_code).with(res) res.evaluate end it "should evaluate the associated AST node" do nodedef = newnode("mynode") - res = Puppet::Parser::Resource.new("node", "mynode", :scope => @scope, :source => @source) + res = Puppet::Parser::Resource.new("node", "mynode", :scope => @scope, :source => @source, :catalog => @catalog) nodedef.expects(:evaluate_code).with(res) res.evaluate end + + it "should add an edge to any specified stage for class resources" do + @compiler.known_resource_types.add Puppet::Resource::Type.new(:hostclass, "foo", '') + + other_stage = Puppet::Parser::Resource.new(:stage, "other", :scope => @scope, :catalog => @catalog) + @compiler.add_resource(@scope, other_stage) + resource = Puppet::Parser::Resource.new(:class, "foo", :scope => @scope, :catalog => @catalog) + resource[:stage] = 'other' + @compiler.add_resource(@scope, resource) + + resource.evaluate + + @compiler.catalog.edge?(other_stage, resource).should be_true + end + + it "should fail if an unknown stage is specified" do + @compiler.known_resource_types.add Puppet::Resource::Type.new(:hostclass, "foo", '') + + resource = Puppet::Parser::Resource.new(:class, "foo", :scope => @scope, :catalog => @catalog) + resource[:stage] = 'other' + + lambda { resource.evaluate }.should raise_error(ArgumentError, /Could not find stage other specified by/) + end + + it "should add edges from the class resources to the parent's stage if no stage is specified" do + main = @compiler.catalog.resource(:stage, :main) + foo_stage = Puppet::Parser::Resource.new(:stage, :foo_stage, :scope => @scope, :catalog => @catalog) + @compiler.add_resource(@scope, foo_stage) + @compiler.known_resource_types.add Puppet::Resource::Type.new(:hostclass, "foo", '') + resource = Puppet::Parser::Resource.new(:class, "foo", :scope => @scope, :catalog => @catalog) + resource[:stage] = 'foo_stage' + @compiler.add_resource(@scope, resource) + + resource.evaluate + + @compiler.catalog.should be_edge(foo_stage, resource) + end + + it "should add edges from top-level class resources to the main stage if no stage is specified" do + main = @compiler.catalog.resource(:stage, :main) + @compiler.known_resource_types.add Puppet::Resource::Type.new(:hostclass, "foo", '') + resource = Puppet::Parser::Resource.new(:class, "foo", :scope => @scope, :catalog => @catalog) + @compiler.add_resource(@scope, resource) + + resource.evaluate + + @compiler.catalog.should be_edge(main, resource) + end end describe "when finishing" do diff --git a/spec/unit/parser/scope_spec.rb b/spec/unit/parser/scope_spec.rb index bf4d1e29e..5308856ed 100755 --- a/spec/unit/parser/scope_spec.rb +++ b/spec/unit/parser/scope_spec.rb @@ -121,7 +121,11 @@ describe Puppet::Parser::Scope do def create_class_scope(name) klass = newclass(name) - Puppet::Parser::Resource.new("class", name, :scope => @scope, :source => mock('source')).evaluate + + catalog = Puppet::Resource::Catalog.new + catalog.add_resource(Puppet::Parser::Resource.new("stage", :main, :scope => Puppet::Parser::Scope.new)) + + Puppet::Parser::Resource.new("class", name, :scope => @scope, :source => mock('source'), :catalog => catalog).evaluate @scope.class_scope(klass) end |
