Commit 7cd3337b authored by Ken Barber's avatar Ken Barber

PDB-307 Fix private method rspec failures due to mocha 1.0.0 upgrade

This patch fixes an rspec failure we were having on the terminus due to the
recent bump from mocha from 0.14.1 to 1.0.0.

Previously mocha seems to have been ignoring private method calls for whatever
reason. With the new version of mocha it is throwing exceptions (as it rightly
should).

This patch removes the use of the `private` declaration and converts all of
these methods to be document `@api private` in YARD instead migrating a
language enforcement to a documentation enforcement instead.

As an aside I noticed that char_encoding.rb had a 3 space indent convention,
this has been converted to 2 space as per our standard.
Signed-off-by: 's avatarKen Barber <ken@bob.sh>
parent 62eb486b
......@@ -10,4 +10,5 @@ group :test do
gem 'puppet', :require => false
gem 'beaker', '~> 1.0'
gem 'mocha', '~> 1.0'
end
......@@ -16,9 +16,7 @@ class Puppet::Resource::Catalog::Puppetdb < Puppet::Indirector::REST
nil
end
# TODO: I think that almost everything below this line should be
# private, but I don't want to break all the tests right now...
# @api private
def extract_extra_request_data(request)
{
:transaction_uuid => request.options[:transaction_uuid]
......
......@@ -19,8 +19,6 @@ Puppet::Reports.register_report(:puppetdb) do
submit_command(self.host, report_to_hash, CommandStoreReport, 2)
end
private
# TODO: It seems unfortunate that we have to access puppet_version and
# report_format directly as instance variables. I've filed the following
# ticket / pull req against puppet to expose them via accessors, which
......@@ -29,16 +27,21 @@ Puppet::Reports.register_report(:puppetdb) do
# the accessors until version 3.x of puppet is our oldest supported version.
#
# This was resolved in puppet 3.x via ticket #16139 (puppet pull request #1073).
# @api private
def report_format
@report_format
end
# @api private
def puppet_version
@puppet_version
end
### Convert `self` (an instance of `Puppet::Transaction::Report`) to a hash
### suitable for sending over the wire to PuppetDB
# Convert `self` (an instance of `Puppet::Transaction::Report`) to a hash
# suitable for sending over the wire to PuppetDB
#
# @api private
def report_to_hash
add_v4_fields_to_report(
{
......@@ -52,6 +55,7 @@ Puppet::Reports.register_report(:puppetdb) do
})
end
# @api private
def build_events_list
filter_events(resource_statuses.inject([]) do |events, status_entry|
_, status = *status_entry
......@@ -71,6 +75,7 @@ Puppet::Reports.register_report(:puppetdb) do
end)
end
# @api private
def run_duration
# TODO: this is wrong in puppet. I am consistently seeing reports where
# start-time + this value is less than the timestamp on the individual
......@@ -81,8 +86,10 @@ Puppet::Reports.register_report(:puppetdb) do
metrics["time"]["total"]
end
## Convert an instance of `Puppet::Transaction::Event` to a hash
## suitable for sending over the wire to PuppetDB
# Convert an instance of `Puppet::Transaction::Event` to a hash
# suitable for sending over the wire to PuppetDB
#
# @api private
def event_to_hash(resource_status, event)
add_v4_fields_to_event(resource_status,
{
......@@ -99,9 +106,11 @@ Puppet::Reports.register_report(:puppetdb) do
})
end
## Given an instance of `Puppet::Resource::Status` and a status string,
## this method fabricates a PuppetDB event object with the provided
## `"status"`.
# Given an instance of `Puppet::Resource::Status` and a status string,
# this method fabricates a PuppetDB event object with the provided
# `"status"`.
#
# @api private
def fabricate_event(resource_status, event_status)
add_v4_fields_to_event(resource_status,
{
......@@ -118,7 +127,9 @@ Puppet::Reports.register_report(:puppetdb) do
})
end
## Backwards compatibility with versions of Puppet prior to report format 4
# Backwards compatibility with versions of Puppet prior to report format 4
#
# @api private
def add_v4_fields_to_report(report_hash)
if report_format >= 4
report_hash.merge("transaction-uuid" => transaction_uuid)
......@@ -127,7 +138,9 @@ Puppet::Reports.register_report(:puppetdb) do
end
end
## Backwards compatibility with versions of Puppet prior to report format 4
# Backwards compatibility with versions of Puppet prior to report format 4
#
# @api private
def add_v4_fields_to_event(resource_status, event_hash)
if report_format >= 4
event_hash.merge("containment-path" => resource_status.containment_path)
......@@ -136,7 +149,9 @@ Puppet::Reports.register_report(:puppetdb) do
end
end
## Filter out blacklisted events, if we're configured to do so
# Filter out blacklisted events, if we're configured to do so
#
# @api private
def filter_events(events)
if config.ignore_blacklisted_events?
events.select { |e| ! config.is_event_blacklisted?(e) }
......@@ -145,7 +160,9 @@ Puppet::Reports.register_report(:puppetdb) do
end
end
## Helper method for accessing the puppetdb configuration
# Helper method for accessing the puppetdb configuration
#
# @api private
def config
Puppet::Util::Puppetdb.config
end
......
......@@ -39,8 +39,8 @@ module Puppet::Util::Puppetdb
child.extend ClassMethods
end
## Given an instance of ruby's Time class, this method converts it to a String
## that conforms to PuppetDB's wire format for representing a date/time.
# Given an instance of ruby's Time class, this method converts it to a String
# that conforms to PuppetDB's wire format for representing a date/time.
def self.to_wire_time(time)
# The current implementation simply calls iso8601, but having this method
# allows us to change that in the future if needed w/o being forced to
......@@ -58,22 +58,21 @@ module Puppet::Util::Puppetdb
end
end
# Public instance methods
# @!group Public instance methods
def submit_command(certname, payload, command_name, version)
command = Puppet::Util::Puppetdb::Command.new(command_name, version, certname, payload)
command.submit
end
private
## Private instance methods
# @!group Private instance methods
# @api private
def config
Puppet::Util::Puppetdb.config
end
# @api private
def log_x_deprecation_header(response)
if warning = response['x-deprecation']
Puppet.deprecation_warning "Deprecation from PuppetDB: #{warning}"
......
......@@ -69,10 +69,9 @@ class Puppet::Util::Puppetdb::Command
end
private
## Private class methods
# @!group Private class methods
# @api private
def self.format_payload(command, version, payload)
message = {
:command => command,
......@@ -83,9 +82,9 @@ class Puppet::Util::Puppetdb::Command
Puppet::Util::Puppetdb::CharEncoding.utf8_string(message)
end
# @!group Private instance methods
## Private instance methods
# @api private
def headers
{
"Accept" => "application/json",
......@@ -93,6 +92,7 @@ class Puppet::Util::Puppetdb::Command
}
end
# @api private
def config
# Would prefer to pass this to the constructor or acquire it some other
# way besides this pseudo-global reference.
......
......@@ -69,7 +69,7 @@ class Config
raise
end
# Public instance methods
# @!group Public instance methods
def initialize(config_hash = {})
@config = config_hash
......@@ -96,13 +96,15 @@ class Config
config[:soft_write_failure]
end
# Private instance methods
private
# @!group Private instance methods
# @!attribute [r] count
# @api private
attr_reader :config
Blacklist = Puppet::Util::Puppetdb::Blacklist
# @api private
def initialize_blacklisted_events(events = Blacklist::BlacklistedEvents)
@blacklist = Blacklist.new(events)
end
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment