Giter Club home page Giter Club logo

puppet-module-test's Introduction

Sample Test Module

Overview

This is a simple Puppet module that aims to provide a simple example of module testing. Included are unit tests and acceptance tests.

Unit tests are used to determine if a catalog can compile and if it looks the way we expect it to with specific parameters.

Acceptance tests are used to determine if applying a module to a system results in the expected state.

This uses rspec-puppet for unit tests and beaker-rspec for acceptance tests.

Relevant resources:

puppetlabs_spec_helper is used to make unit testing more convenient and easy.

Serverspec is what our acceptance tests are written with.

Getting Set Up

Basic Procedure

gem install bundler
bundle install                    # Install the required Rubygems

Running Tests

Unit Tests (rspec-puppet)

bundle exec rake spec

Acceptance Tests (beaker-rspec)

bundle exec rspec spec/acceptance # Acceptance tests (beaker-rspec)

Test it on Ubuntu:

BEAKER_setfile=spec/acceptance/nodesets/ubuntu-server-1404-x64.yml rake beaker

Rake tasks

The following will list some Rake tasks that you might find useful:

rake -T

A couple of useful rake taks for this example:

rake lint    # puppet-lint
rake syntax  # Puppet syntax check (manifests and templates)

Module Boilerplate

###.fixtures

This file defines a "sandbox" for our unit tests. Essentially, any dependencies that our module has will be listed in here so that they can be retrieved and placed in a "sandbox" during our tests. We also list our module here to make it available in the sandbox. See spec/fixtures below.

This is a feature of the puppetlabs_spec_helper

###Gemfile

This file lists what Rubygems are needed for this module's tests. Used with Bundler, this will install the required Gems and their dependencies.

###Rakefile

Provides "tasks" for making running the tests easier. Also specifies which libraries to use for the tests. Sometimes, this can also provide configuration options. In this example module, we pass some puppet-lint options.

###.rspec

Options for rspec. Simple and not required.

###spec/

This directory contains all of our tests and testing data.

###spec/spec_helper.rb

A "helper" for our unit tests. In our case, we're just using the puppetlabs_spec_helper, and this file just requires that.

Think of this as something like a standard library (stdlib) for module testing - useful, reusable code for testing.

###spec/spec_helper_acceptance

Similar to the regular spec_helper file, but this is specifically for our acceptance tests.

###spec/fixtures

This directory isn't directly used by the end user. puppetlabs_spec_helper uses this as a "sandbox" for running tests. See .fixtures above.

This is a feature of the puppetlabs_spec_helper

Acceptance Tests

####spec/acceptance

Our acceptance tests. We use Beaker-rspec for these.

####spec/acceptance/nodesets

Contains files that specify what types of systems should be available for our Beaker tests.

####spec/acceptance/sample_test_spec.rb

This is the main spec test for our module. Refer to Serverspec for information on how to write these tests.

####spec/acceptance/unsupported_spec.rb

This is a test for unsupported platforms. This module isn't actually setup to use this, but it's there for reference. Basically, this should test that the module fails.

Unit Tests

####spec/classes

This contains our unit tests, utilizing rspec-puppet

####spec/classes/sample_test_spec.rb

This is a unit test for our module. You'll notice it contains almost three times as many lines as our module code itself!

Contributions

Contributions are more than welcome. Keep in mind this is supposed to be a fairly simple example ;)

Authors

Josh Beard, [email protected]

puppet-module-test's People

Contributors

joshbeard avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.