(PDOC-63) Fix specs for Puppet versions less than 4.1.
The specs test functions written in the Puppet language in a few places, but this feature is only supported in Puppet 4.1+. This commit prevents these specs from running if targeting older versions of Puppet.
This commit is contained in:
parent
ef651fb33a
commit
9ba9b56306
|
@ -178,7 +178,7 @@
|
|||
{
|
||||
"name": "func",
|
||||
"file": "(stdin)",
|
||||
"line": 20,
|
||||
"line": 6,
|
||||
"type": "puppet",
|
||||
"signature": "func(Integer $param1, Any $param2, String $param3 = hi)",
|
||||
"docstring": {
|
||||
|
|
|
@ -0,0 +1,301 @@
|
|||
{
|
||||
"puppet_classes": [
|
||||
{
|
||||
"name": "klass",
|
||||
"file": "(stdin)",
|
||||
"line": 5,
|
||||
"inherits": "foo::bar",
|
||||
"docstring": {
|
||||
"text": "A simple class.",
|
||||
"tags": [
|
||||
{
|
||||
"tag_name": "param",
|
||||
"text": "First param.",
|
||||
"types": [
|
||||
"Integer"
|
||||
],
|
||||
"name": "param1"
|
||||
},
|
||||
{
|
||||
"tag_name": "param",
|
||||
"text": "Second param.",
|
||||
"types": [
|
||||
"Any"
|
||||
],
|
||||
"name": "param2"
|
||||
},
|
||||
{
|
||||
"tag_name": "param",
|
||||
"text": "Third param.",
|
||||
"types": [
|
||||
"String"
|
||||
],
|
||||
"name": "param3"
|
||||
}
|
||||
]
|
||||
},
|
||||
"defaults": {
|
||||
"param3": "hi"
|
||||
},
|
||||
"source": "class klass(Integer $param1, $param2, String $param3 = hi) inherits foo::bar {\n}"
|
||||
}
|
||||
],
|
||||
"defined_types": [
|
||||
{
|
||||
"name": "dt",
|
||||
"file": "(stdin)",
|
||||
"line": 12,
|
||||
"docstring": {
|
||||
"text": "A simple defined type.",
|
||||
"tags": [
|
||||
{
|
||||
"tag_name": "param",
|
||||
"text": "First param.",
|
||||
"types": [
|
||||
"Integer"
|
||||
],
|
||||
"name": "param1"
|
||||
},
|
||||
{
|
||||
"tag_name": "param",
|
||||
"text": "Second param.",
|
||||
"types": [
|
||||
"Any"
|
||||
],
|
||||
"name": "param2"
|
||||
},
|
||||
{
|
||||
"tag_name": "param",
|
||||
"text": "Third param.",
|
||||
"types": [
|
||||
"String"
|
||||
],
|
||||
"name": "param3"
|
||||
}
|
||||
]
|
||||
},
|
||||
"defaults": {
|
||||
"param3": "hi"
|
||||
},
|
||||
"source": "define dt(Integer $param1, $param2, String $param3 = hi) {\n}"
|
||||
}
|
||||
],
|
||||
"resource_types": [
|
||||
{
|
||||
"name": "database",
|
||||
"file": "(stdin)",
|
||||
"line": 43,
|
||||
"docstring": {
|
||||
"text": "An example database server resource type."
|
||||
},
|
||||
"properties": [
|
||||
{
|
||||
"name": "ensure",
|
||||
"description": "What state the database should be in.",
|
||||
"values": [
|
||||
"present",
|
||||
"absent",
|
||||
"up",
|
||||
"down"
|
||||
],
|
||||
"aliases": {
|
||||
"up": "present",
|
||||
"down": "absent"
|
||||
},
|
||||
"default": "up"
|
||||
},
|
||||
{
|
||||
"name": "file",
|
||||
"description": "The database file to use."
|
||||
},
|
||||
{
|
||||
"name": "log_level",
|
||||
"description": "The log level to use.",
|
||||
"values": [
|
||||
"debug",
|
||||
"warn",
|
||||
"error"
|
||||
],
|
||||
"default": "warn"
|
||||
}
|
||||
],
|
||||
"parameters": [
|
||||
{
|
||||
"name": "address",
|
||||
"description": "The database server name.",
|
||||
"isnamevar": true
|
||||
},
|
||||
{
|
||||
"name": "encryption_key",
|
||||
"description": "The encryption key to use."
|
||||
},
|
||||
{
|
||||
"name": "encrypt",
|
||||
"description": "Whether or not to encrypt the database.",
|
||||
"values": [
|
||||
"true",
|
||||
"false",
|
||||
"yes",
|
||||
"no"
|
||||
],
|
||||
"default": "false"
|
||||
}
|
||||
],
|
||||
"features": [
|
||||
{
|
||||
"name": "encryption",
|
||||
"description": "The provider supports encryption."
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
"providers": [
|
||||
{
|
||||
"name": "linux",
|
||||
"type_name": "database",
|
||||
"file": "(stdin)",
|
||||
"line": 33,
|
||||
"docstring": {
|
||||
"text": "An example provider on Linux."
|
||||
},
|
||||
"confines": {
|
||||
"kernel": "Linux",
|
||||
"osfamily": "RedHat"
|
||||
},
|
||||
"features": [
|
||||
"implements_some_feature",
|
||||
"some_other_feature"
|
||||
],
|
||||
"defaults": {
|
||||
"kernel": "Linux"
|
||||
},
|
||||
"commands": {
|
||||
"foo": "/usr/bin/foo"
|
||||
}
|
||||
}
|
||||
],
|
||||
"puppet_functions": [
|
||||
{
|
||||
"name": "func3x",
|
||||
"file": "(stdin)",
|
||||
"line": 1,
|
||||
"type": "ruby3x",
|
||||
"signature": "func3x(String $first, Any $second)",
|
||||
"docstring": {
|
||||
"text": "An example 3.x function.",
|
||||
"tags": [
|
||||
{
|
||||
"tag_name": "param",
|
||||
"text": "The first parameter.",
|
||||
"types": [
|
||||
"String"
|
||||
],
|
||||
"name": "first"
|
||||
},
|
||||
{
|
||||
"tag_name": "param",
|
||||
"text": "The second parameter.",
|
||||
"types": [
|
||||
"Any"
|
||||
],
|
||||
"name": "second"
|
||||
},
|
||||
{
|
||||
"tag_name": "return",
|
||||
"text": "Returns nothing.",
|
||||
"types": [
|
||||
"Undef"
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
"source": "Puppet::Parser::Functions.newfunction(:func3x, doc: <<-DOC\nAn example 3.x function.\n@param [String] first The first parameter.\n@param second The second parameter.\n@return [Undef] Returns nothing.\nDOC\n) do |*args|\nend"
|
||||
},
|
||||
{
|
||||
"name": "func4x",
|
||||
"file": "(stdin)",
|
||||
"line": 11,
|
||||
"type": "ruby4x",
|
||||
"docstring": {
|
||||
"text": "An example 4.x function.",
|
||||
"tags": [
|
||||
{
|
||||
"tag_name": "overload",
|
||||
"signature": "func4x(Integer $param1, Any $param2, Optional[Array[String]] $param3)",
|
||||
"docstring": {
|
||||
"text": "The first overload.",
|
||||
"tags": [
|
||||
{
|
||||
"tag_name": "param",
|
||||
"text": "The first parameter.",
|
||||
"types": [
|
||||
"Integer"
|
||||
],
|
||||
"name": "param1"
|
||||
},
|
||||
{
|
||||
"tag_name": "param",
|
||||
"text": "The second parameter.",
|
||||
"types": [
|
||||
"Any"
|
||||
],
|
||||
"name": "param2"
|
||||
},
|
||||
{
|
||||
"tag_name": "param",
|
||||
"text": "The third parameter.",
|
||||
"types": [
|
||||
"Optional[Array[String]]"
|
||||
],
|
||||
"name": "param3"
|
||||
},
|
||||
{
|
||||
"tag_name": "return",
|
||||
"text": "Returns nothing.",
|
||||
"types": [
|
||||
"Undef"
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
"name": "func4x"
|
||||
},
|
||||
{
|
||||
"tag_name": "overload",
|
||||
"signature": "func4x(Boolean $param, Callable &$block)",
|
||||
"docstring": {
|
||||
"text": "The second overload.",
|
||||
"tags": [
|
||||
{
|
||||
"tag_name": "param",
|
||||
"text": "The first parameter.",
|
||||
"types": [
|
||||
"Boolean"
|
||||
],
|
||||
"name": "param"
|
||||
},
|
||||
{
|
||||
"tag_name": "param",
|
||||
"text": "The block parameter.",
|
||||
"types": [
|
||||
"Callable"
|
||||
],
|
||||
"name": "&block"
|
||||
},
|
||||
{
|
||||
"tag_name": "return",
|
||||
"text": "Returns a string.",
|
||||
"types": [
|
||||
"String"
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
"name": "func4x"
|
||||
}
|
||||
]
|
||||
},
|
||||
"source": "Puppet::Functions.create_function(:func4x) do\n # The first overload.\n # @param param1 The first parameter.\n # @param param2 The second parameter.\n # @param param3 The third parameter.\n # @return [Undef] Returns nothing.\n dispatch :foo do\n param 'Integer', :param1\n param 'Any', :param2\n optional_param 'Array[String]', :param3\n end\n\n # The second overload.\n # @param param The first parameter.\n # @param block The block parameter.\n # @return [String] Returns a string.\n dispatch :other do\n param 'Boolean', :param\n block_param\n end\nend"
|
||||
}
|
||||
]
|
||||
}
|
|
@ -1,11 +1,15 @@
|
|||
require 'mocha'
|
||||
require 'rspec'
|
||||
require 'puppet/version'
|
||||
require 'puppet-strings'
|
||||
require 'puppet-strings/yard'
|
||||
|
||||
# Explicitly set up YARD once
|
||||
PuppetStrings::Yard.setup!
|
||||
|
||||
# Enable testing of Puppet functions if running against 4.1+
|
||||
TEST_PUPPET_FUNCTIONS = Gem::Dependency.new('', '>= 4.1.0').match?('', Puppet::PUPPETVERSION)
|
||||
|
||||
RSpec.configure do |config|
|
||||
config.mock_with :mocha
|
||||
|
||||
|
|
|
@ -19,7 +19,10 @@ class klass(Integer $param1, $param2, String $param3 = hi) inherits foo::bar {
|
|||
# @param param3 Third param.
|
||||
define dt(Integer $param1, $param2, String $param3 = hi) {
|
||||
}
|
||||
SOURCE
|
||||
|
||||
# Only include Puppet functions for 4.1+
|
||||
YARD::Parser::SourceParser.parse_string(<<-SOURCE, :puppet) if TEST_PUPPET_FUNCTIONS
|
||||
# A simple function.
|
||||
# @param param1 First param.
|
||||
# @param param2 Second param.
|
||||
|
@ -112,7 +115,8 @@ end
|
|||
SOURCE
|
||||
end
|
||||
|
||||
let(:baseline_path) { File.join(File.dirname(__FILE__), '../../fixtures/unit/json/output.json') }
|
||||
let(:filename) { TEST_PUPPET_FUNCTIONS ? 'output.json' : 'output_without_puppet_function.json' }
|
||||
let(:baseline_path) { File.join(File.dirname(__FILE__), "../../fixtures/unit/json/#{filename}") }
|
||||
let(:baseline) { File.read(baseline_path) }
|
||||
|
||||
describe 'rendering JSON to a file' do
|
||||
|
|
|
@ -1,7 +1,8 @@
|
|||
require 'spec_helper'
|
||||
require 'puppet-strings/yard'
|
||||
|
||||
describe PuppetStrings::Yard::Handlers::Puppet::FunctionHandler do
|
||||
# Limit this spec to Puppet 4.1+ (when functions in Puppet were implemented)
|
||||
describe PuppetStrings::Yard::Handlers::Puppet::FunctionHandler, if: TEST_PUPPET_FUNCTIONS do
|
||||
subject {
|
||||
YARD::Parser::SourceParser.parse_string(source, :puppet)
|
||||
YARD::Registry.all(:puppet_function)
|
||||
|
|
|
@ -133,7 +133,7 @@ SOURCE
|
|||
end
|
||||
end
|
||||
|
||||
describe 'parsing puppet functions' do
|
||||
describe 'parsing puppet functions', if: TEST_PUPPET_FUNCTIONS do
|
||||
let(:source) { <<SOURCE
|
||||
notice hello
|
||||
# A simple foo function.
|
||||
|
|
Loading…
Reference in New Issue