Merge pull request #106 from whopper/PDOC-106/json-tests
(PDOC-106) Add acceptance tests for --emit-json options
This commit is contained in:
commit
f1c7ad39ae
|
@ -0,0 +1,41 @@
|
||||||
|
require 'spec_helper_acceptance'
|
||||||
|
require 'util'
|
||||||
|
require 'json'
|
||||||
|
|
||||||
|
include PuppetStrings::Acceptance::Util
|
||||||
|
|
||||||
|
describe 'Emitting JSON' do
|
||||||
|
expected = {
|
||||||
|
"puppet_classes" => [],
|
||||||
|
"defined_types" => [],
|
||||||
|
"resource_types" => [],
|
||||||
|
"providers" => [],
|
||||||
|
"puppet_functions" => [
|
||||||
|
"name" => "function3x",
|
||||||
|
"file" => "/etc/puppet/modules/test/lib/puppet/parser/functions/function3x.rb",
|
||||||
|
"line" => 1,
|
||||||
|
"type" => "ruby3x",
|
||||||
|
"signature" => "function3x()",
|
||||||
|
"docstring" => {
|
||||||
|
"text" => "This is the function documentation for `function3x`",
|
||||||
|
"tags" => ["tag_name" => "return", "text" => "", "types" => ["Any"]]},
|
||||||
|
"source" => "Puppet::Parser::Functions.newfunction(:function3x, :doc => \"This is the function documentation for `function3x`\") do |args|\nend"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
it 'should emit JSON to stdout when using the --emit-json-stdout option' do
|
||||||
|
test_module_path = get_test_module_path(master, /Module test/)
|
||||||
|
on master, puppet('strings', 'generate', '--emit-json-stdout', "#{test_module_path}/lib/puppet/parser/functions/function3x.rb") do
|
||||||
|
output = stdout.chomp
|
||||||
|
expect(JSON.parse(output)).to eq(expected)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'should write JSON to a file when using the --emit-json option' do
|
||||||
|
test_module_path = get_test_module_path(master, /Module test/)
|
||||||
|
tmpfile = master.tmpfile('json_output.json')
|
||||||
|
on master, puppet('strings', 'generate', "--emit-json #{tmpfile}", "#{test_module_path}/lib/puppet/parser/functions/function3x.rb")
|
||||||
|
output = read_file_on(master, tmpfile)
|
||||||
|
expect(JSON.parse(output)).to eq(expected)
|
||||||
|
end
|
||||||
|
end
|
|
@ -0,0 +1,15 @@
|
||||||
|
module PuppetStrings
|
||||||
|
module Acceptance
|
||||||
|
module Util
|
||||||
|
def read_file_on(host, filename)
|
||||||
|
on(host, "cat #{filename}").stdout
|
||||||
|
end
|
||||||
|
|
||||||
|
def get_test_module_path(host, module_regex)
|
||||||
|
modules = JSON.parse(on(host, puppet('module', 'list', '--render-as', 'json')).stdout)
|
||||||
|
test_module_info = modules['modules_by_path'].values.flatten.find { |mod_info| mod_info =~ module_regex }
|
||||||
|
test_module_info.match(/\(([^)]*)\)/)[1]
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
|
@ -1,16 +1,12 @@
|
||||||
require 'spec_helper_acceptance'
|
require 'spec_helper_acceptance'
|
||||||
|
require 'util'
|
||||||
require 'json'
|
require 'json'
|
||||||
|
|
||||||
|
include PuppetStrings::Acceptance::Util
|
||||||
|
|
||||||
describe 'Generating module documentation using generate action' do
|
describe 'Generating module documentation using generate action' do
|
||||||
def read_file_on(host, filename)
|
|
||||||
on(host, "cat #{filename}").stdout
|
|
||||||
end
|
|
||||||
|
|
||||||
before :all do
|
before :all do
|
||||||
modules = JSON.parse(on(master, puppet('module', 'list', '--render-as', 'json')).stdout)
|
test_module_path = get_test_module_path(master, /Module test/)
|
||||||
test_module_info = modules['modules_by_path'].values.flatten.find { |mod_info| mod_info =~ /Module test/ }
|
|
||||||
test_module_path = test_module_info.match(/\(([^)]*)\)/)[1]
|
|
||||||
|
|
||||||
on master, puppet('strings', 'generate', "#{test_module_path}/**/*.{rb,pp}")
|
on master, puppet('strings', 'generate', "#{test_module_path}/**/*.{rb,pp}")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
require 'beaker-rspec/spec_helper'
|
require 'beaker-rspec/spec_helper'
|
||||||
require 'beaker-rspec/helpers/serverspec'
|
require 'beaker-rspec/helpers/serverspec'
|
||||||
|
|
||||||
|
$LOAD_PATH << File.expand_path(File.join(File.dirname(__FILE__), 'acceptance/lib'))
|
||||||
|
|
||||||
unless ENV['RS_PROVISION'] == 'no'
|
unless ENV['RS_PROVISION'] == 'no'
|
||||||
install_puppet
|
install_puppet
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue