From b2267fcfc6da9c494803764578bbd04a648724cf Mon Sep 17 00:00:00 2001 From: Hailee Kenney Date: Tue, 2 Sep 2014 13:50:34 -0700 Subject: [PATCH] (PDOC-5) Test host classes and 3x functions Add tests for the remaining two Puppet-specific handlers that were not tested in the previous commit. Specifically, add tests for the 3.x function handler and the host class handler. --- spec/spec_helper.rb | 2 +- spec/unit/puppet/examples/test/Modulefile | 10 ++++++ .../puppet/examples/test/manifests/init.pp | 12 +++++++ .../puppetx/yardoc/yard/examples/class.pp | 5 +++ .../yardoc/yard/examples/puppet3_function.rb | 7 +++++ .../unit/puppetx/yardoc/yard/handlers_spec.rb | 31 +++++++++++++++++-- 6 files changed, 63 insertions(+), 4 deletions(-) create mode 100644 spec/unit/puppet/examples/test/Modulefile create mode 100644 spec/unit/puppet/examples/test/manifests/init.pp create mode 100644 spec/unit/puppetx/yardoc/yard/examples/class.pp create mode 100644 spec/unit/puppetx/yardoc/yard/examples/puppet3_function.rb diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 002b026..311484f 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -13,7 +13,7 @@ RSpec.configure do |config| config.mock_with :mocha end -# Borrwed from YARD spec helper +# Borrowed from YARD spec helper def parse_file(file, thisfile = __FILE__, log_level = log.level, ext = '.pp') Registry.clear path = File.join(File.dirname(thisfile), 'examples', file.to_s + ext) diff --git a/spec/unit/puppet/examples/test/Modulefile b/spec/unit/puppet/examples/test/Modulefile new file mode 100644 index 0000000..5f73a2f --- /dev/null +++ b/spec/unit/puppet/examples/test/Modulefile @@ -0,0 +1,10 @@ +name 'username-test' +version '0.1.0' +source '' +author 'username' +license 'Apache 2.0' +summary '' +description '' +project_page '' + +dependency 'puppetlabs/stdlib' diff --git a/spec/unit/puppet/examples/test/manifests/init.pp b/spec/unit/puppet/examples/test/manifests/init.pp new file mode 100644 index 0000000..487cf30 --- /dev/null +++ b/spec/unit/puppet/examples/test/manifests/init.pp @@ -0,0 +1,12 @@ +class test ( + $package_name = $test::params::package_name, + $service_name = $test::params::service_name, +) inherits test::params { + + # validate parameters here + + class { 'test::install': } -> + class { 'test::config': } ~> + class { 'test::service': } -> + Class['test'] +} diff --git a/spec/unit/puppetx/yardoc/yard/examples/class.pp b/spec/unit/puppetx/yardoc/yard/examples/class.pp new file mode 100644 index 0000000..512b39f --- /dev/null +++ b/spec/unit/puppetx/yardoc/yard/examples/class.pp @@ -0,0 +1,5 @@ +class foo::bar { + file { '/test/file/path': + owner => 'baz', + } +} diff --git a/spec/unit/puppetx/yardoc/yard/examples/puppet3_function.rb b/spec/unit/puppetx/yardoc/yard/examples/puppet3_function.rb new file mode 100644 index 0000000..a9e352f --- /dev/null +++ b/spec/unit/puppetx/yardoc/yard/examples/puppet3_function.rb @@ -0,0 +1,7 @@ +require 'puppet' + +module Puppet::Parser::Functions + newfunction(:puppet3_function, :type => rvalue) do |args| + puts 'Hello World!' + end +end diff --git a/spec/unit/puppetx/yardoc/yard/handlers_spec.rb b/spec/unit/puppetx/yardoc/yard/handlers_spec.rb index e554347..adbbeb6 100644 --- a/spec/unit/puppetx/yardoc/yard/handlers_spec.rb +++ b/spec/unit/puppetx/yardoc/yard/handlers_spec.rb @@ -4,9 +4,7 @@ require 'puppetx/yardoc/yard/handlers' describe Puppetx::Yardoc::YARD::Handlers do describe "DefinedTypeHanlder" do it "should add a defined type object in the Registry" do - parse_file :defined_type, __FILE__ - require 'pry' - #binding.pry + parse_file :defined_type, __FILE__, log.level, '.pp' obj = Registry.at("wibbly::wobbly") expect(obj.type).to be(:definedtype) end @@ -30,4 +28,31 @@ describe Puppetx::Yardoc::YARD::Handlers do expect(method.type).to be(:method) end end + + describe "ParserFunctionHanlder" do + before(:each) {parse_file :puppet3_function, __FILE__, log.level, '.rb'} + + it "should add a module object to the Registry" do + puppet_module = Registry.at("Puppet::Parser::Functions") + expect(puppet_module.type).to be(:module) + end + + it "should add a puppet namespace object to the Registry" do + namespace = Registry.at("ParserFunctions") + expect(namespace.type).to be(:puppetnamespace) + end + + it "should add a method object to the Registry" do + method = Registry.at("ParserFunctions#puppet3_function") + expect(method.type).to be(:method) + end + end + + describe "HostClassDefintion" do + before(:each) {parse_file :class, __FILE__, log.level, '.pp'} + it "should add a host class object to the Registry" do + hostclass = Registry.at("foo::bar") + expect(hostclass.type).to be(:hostclass) + end + end end