• Stars
    star
    112
  • Rank 312,240 (Top 7 %)
  • Language
    Ruby
  • License
    Apache License 2.0
  • Created over 12 years ago
  • Updated over 9 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Run isolated cookbook tests against your chef repository with Strainer.

Strainer

Strainer is a gem for isolating and testing individual chef cookbooks. It allows you to keep all your cookbooks in a single repository (saving you time and money), while having all the benefits of individual repositories.

IMPORTANT! Strainer is no longer maintained as monolithic Chef repositories are no longer recommended. This documentation and repository are kept here for historical reasons.

Usage

First, create a Strainerfile. Cookbook-level Strainerfiles will take precedence over root-level ones. For simplicity, let's just create one in the root of our chef repository:

# Strainerfile
knife test: bundle exec knife cookbook test $COOKBOOK
foodcritic: bundle exec foodcritic -f any cookbooks/$COOKBOOK

Strainerfile exposes two variables:

  • $COOKBOOK - the current running cookbook
  • $SANDBOX - the sandbox path

Just like foreman, the labels don't actually matter - they are only used in formatting the output.

That Strainerfile will run foodcritic and knife test. I recommend this as the bare minimum for a cookbook test.

Strainerfiles commands are run in the context to the sandbox directory. The sandbox is essentially a clone of your working directory. This can be a bit confusing. knife cookbook test requires that you run your command against the "root" directory, yet foodcrtitic and chefspec require you run inside an actual cookbook. Here's a quick example to clear up some confusion:

# Strainerfile
knife test: bundle exec knife cookbook test $COOKBOOK
foodcritic: bundle exec foodcritic -f any $SANDBOX/$COOKBOOK
chefspec:   bundle exec rspec --color
kitchen:    bundle exec kitchen test

To strain, simply run the strainer command and pass in the cookbook(s) to strain:

$ bundle exec strainer test phantomjs tmux

This will first detect the cookbook dependencies, copy the cookbook and all dependencies into a sandbox. It will execute the contents of the Strainerfile on each cookbook.

Standalone

As of 2.0.0, Strainer supports "standalone" mode. This allows you to use Strainer file from within a cookbook. Instead of specifying the path for a cookbook, you just use test

$ bundle exec strainer test

from the root of your cookbook. Note: your cookbook must have it's own Gemfile and working directory.

Running on CI

It's very easy to use Strainer on your CI system. If your cookbook is run on Travis CI, for example, you could use the following .travis.yml file:

rvm:
  - 1.9.3
  - 2.0.0
script: bundle exec strainer test --except kitchen

(Currently test-kitchen cannot be run on Travis, which is why it's skipped)

Berkshelf

Berkshelf is a tool for managing multiple cookbooks. It works very similar to how a Gemfile works with Rubygems. If you're already using Berkshelf, Strainer will work out of the box. If you're not using Berkshelf, Strainer will work out of the box.

Failing Quickly

As of v0.0.4, there's an option for --fail-fast that will fail immediately when any strain command returns a non-zero exit code:

$ bundle exec strainer test phantomjs --fail-fast

This can save time, especially when running tests locally. This is not recommended on continuous integration.

Custom Sandboxes

By default, Strainer uses Dir.mktmpdir to execute your sandbox in. This means the directory is destroyed in due time. However, you can pass the --sandbox option to specify a specific sandbox.

Custom Foodcritic Rules

I always advocate using both Etsy Foodcritic Rules and CustomInk Foodcritic Rules in all your projects. I also advocate keeping them all as submodules in [Chef Repo]/foodcritic/.... This makes strainer unhappy...

Strainer runs everything in an isolated sandbox, inside your Chef Repo. When including additional foodcritic rules, you need to do something like this:

# Strainerfile
foodcritic: bundle exec foodcritic -I foodcritic/* -f any $SANDBOX/$COOKBOOK

Rake Task

Strainer includes a Rake task for convenience:

require 'strainer/rake_task'

Strainer::RakeTask.new(:strainer) do |s|
  s.except = [...]
  s.strainerfile = 'MyStrainerfile'
end

Thor Task

Strainer includes a Thor task for convenience:

require 'strainer/thor'

Strainer::Thor...

Needs Your Help

This is a list of features or problem you can help solve! Fork and submit a pull request to make Strain even better!

  • Threading - Run each cookbook's tests (or each cookbook tests test) in a separate thread

More Repositories

1

lamby

Simple Rails & AWS Lambda Integration 🐑🛤
Ruby
504
star
2

secondbase

Seamless second database integration for Rails.
Ruby
219
star
3

lambdakiq

ActiveJob on SQS & Lambda
Ruby
155
star
4

activerecord-colored_log_subscriber

Colorized SQL Logging Backport for ActiveRecord. See http://git.io/vmlOb
Ruby
92
star
5

activerecord-aurora-serverless-adapter

ActiveRecord Adapter for Amazon Aurora Serverless
Ruby
66
star
6

actionpack-cloudflare

Allow Rails request.remote_ip to defer to CloudFlare's connecting IP.
Ruby
51
star
7

crypteia

Rust Lambda Extension for any Runtime/Container to preload SSM Parameters as 🔐 Secure Environment Variables!
Shell
41
star
8

ruby-vips-lambda

AWS Lambda Layer for Ruby Libvips Gem
Dockerfile
38
star
9

activerecord-collection_cache_key

A Backport of Rails 5's collection cache keys to AR 3 and 4
Ruby
38
star
10

format_for_extensions

Extends ActiveRecord validates_format_of validations with reusable and customizable validation methods.
Ruby
34
star
11

central_log_viewer

Web based log viewer for the Central Logger
Ruby
32
star
12

lamby-cookiecutter

AWS SAM Cookiecutter to Quick Start Rails & Lambda 🐑🛤
HTML
27
star
13

mysql2-lambda

Precompiled Mysql2 Gem for AWS Lambda
Dockerfile
23
star
14

lambda_punch

Asynchronous background job processing for AWS Lambda with Ruby using Lambda Extensions. Inspired by the SuckerPunch gem but specifically tooled to work with Lambda's invoke model.
Ruby
19
star
15

cookiecutter-ruby-workshop

Cookiecutter Ruby - Microservice Workshop
18
star
16

webpack-react-graph

A webpack plugin that generates a graph visualization of a React component tree
JavaScript
16
star
17

signalerjs

JavaScript A/B testing feature flag library
JavaScript
14
star
18

actionpack-cloudfront

Configure ActionDispatch::RemoteIp trusted proxies for Amazon CloudFront.
Ruby
14
star
19

lamby-site

Simple Rails & AWS Lambda Integration 🚂🐑 (PRODUCT SITE)
JavaScript
13
star
20

lambdipy

A tool for building and packaging python packages for AWS Lambda.
Python
13
star
21

nagios-nrpe-check_glusterfs

Fork of Mark Ruys' check_glusterfs from http://exchange.nagios.org/directory/Plugins/System-Metrics/File-System/GlusterFS-checks/details
13
star
22

docker-rails-lambda

A simple Rails Lambda Project on Docker to test Mac filesystems (https://github.com/docker/roadmap/issues/7) benchmarks for the Docker team.
Ruby
11
star
23

ft2-ruby

Freetype2 ruby bindings
C
10
star
24

lambda-python-nltk-layer

Lambda layer to enable using famous NLTK python package with AWS lambda
Shell
10
star
25

codespaces-features

Public Codespaces Scripts/Features
Shell
9
star
26

lamby-rds-proxy

🦎♻️ Simple RDS Proxy Tutorial for Rails & Lambda
TypeScript
8
star
27

aws-embedded-metrics-customink

Amazon CloudWatch Embedded Metric Format Client Library for Ruby.
Ruby
8
star
28

sass_paths

Helper methods to append directories to the SASS_PATH ENV variable
Ruby
7
star
29

signalerjs-react

signalerjs React component for A/B testing
JavaScript
6
star
30

cookiecutter-ruby

Demo AWS SAM Lambda Cookiecutter Ruby Project
Python
6
star
31

capistrano-rollbar-sourcemaps

Uploads sourcemaps to Rollbar as a part of the Capistrano deploy process
Ruby
5
star
32

vertex_client

🧮 A ruby gem to interact with the Vertex Cloud API, which calculates sales tax.
Ruby
5
star
33

astro-devcontainer-example

An example project of how to use local devcontainers with the Astronomer Astro platform
Python
5
star
34

rubyconf5k_2015_results

Results for the 2015 RubyConf 5k in San Antonio, TX
4
star
35

is-it-up

A Ruby gem for adding a simple endpoint to see if your application "is up”.
Ruby
4
star
36

navigation_builder

Just like a Rails FormBuilder, but for Navigation
Ruby
4
star
37

gigo

Garbage in, garbage out. Fix ruby encoded strings at all costs.
Ruby
4
star
38

barcode_input

A Javascript handler for barcode scanner input
CoffeeScript
3
star
39

moxa_11x0

This is an updated driver for the Moxa USB to Serial 11x0 family adapters that runs on Linux kernel 2.6.32 (x86 or x64).
C
3
star
40

subexec-notifications

Instrumentation for Subexec commands using ActiveSupport::Notifications
Ruby
3
star
41

firstgiving_ruby

FirstGiving Ruby Client. Open Source!.
Ruby
2
star
42

nagios-check_s3_LastModified

Checks to see when an object in was last modified, and alerts based on thresholds you set.
Shell
2
star
43

customink.github.io

🐙 📒 CustomInk Technology Blog
HTML
2
star
44

greenscreenapp

A running version of GreenScreen
JavaScript
2
star
45

rolling_travis_builds

Rolling TravisCI Pro Builds - GitHub Webhook Template Application
Ruby
2
star
46

jquery-datalink

Fork of older version of git://github.com/jquery/jquery-datalink.git
JavaScript
2
star
47

homebrew-openssl-1.0

HomeBrew Tap for OpenSSL 1.0
Ruby
2
star
48

lambda_cable

Serverless WebSockets for Rails
Ruby
2
star
49

lamby-vpc

🦾🌎 Simple VPC for RDS Proxy Tutorial with Rails & Lambda
Shell
2
star
50

is_it_ready

Rails Engine for verifying whether applications are able to serve traffic
Ruby
2
star
51

dnd-demo

Docker in Docker Failure Demo
2
star
52

easy_office_map

Open source office map app created during Inkovate 2016 - CustomInk's internal hack-a-thon.
JavaScript
1
star
53

stuffed_bunny

Provides stubbing of the Bunny gem
Ruby
1
star
54

action_parameter_cache

1
star
55

pear-zipcodes-api

HTML
1
star
56

code-challenge

Represent code challenge
JavaScript
1
star
57

lambda-node-canvas-layer

Build and deploy an AWS Lambda layer for using node-canvas
Shell
1
star
58

gigo-activerecord

GIGO for ActiveRecord
Ruby
1
star
59

nagios-check_sftp_file_exist

A nagios check script that tests for the existence of a file on an SFTP server.
Shell
1
star
60

rubyconf5k_2014_results

Results for the 2014 Rubyconf 5k in San Diego
1
star
61

.github

Default Repository to hold the community health guidelines & template files
1
star
62

yaml-data

Safely read CloudFormation YAML data.
JavaScript
1
star
63

minitest-pngdiff

Minitest assertions to test for PNG differences
Ruby
1
star
64

aws-lambda-nodejs-runtime-interface-client-prebuilt

Dockerfile
1
star
65

frontend-gh-actions

Github actions by the frontend team
JavaScript
1
star
66

jekyll_hello_world

A Jekyll hello world for tinkering in AWS
Ruby
1
star