Giter Club home page Giter Club logo

rspec-puppet-facts's Introduction

rspec-puppet-facts

Build Status Code Climate Gem Version Coverage Status

Based on an original idea from apenney.

Simplify your unit tests by looping on every supported Operating System and populating facts.

Before

require 'spec_helper'

describe 'myclass' do

  context "on debian-7-x86_64" do
    let(:facts) do
      {
        :osfamily                  => 'Debian',
        :operatingsystem           => 'Debian',
        :operatingsystemmajrelease => '7',
        ...
      }
      
      it { should compile.with_all_deps }
      ...
    end
  end

  context "on redhat-6-x86_64" do
    let(:facts) do
      {
        :osfamily                  => 'RedHat',
        :operatingsystem           => 'RedHat',
        :operatingsystemmajrelease => '6',
        ...
      }
      
      it { should compile.with_all_deps }
      ...
    end
  end
  
  ...
end

After

require 'spec_helper'

describe 'myclass' do

  on_supported_os.each do |os, facts|
    context "on #{os}" do
      let(:facts) do
        facts
      end
      
      it { should compile.with_all_deps }
      ...
      case facts[:osfamily]
      when 'Debian'
        ...
      when 'RedHat'
        ...
      end
    end
  end
end

By default rspec-puppet-facts looks at your metadata.json to find supported operating systems and tests only with x86_64, but you can specify for each context which ones you want to use:

require 'spec_helper'

describe 'myclass' do

  on_supported_os({
    :hardwaremodels => ['i386', 'x86_64'],
    :supported_os   => [
      {
        "operatingsystem" => "Debian",
        "operatingsystemrelease" => [
          "6",
          "7"
        ]
      },
      {
        "operatingsystem" => "RedHat",
        "operatingsystemrelease" => [
          "5",
          "6"
        ]
      }
    ],
  }).each do |os, facts|
    context "on #{os}" do
      let(:facts) do
        facts
      end
      
      it { should compile.with_all_deps }
      ...
    end
  end
end

Append some facts:

require 'spec_helper'

describe 'myclass' do

  on_supported_os.each do |os, facts|
    context "on #{os}" do
      let(:facts) do
        facts.merge({
          :foo => 'bar',
        })
      end
      
      it { should compile.with_all_deps }
      ...
    end
  end
end

Usage

Add this in your Gemfile:

gem 'rspec-puppet-facts', :require => false

Add this is your spec/spec_helper.rb:

require 'rspec-puppet-facts'
include RspecPuppetFacts

Finaly, Add some facter version to test in your .travis.yml

...
matrix:
  fast_finish: true
  include:
  - rvm: 1.8.7
    env: PUPPET_GEM_VERSION="~> 2.7.0" FACTER_GEM_VERSION="~> 1.6.0"
  - rvm: 1.8.7
    env: PUPPET_GEM_VERSION="~> 2.7.0" FACTER_GEM_VERSION="~> 1.7.0"
  - rvm: 1.9.3
    env: PUPPET_GEM_VERSION="~> 3.0" FACTER_GEM_VERSION="~> 2.1.0"
  - rvm: 1.9.3
    env: PUPPET_GEM_VERSION="~> 3.0" FACTER_GEM_VERSION="~> 2.2.0"
  - rvm: 2.0.0
    env: PUPPET_GEM_VERSION="~> 3.0"
  allow_failures:
    - rvm: 1.8.7
      env: PUPPET_GEM_VERSION="~> 2.7.0" FACTER_GEM_VERSION="~> 1.6.0"
...

Facter versions supported

  • 1.6
  • 1.7
  • 2.0
  • 2.1
  • 2.2
  • 2.3
  • 2.4

Operating Systems supported

  • ArchLinux
  • CentOS 5
  • CentOS 6
  • CentOS 7
  • Debian 6
  • Debian 7
  • Debian 8
  • Fedora 19
  • OpenSuse 12
  • OpenSuse 13
  • Oracle 5
  • Oracle 6
  • Oracle 7
  • RedHat 5
  • RedHat 6
  • RedHat 7
  • Scientific 5
  • Scientific 6
  • Scientific 7
  • SLES 11
  • Ubuntu 10.04
  • Ubuntu 12.04
  • Ubuntu 14.04

Add new Operating System support

There is Vagrantfile to automagically populate facts directory by spawning a new VM and launches a provisioning scripts.

$ cd facts
$ vagrant up --provision

Create i386 facts from x86_64's ones

for file in facts/*/*-x86_64.facts; do cat $file | sed -e 's/x86_64/i386/' -e 's/amd64/i386/' > $(echo $file | sed 's/x86_64/i386/'); done

Create RedHat, Scientific, OracleLinux facts from CentOS's ones

for file in facts/*/centos-*.facts; do cat $file | sed -e 's/CentOS/RedHat/' > $(echo $file | sed 's/centos/redhat/'); done
for file in facts/*/centos-*.facts; do cat $file | sed -e 's/CentOS/Scientific/' > $(echo $file | sed 's/centos/scientific/'); done
for file in facts/*/centos-*.facts; do cat $file | sed -e 's/CentOS/OracleLinux/' > $(echo $file | sed 's/centos/oraclelinux/'); done

rspec-puppet-facts's People

Contributors

mcanevet avatar raphink avatar

Watchers

Frédéric Junod avatar Mathieu Bornoz avatar Christian Kaenzig avatar Vincent Renaville avatar James Cloos avatar Maurer Luc avatar  avatar  avatar

Forkers

coffeecoco

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.