Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add tests and Puppet-Strings based reference docs #41

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

alexjfisher
Copy link
Contributor

A couple of the data-types are tightened slightly, but otherwise, no functional changes anyone should notice.

gem 'puppet-lint', '>= 1.0.0'
gem 'puppetlabs_spec_helper', '>= 2.11.0'
gem 'rspec-puppet-facts', '>= 1.8.0'
gem 'metadata-json-lint'
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Without this gem explicitly declared, the validate rake task won't check the metadata.json file.

# Cerebro Puppet Module [![Puppet Forge](https://img.shields.io/puppetforge/v/yano3/cerebro.svg?style=flat-square)](https://forge.puppet.com/yano3/cerebro)
# Cerebro Puppet Module
[![Puppet Forge](https://img.shields.io/puppetforge/v/yano3/cerebro.svg?style=flat-square)](https://forge.puppet.com/yano3/cerebro)
[![License](https://img.shields.io/github/license/yano3/puppet-cerebron.svg)](https://github.com/yano3/puppet-cerebro/blob/master/LICENSE)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because who doesn't like badges! :)

# @api private
class cerebro::config
{
$secret = $cerebro::secret
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since the class is private and only ever expected to be declared from the base class, I've moved the variable declarations from being class parameters to being in the body of the class.

Optional[Stdlib::Unixpath] $java_home = $::cerebro::params::java_home,
Optional[Hash] $basic_auth_settings = $::cerebro::params::basic_auth_settings,
Optional[Stdlib::Ip_address] $address = $::cerebro::params::address,
Stdlib::Ensure::Service $service_ensure = $cerebro::params::service_ensure,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note, Stdlib::Ensure::Service doesn't accept Booleans. I could change it to Variant[Stdlib::Ensure::Service, Boolean] if you prefer.

Array[Struct[{
host => Stdlib::HTTPUrl,
name => String[1]
}]] $hosts = $cerebro::params::hosts,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This data type should be correct (and there's a spec test for this). The other advantage of using this data type is that puppet-strings will add it to the reference documentation.

Array[String[1]] $java_opts = $cerebro::params::java_opts,
Optional[Stdlib::Unixpath] $java_home = $cerebro::params::java_home,
Optional[Hash] $basic_auth_settings = $cerebro::params::basic_auth_settings,
Optional[Stdlib::IP::Address] $address = $cerebro::params::address,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stdlib::Ip_address was removed in stdlib 5. Stdlib::IP::Address is available since 4.25.0.

) inherits cerebro::params {

if $manage_user {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I moved the if to the cerebro::user class.

) inherits cerebro::params {

if $manage_user {
contain '::cerebro::user'
contain cerebro::user
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Leading :: is no longer, (since Puppet 4), needed or recommended. See https://github.com/voxpupuli/puppet-lint-absolute_classname-check#relative-class-name-inclusion

content => template('cerebro/etc/tmpfiles.d/cerebro.conf.erb'),
}


if ($::operatingsystem == 'Amazon') {
if $facts['os']['name'] == 'Amazon' {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've replaced legacy facts with modern equivalents (available since Facter 3 which was shipped with puppet 4.2.0).

@@ -14,19 +14,19 @@
"dependencies": [
{
"name": "puppetlabs/stdlib",
"version_requirement": ">= 4.0.0 < 5.0.0"
"version_requirement": ">= 4.25.0 < 6.0.0"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

4.25.0 is needed for Stdlib::IP::Address

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Either that or you can use Stdlib::Compat::IP_address, which was available on earlier versions.

Not sure how it happened, but this issue leaked into my environment. I had to manually patch this module to get it to work. I'll evaluate updating stdlib to 4.25.0 but it will take me some time, since several of our own modules depend on it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not super clear, but I don't think you're supposed to use the compat types generally.
https://github.com/puppetlabs/puppetlabs-stdlib#for-module-developers

After releasing this version, you can release another breaking change release where you remove all compat types and all calls to validate_legacy.

They were just there as a mechanism for moving away from the old validate_x functions.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see, thanks for the clarification!

context 'by default' do
let(:pre_condition) { 'include cerebro' }

# TODO: Verify template contents
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's actually one example of testing template contents below.

end

context 'with hosts set' do
let(:pre_condition) { 'class {\'cerebro\': hosts => [{ "name" => "my_cluster", "host" => "http://127.0.0.1:9200"}] }' }
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is where I test

Array[Struct[{
    host => Stdlib::HTTPUrl,
    name => String[1]
  }]]

@alexjfisher
Copy link
Contributor Author

@yano3 Do you have a travis account? If so, I could add a .travis.yml to enable running of the tests.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants