Coder Social home page Coder Social logo

puppet_spec_facts's Introduction

PuppetSpecFacts

Build Status Code Climate Coverage Status Dependency Status Gem Version

This gem provides facts for rspec-puppet, much like apenny/puppet_facts but targeted toward open source puppet whereas puppet_facts seems to be aimed at Puppet Enterprise.

This project is very (very) new. If you're successful in using it (or not) I'd really appreciate feedback.

Puppet module developers (should) use rspec-puppet to validate conditional logic. One of the most common forms of conditional logic is to change behavior based on operating system or linux distribution. Unfortunately, most rspec-puppet tests only include a handful of relevant facts from one or two popular Linux distributions. This gem is intended to provide a flexible way to iterate across platforms with full facter facts.

In order to be useful, this needs a wide range of facts from different platforms. You can help by making pull requests, or by submitting facts to facts.whilefork.com via HTTP POST:

facter --json | curl -H "Content-Type: application/json" -d @- http://facts.whilefork.com

Installation

Add this line to your puppet module's Gemfile:

    gem 'puppet_spec_facts'

Add these lines to your spec/spec_helper.rb file:

    require 'puppet_spec_facts'
    include PuppetSpecFacts

Usage

The code below doesn't quite work yet, so wait for an update on this before trying to use it.

To iterate through all available fact sets, do something like the following in your spec file:

require 'spec_helper'
include PuppetSpecFacts # shown here, but should be included from spec_helper.rb

describe 'example' do
  context 'all operating systems' do
    PuppetSpecFacts.puppet_platforms.each do |name, facthash|
    # at this point, name is a human-readable string like:
    # FreeBSD_10.0-RELEASE_amd64_3.6.2_structured
    # Debian_wheezy_7.7_i386_PE-3.3.2_stringified
    # CentOS_5.11_x86_64_3.7.1_structured
    # etc
      describe "example class without any parameters on #{name}" do
        let(:params) {{ }}
        let(:facts) { facthash } # the fact hash from puppet_spec_facts is now available for rspec tests

        it { should compile.with_all_deps }
      end
    end
  end
end

In the real world, you probably don't want to iterate through all of the platforms, so puppet_spec_facts allows you to query a subset based on facter facts:

require 'spec_helper'

describe 'example' do
  context 'all operating systems' do
    PuppetSpecFacts.facts_for_platform_by_fact(
      select_facts: {
        'lsbdistid' => 'CentOS',
        'architecture' => 'x86_64',
        'is_pe' => 'true',
        'fact_style' => 'stringified'
    }) do |name, facthash|
    # This loads all fact sets for Puppet Enterprise on x86_64 CentOS with stringified-style facts
      describe "example class without any parameters on #{name}" do
        let(:params) {{ }}
        let(:facts) { facthash } # the facter output you sent in above is now available in rspec

        it { should compile.with_all_deps }
      end
    end
  end
end

In many cases, this will provide too many results. You can constrain the results further by using the select_facts parameter to indicate the general set, then the unique_selector parameter to only return one result for the parameters specified in unique_selector. For example, you may wish to only get one result per operatingsystemrelease fact, to avoid testing

puppet_spec_facts's People

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

mcanevet fuero

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.