Commit dd9bda7c authored by Jonathan Gazeley's avatar Jonathan Gazeley
Browse files

Add test suite with retrospec

parent f0d20754
fixtures:
symlinks:
freeradius: "#{source_dir}"
puppet-freeradius: "#{source_dir}"
repositories:
stdlib:
repo: https://github.com/puppetlabs/puppetlabs-stdlib.git
......
*.swp
pkg/
spec/fixures/
.gemfile.lock
.*.sw?
pkg
spec/fixtures
.rspec_system
.vagrant
.bundle
vendor
.idea
.project
.DS_Store
......@@ -3,6 +3,53 @@
# refer to <http://puppet-lint.com/checks/>.
# Examples (uncomment before use):
# spacing, indentation and whitespace
#--no-2sp_soft_tabs-check
#--no-hard_tabs-check
#--no-trailing_whitespace-check
#--no-80chars-check
#--no-arrow_alignment-check
# comments
#--no-slash_comments-check
#--no-star_comments-check
# quoting
#--no-double_quoted_strings-check
#--no-variables_not_enclosed-check
#--no-only_variable_string-check
#--no-single_quote_string_with_variables-check
#--no-quoted_booleans-check
#--no-puppet_url_without_modules-check
# resources
#--no-unquoted_resource_title-check
#--no-ensure_first_param-check
#--no-ensure_not_symlink_target-check
#--no-file_mode-check
#--no-unquoted_file_mode-check
#--no-duplicate_params-check
# conditionals
#--no-selector_inside_resource-check
#--no-case_without_default-check
# classes
#--no-class_inherits_from_params_class-check
#--no-autoloader_layout-check
#--no-right_to_left_relationship-check
#--no-nested_classes_or_defines-check
#--no-inherits_across_namespaces-check
#--no-variable_scope-check
#--no-variable_contains_dash-check
#--no-parameter_order-check
#--no-names_containing_dash-check
# documentation
#--no-documentation-check
# nodes
#--no-unquoted_node_name-check
# For more controls please see http://puppet-lint.com/plugins/
\ No newline at end of file
## Changelog
## Release 0.0.1
### Summary
### 3.6.0
* Add support for Debian 9 (thanks @its-not-a-bug-its-a-feature)
Adds several new features and updates
### 3.5.0
* Add support for huntgroups (thanks @sts and @phaer)
### Features
- Deprecation function X in favor of Y.
- Updated Gemfile to deal with parallel_tests Ruby dependancy
### 3.4.3
* Fix missing notify that caused problems when adding a new virtual server in `sites_available`
### Bugfixes
- README typo fixes.
- Updates deprecation tests to include future parser.
### 3.4.1
* Fix calling syntax for logrotate
* Add param `package_ensure`
### 3.4.0
* Fix bug with modules that have ensure => absent
* Fix bug with module::files where content and source
* Fix bug with path of krb5 module
* Manage parameter `allow_expired_crl`
* Clean up comments in templates to reduce the size
### 3.3.0
* Deploy modules to `mods_available` and symlink to `mods_enabled`
* Deploy modules to `sites_available` and symlink to `sites_enabled`
### 3.2.0
* Warn instead of failing if the FR version is not 3.x
* Update logrotate module dependency
* Add PostgreSQL support
* Fix bug with templating home servers in Puppet 4
* Fix bug with logrotate postrotate on non Red Hat distros
### 3.1.0
* Provide facility to enable/disable specific EAP types in `freeradius::module::eap`
### 3.0.0
* More parameters available for `freeradius::client`
* Allow management of `freeradius::dictionary` with `source` or `content`
* Enable status checks for `freeradius::home_server`
* More configurable options for `freeradius` base class
* More sensible permissions on various config files
* Refactor `freeradius::ldap` as `freeradius::module::ldap` and add more params
* Create `freeradius::listen` to manage arbitrary listeners
* Create `freeradius::module::detail` to configure detail loggers
* Create `freeradius::module::eap` to manage instantiations of the `eap` module
* Create `freeradius::module::files` to manage instantiations of the `files` module
* Create `freeradius::module::huntgroup` to manage huntgroups
* Create `freeradius::module::ippool` to manage ippool resources
* Create `freeradius::module::linelog` to configure linelog loggers
* Create `freeradius::module::preprocess` to manage instantiations of the `preprocess` module
* Fix some compatibility problems with Debian/Ubuntu systems
* Allow `freeradius::site` resources (virtual servers) to have their content managed other than just with flat files
* Add more options to `freeradius::sql`
* Add various types of validation for Puppet 4
### 2.3.1
* Fix bug with log rotation throwing errors when radiusd is not running
### 2.3.0
* Add support to configure virtual modules for fail-over and load-balancing
### 2.2.0
* Add support to configure the krb5 module
### 2.1.4
* Fix compatibility with Puppet 4
### 2.1.3
* Fix compatibility with Puppet 4
### 2.1.2
* Write out ldap config with different syntax for FreeRADIUS 3.0.x and 3.1.x when using multiple servers
### 2.1.1
* Fix bug with the facts not reporting version numbers accurately
### 2.1.0
* Various changes to preserve stock modules in a FreeRADIUS installation and be able to toggle them
### 2.0.1
* Fix up LDAP template to allow better compatibility with FreeRADIUS 3.1.x
### 2.0.0
* Drop support for FreeRADIUS 2.x, enabling us to keep the codebase tidier
### 1.3.0
* Add support for defining config templates
### 1.2.6
* Fix a bug that now enables sqltrace (sqllog) to work on FR3
### 1.2.5
* Switch to use [saz/rsyslog](https://forge.puppetlabs.com/saz/rsyslog) to manage syslog rules
### 1.2.4
* Start with just 1 SQL socket by default to avoid overloading the SQL server
### 1.2.3
* Make facts fail gracefully if radiusd is not installed
### 1.2.2
* Fix a bug that stops statusclients from working
### 1.2.1
* Fix a bug that prevent 1.2.0 from working on FreeRADIUS 2
### 1.2.0
* Deprecate `netmask` parameter from `freeradius::client`
### 1.1.0
* Add support to supply an array of multiple LDAP servers
### 1.0.4
* Make an educated guess about the version of FR when the fact is unavailable (e.g. on the first Puppet run)
### 1.0.3
* Iron out a couple of issues with LDAP compatibility with Active Directory
### 1.0.2
* Fixed a bug that prevented LDAP from working on any port except 389
### 1.0.1
* Fixed a bug that caused an error when no proxy config items were defined
### 1.0.0
* Support for FreeRADIUS 3
* Native support for managing the LDAP module
* Native support for configuring realms (via realms, home_server and home_server_pool)
* Improved handling of attribute filtering
* Improved handling of SQL support
This release retains support for FreeRADIUS 2 but some of the parameters have changed so you will probably need to make changes to the way you use this module. Upgrade on a dev system first!
### 0.4.5
* Tweak wildcard matching on logrotate config
### 0.4.4
* Fix bug displaying deprecation notice and update documentation to reflect this
### 0.4.3
* Manage log rotation with [rodjek/logrotate](https://forge.puppetlabs.com/rodjek/logrotate) instead of deploying flat files
### 0.4.2
* Provide new SQL option custom_query_file
### 0.4.1
* Cease management of custom logging modules `logtofile` and `logtosyslog` since it does not make sense to manage these globally
* Purge instantiation of unused modules
### 0.4.0
* Move control_socket into its own class and add parameters
* Improve the way the status_server is added or removed
* Delete all unmanaged sites from sites-available
### 0.3.8
* Purge all non-managed sites
### 0.3.7
* Minor linting of code to improve score
* Minor linting of metadata to improve score
### 0.3.6
* Bugfixes and feature improvements in `freeradius::sql`
### 0.3.5
* Add ability to customise SQL socket lifetimes
* Purge all non-managed clients
* Add defined type to blank out unneeded config files without deleting them
### 0.3.4
* Correctly pass template content to control-socket
### 0.3.3
* The default behaviour is now to purge anything in ${confdir}/certs that is not managed by Puppet
### 0.3.2
* Various improvements to support Debian family
* Optional content parameters in various resources
### 0.3.1
* Fix a bug which prevents the module from working properly on Debian/Ubuntu (thanks @diranged)
### 0.3.0
* Add `ensure` parameter to all defined types
### 0.2.0
* Add support for customising `sql.conf` natively by adding `freeradius::sql`
### 0.1.4
* Fix ambiguity about net/netmask in freeradius::client
### 0.1.3
* Add support for managing firewall rules automatically
* Add support for installation certificates & keys
* Make syslog support an optional component
* Various bugfixes
### 0.1.2
* Improved modular installs with optional components
* Improved support for Debian
* Clarify dependencies on other modules
* Lots of bugfixes
### 0.1.0
* Initial release with support for installing FreeRADIUS and configuring servers, modules, clients and other objects using flat files.
* Probably works only with FreeRADIUS 2.x
* Only tested with CentOS 6
This changelog is used track changes with this module in human readable format.
Feel free to reference tickets with links or other important information the
reader would find useful when determining the level of risk with upgrading.
For more information on changelogs please [see the keeping a changelog site](http://keepachangelog.com/en/0.3.0/).
\ No newline at end of file
# module name
## Module development setup
Install all the require gems to run test code
```shell
bundle install (only need to do once)
```
## Running Tests
### Unit tests
This type of testing is fast and should be the first thing you do before committing your code. Mistakes can be found
in a matter of seconds vs minutes/hours. You can test your logic in a unit test. The downside is you need to learn
how to write unit tests which can take some initial time getting used to.
```shell
bundle exec rake spec
```
### Integration Testing
This type of testing is somewhat manual and requires the use of vagrant and a test vm that is controlled by vagrant.
You can find the list of available test vms by running `vagrant status` in the root of the module directory. There is
at lot of magic happening in the vagrantfile that makes this easy. Windows support with this module has not been added yet.
```shell
$ vagrant status
Current machine states:
win2012r2 not created (vmware_fusion)
win2008r2 not created (vmware_fusion)
centos6 running (vmware_fusion)
```
To run a test first you need to define the test code located in module_root/tests directory. This code is nothing more
than a bunch of puppet code that uses your manifest code. You will be using puppet apply to run this code on the vm.
Have a look inside the tests directory for examples.
Example test file
```
include profiles::default_linux
file{'/tmp/test.txt':
ensure => file,
content => 'Hello World'
}
```
There are a few ways to run the test code against a test vm, both of which have the same outcome.
```shell
bundle exec rake spec_prep
VAGRANT_MANIFEST=linux.pp vagrant provision centos6
```
or use the rake command which bundles the two commands together
```shell
bundle exec rake "vagrant_up[linux.pp,centos6]"
```
### Acceptance Tests
Acceptance testing is sorta like combining unit testing and integration testing where it tests the code on real systems
automatically across a wide range of operating systems. This is an advanced topic, so you will want to master unit and
integration testing first before writing acceptance tests.
```shell
bundle exec rake beaker
```
## CI config doc
https://gitlab.com/gitlab-org/gitlab-ci-multi-runner/blob/master/docs/configuration/advanced-configuration.md
......@@ -2,19 +2,20 @@ source "https://rubygems.org"
group :test do
gem "rake"
gem "puppet", ENV['PUPPET_VERSION'] || '~> 3.8.3'
gem "rspec-puppet", :git => 'https://github.com/rodjek/rspec-puppet.git'
gem "puppet", ENV['PUPPET_GEM_VERSION'] || '~> 3.8.3'
gem "rspec-puppet"
gem "puppetlabs_spec_helper"
gem 'rspec-puppet-utils', :git => 'https://github.com/Accuity/rspec-puppet-utils.git'
gem 'rspec-puppet-utils'
gem 'hiera-puppet-helper', :git => 'https://github.com/bobtfish/hiera-puppet-helper.git'
gem "metadata-json-lint"
gem 'puppet-syntax'
gem 'puppet-lint'
end
# to disable installing the 50+ gems this group contains run : bundle install --without integration
group :integration do
gem "beaker", :git => 'https://github.com/puppetlabs/beaker.git'
gem "beaker-rspec", :git => 'https://github.com/puppetlabs/beaker-rspec.git'
gem "beaker"
gem "beaker-rspec"
gem "vagrant-wrapper"
gem 'serverspec'
end
......@@ -23,5 +24,7 @@ group :development do
gem "travis"
gem "travis-lint"
gem "puppet-blacksmith"
gem "guard-rake"
gem 'puppet-debugger'
# This gem causes bundler install erorrs
# gem "guard-rake"
end
......@@ -14,7 +14,7 @@ end
PuppetLint.configuration.relative = true
PuppetLint.configuration.send("disable_80chars")
PuppetLint.configuration.log_format = "%{path}:%{linenumber}:%{check}:%{KIND}:%{message}"
PuppetLint.configuration.log_format = "%{path}:%{line}:%{check}:%{KIND}:%{message}"
PuppetLint.configuration.fail_on_warnings = true
# Forsake support for Puppet 2.6.2 for the benefit of cleaner code.
......
......@@ -9,28 +9,28 @@ describe 'freeradius::control_socket' do
# rspec-puppet does not allow you to swap out hiera data on a per test block
#include_context :hiera
# below is the facts hash that gives you the ability to mock
# facts on a per describe/context block. If you use a fact in your
# manifest you should mock the facts below.
let(:facts) do
{}
end
# below is a list of the resource parameters that you can override.
# By default all non-required parameters are commented out,
# while all required parameters will require you to add a value
let(:params) do
{
#:mode => "ro",
# mode: "ro",
}
end
# add these two lines in a single test block to enable puppet and hiera debug mode
# Puppet::Util::Log.level = :debug
# Puppet::Util::Log.newdestination(:console)
it do
is_expected.to contain_freeradius__site('control-socket')
.with(
'content' => 'template(freeradius/sites-enabled/control-socket.erb)'
)
is_expected.to contain_freeradius__site('control-socket').with(
content: [],
)
end
end
This diff is collapsed.
require 'spec_helper'
require 'shared_contexts'
describe 'freeradius::module::preprocess' do
# by default the hiera integration uses hiera data from the shared_contexts.rb file
# but basically to mock hiera you first need to add a key/value pair
# to the specific context in the spec/shared_contexts.rb file
# Note: you can only use a single hiera context per describe/context block
# rspec-puppet does not allow you to swap out hiera data on a per test block
#include_context :hiera
# below is the facts hash that gives you the ability to mock
# facts on a per describe/context block. If you use a fact in your
# manifest you should mock the facts below.
let(:facts) do
{}
end
# below is a list of the resource parameters that you can override.
# By default all non-required parameters are commented out,
# while all required parameters will require you to add a value
let(:params) do
{
# ensure: "present",
# moddir: "${modconfdir}/${.:instance}",
# huntgroups: "${moddir}/huntgroups",
# hints: "${moddir}/hints",
# with_ascend_hack: "no",
# ascend_channels_per_line: "23",
# with_ntdomain_hack: "no",
# with_specialix_jetstream_hack: "no",
# with_cisco_vsa_hack: "no",
}
end
# add these two lines in a single test block to enable puppet and hiera debug mode
# Puppet::Util::Log.level = :debug
# Puppet::Util::Log.newdestination(:console)
it do
is_expected.to contain_freeradius__module('preprocess').with(
ensure: 'present',
content: [],
)
end
end
......@@ -9,13 +9,13 @@ describe 'freeradius::params' do
# rspec-puppet does not allow you to swap out hiera data on a per test block
#include_context :hiera
# below is the facts hash that gives you the ability to mock
# facts on a per describe/context block. If you use a fact in your
# manifest you should mock the facts below.
let(:facts) do
{}
end
# below is a list of the resource parameters that you can override.
# By default all non-required parameters are commented out,
# while all required parameters will require you to add a value
......
......@@ -9,30 +9,29 @@ describe 'freeradius::status_server' do
# rspec-puppet does not allow you to swap out hiera data on a per test block
#include_context :hiera
# below is the facts hash that gives you the ability to mock
# facts on a per describe/context block. If you use a fact in your
# manifest you should mock the facts below.
let(:facts) do
{}
end
# below is a list of the resource parameters that you can override.
# By default all non-required parameters are commented out,
# while all required parameters will require you to add a value
let(:params) do
{
:secret => 'place_value_here',
#:port => "18121",
#:listen => "*",
# port: "18121",
# listen: "*",
}
end
# add these two lines in a single test block to enable puppet and hiera debug mode
# Puppet::Util::Log.level = :debug
# Puppet::Util::Log.newdestination(:console)
it do
is_expected.to contain_freeradius__site('status')
.with(
'content' => 'template(freeradius/sites-enabled/status.erb)'
)
is_expected.to contain_freeradius__site('status').with(
content: [],
)
end
end
......@@ -10,45 +10,48 @@ describe 'freeradius::attr' do
#include_context :hiera
let(:title) { 'XXreplace_meXX' }
# below is the facts hash that gives you the ability to mock
# facts on a per describe/context block. If you use a fact in your
# manifest you should mock the facts below.
let(:facts) do
{}
end
# below is a list of the resource parameters that you can override.
# By default all non-required parameters are commented out,
# while all required parameters will require you to add a value
let(:params) do
{
:source => 'place_value_here',
#:ensure => present,
#:key => "User-Name",
#:prefix => "filter",
source: nil,
# ensure: "present",
# key: "User-Name",
# prefix: "filter",
}
end
# add these two lines in a single test block to enable puppet and hiera debug mode
# Puppet::Util::Log.level = :debug
# Puppet::Util::Log.newdestination(:console)
it do
is_expected.to contain_file('$fr_version ? { 2 => $fr_basepath, 3 => $fr_moduleconfigpath/attr_filter, default => $fr_moduleconfigpath }/XXreplace_meXX')
.with(
'ensure' => 'present',
'group' => '$::osfamily ? { RedHat => radiusd, Debian => freerad, default => radiusd }',
'mode' => '0640',
'notify' => 'Service[$fr_service]',
'owner' => 'root',
'require' => '[Package[$fr_package], Group[$fr_group]]',