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

Bkr 1115 Allow options-file to be configured via ENV #90

Merged
merged 3 commits into from
Oct 2, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 12 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#beaker-rspec
# beaker-rspec

beaker-rspec is a bridge between the puppet acceptance test harness ([beaker](https://github.com/puppetlabs/beaker)) and [rspec](https://github.com/rspec/rspec). It also integrates [serverspec](http://serverspec.org/).

#Upgrading from beaker-rspec 5 to 6
# Upgrading from beaker-rspec 5 to 6

In beaker-rspec 6, we've picked up the newest beaker, 3.y. In this release, we've
given up support for Ruby 1.9 and moved to 2.2.5 as our lowest tested version,
Expand All @@ -13,7 +13,7 @@ To learn more about those changes, please checkout our
doc. Note that besides the Ruby version & beaker dependency change, nothing else
was changed in beaker-rspec itself.

#Typical Workflow
# Typical Workflow

Beaker does setup and provision all nodes from your nodeset on each test run, and cleans up the VMs after use. During development on a module it can be very handy to keep the VMs available for inspection or reuse. Set `BEAKER_destroy=no` do skip the cleanup and `BEAKER_provision=no` once the VMs are created.

Expand All @@ -31,28 +31,29 @@ Beaker does setup and provision all nodes from your nodeset on each test run, an

cd .vagrant/beaker_vagrant_files/default.yml ; vagrant destroy --force

##Supported ENV variables
## Supported ENV variables

* `BEAKER_color`: set to `no` to disable color output
* `BEAKER_debug`: set to any value to enable beaker debug logging
* `BEAKER_destroy`: set to `no` to keep the VMs after the test run. Set to `onpass` to keep the VMs around only after a test failure.
* `BEAKER_keyfile`: specify alternate SSH key to access the test VMs
* `BEAKER_options_file`: set to the file path of the options file to be used as the default options for beaker. Equivalent to the `--options-file` parameter.
* `BEAKER_provision`: set to `no` to skip provisioning boxes before testing, beaker will then assume that boxes are already provisioned and reachable
* `BEAKER_set`: set to the name of the node file to be used during testing (exclude .yml file extension, it will be added by beaker-rspec). The file is assumed to be in module's spec/acceptance/nodesets directory.
* `BEAKER_setfile` - set to the full path to a node file be used during testing (be sure to include full path and file extensions, beaker-rspec will use this path without editing/altering it in any way)

For details on the specific mappings, the [setup code](https://github.com/puppetlabs/beaker-rspec/blob/2771b4b1864692690254a969680a57ff22ac0516/lib/beaker-rspec/spec_helper.rb#L26-L32) and the [beaker docs](https://github.com/puppetlabs/beaker/blob/master/docs/tutorials/the_command_line.md).

#Building your Module Testing Environment
# Building your Module Testing Environment

Using puppetlabs-mysql as an example module.

##Clone the module repository of the module where you want to add tests
## Clone the module repository of the module where you want to add tests

git clone https://github.com/puppetlabs/puppetlabs-mysql
cd puppetlabs-mysql

##Install beaker-rspec
## Install beaker-rspec

In module's top level directory edit the Gemfile. You should see a `:system_tests`
or `:acceptance` group there, but if not, add beaker-rspec there:
Expand All @@ -67,7 +68,7 @@ Then run

bundle install

##Create node files
## Create node files

These files indicate the nodes (or hosts) that the tests will be run on. By default, any node file called `default.yml` will be used. You can override this using the `BEAKER_set` environment variable to indicate an alternate file. Do not provide full path or the '.yml' file extension to `BEAKER_set`, it is assumed to be located in 'spec/acceptance/nodesets/${NAME}.yml' by beaker-rspec. If you wish to use a completely different file location use `BEAKER_setfile` and set it to the full path (including file extension) of your hosts file.

Expand All @@ -83,7 +84,7 @@ Create the nodesets directory. From module's top level directory:

Copy any nodesets that you wish to use into the nodesets directory.

##Create the spec_helper_acceptance.rb
## Create the spec_helper_acceptance.rb

In the `spec` folder, you should see the project's `spec_helper_acceptance.rb`.
This file contains all of the setup logic needed to get your Systems Under Test
Expand Down Expand Up @@ -133,7 +134,7 @@ This method will install the latest puppet-agent from the specified

Update spec_helper_acceptance.rb to reflect the module under test. You will need to set the correct module name and add any module dependencies. Place the file in the `spec` directory (in this case `puppetlabs-mysql/spec`)

##Create spec tests for your module
## Create spec tests for your module

Spec tests are written in [RSpec](http://rspec.info). You can also use [serverspec](http://serverspec.org/) matchers to test [resources](http://serverspec.org/resource_types.html).

Expand Down Expand Up @@ -178,7 +179,7 @@ describe 'mysql::server::account_security class' do
end
```

##Run your spec tests
## Run your spec tests

From module's top level directory

Expand Down
10 changes: 6 additions & 4 deletions lib/beaker-rspec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,19 +30,21 @@
:keyfile => ENV['BEAKER_keyfile'] || ENV['RS_KEYFILE'],
:debug => ENV['BEAKER_debug'] || ENV['RS_DEBUG'],
:destroy => ENV['BEAKER_destroy'] || ENV['RS_DESTROY'],
}.delete_if {|key, value| value.nil?}
#combine defaults and env_vars to determine overall options
options = defaults.merge(env_vars)
:optionsfile => ENV['BEAKER_options_file'] || ENV['RS_OPTIONS_FILE'],
}.delete_if {|key, value| value.nil?}
#combine defaults and env_vars to determine overall options
options = defaults.merge(env_vars)

# process options to construct beaker command string
nodesetfile = options[:nodesetfile] || File.join('spec/acceptance/nodesets',"#{options[:nodeset]}.yml")
fresh_nodes = options[:provision] == 'no' ? '--no-provision' : nil
keyfile = options[:keyfile] ? ['--keyfile', options[:keyfile]] : nil
debug = options[:debug] ? ['--log-level', 'debug'] : nil
color = options[:color] == 'no' ? ['--no-color'] : nil
options_file = options[:optionsfile] ? ['--options-file',options[:optionsfile]] || nil

# Configure all nodes in nodeset
c.setup([fresh_nodes, '--hosts', nodesetfile, keyfile, debug, color].flatten.compact)
c.setup([fresh_nodes, '--hosts', nodesetfile, keyfile, debug, color, options_file]).flatten.compact)
c.provision
c.validate
c.configure
Expand Down