summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergey Stankevich <stankevich@users.noreply.github.com>2014-07-27 11:48:56 -0400
committerSergey Stankevich <stankevich@users.noreply.github.com>2014-07-27 11:48:56 -0400
commitb779d0d0e2d11471241f647c96e6f91683d3c5a0 (patch)
tree628a42d51c3f2a79ae8aaae7e218078392faef27
parentf9a04de1d66be8a05c479d18796b8272b3313653 (diff)
parent62be88b026e19e1750deaf5cf81b3f9519ff651a (diff)
Merge pull request #99 from daniellawrence/rspec
Getting started with basic rspec
-rw-r--r--.fixtures.yml6
-rw-r--r--.travis.yml23
-rw-r--r--Gemfile25
-rw-r--r--Rakefile2
-rw-r--r--spec/classes/python_spec.rb228
-rw-r--r--spec/defines/requirements_spec.rb53
-rw-r--r--spec_helper.rb25
7 files changed, 362 insertions, 0 deletions
diff --git a/.fixtures.yml b/.fixtures.yml
new file mode 100644
index 0000000..6dcef97
--- /dev/null
+++ b/.fixtures.yml
@@ -0,0 +1,6 @@
+ fixtures:
+ repositories:
+ stdlib: "git://github.com/puppetlabs/puppetlabs-stdlib.git"
+# concat: "git://github.com/puppetlabs/puppetlabs-concat.git"
+ symlinks:
+ python: "#{source_dir}" \ No newline at end of file
diff --git a/.travis.yml b/.travis.yml
new file mode 100644
index 0000000..f6cc003
--- /dev/null
+++ b/.travis.yml
@@ -0,0 +1,23 @@
+---
+language: ruby
+bundler_args: --without development
+script: "bundle exec rake validate && bundle exec rake lint && bundle exec rake spec SPEC_OPTS='--format documentation'"
+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"
+ - rvm: 2.0.0
+ env: PUPPET_GEM_VERSION="~> 3.0"
+ - rvm: 1.9.3
+ env: PUPPET_GEM_VERSION="~> 3.5.0" STRICT_VARIABLES="yes"
+ - rvm: 2.0.0
+ env: PUPPET_GEM_VERSION="~> 3.5.0" STRICT_VARIABLES="yes"
+ - rvm: 2.0.0
+ env: PUPPET_GEM_VERSION="~> 3.6.2" STRICT_VARIABLES="yes"
+notifications:
+ email: false \ No newline at end of file
diff --git a/Gemfile b/Gemfile
new file mode 100644
index 0000000..60f5f8d
--- /dev/null
+++ b/Gemfile
@@ -0,0 +1,25 @@
+source ENV['GEM_SOURCE'] || "https://rubygems.org"
+
+group :development, :test do
+ gem 'rake', :require => false
+ gem 'rspec-puppet', :require => false
+ gem 'puppetlabs_spec_helper', :require => false
+ gem 'serverspec', :require => false
+ gem 'puppet-lint', :require => false
+ gem 'beaker', :require => false
+ gem 'beaker-rspec', :require => false
+ gem 'pry', :require => false
+ gem 'simplecov', :require => false
+end
+
+if facterversion = ENV['FACTER_GEM_VERSION']
+ gem 'facter', facterversion, :require => false
+else
+ gem 'facter', :require => false
+end
+
+if puppetversion = ENV['PUPPET_GEM_VERSION']
+ gem 'puppet', puppetversion, :require => false
+else
+ gem 'puppet', :require => false
+end
diff --git a/Rakefile b/Rakefile
index 58df3ec..b133dff 100644
--- a/Rakefile
+++ b/Rakefile
@@ -6,3 +6,5 @@ PuppetLint.configuration.with_filename = true
PuppetLint.configuration.send('disable_documentation')
PuppetLint.configuration.send('disable_class_parameter_defaults')
PuppetLint.configuration.send('disable_80chars')
+
+require 'puppetlabs_spec_helper/rake_tasks'
diff --git a/spec/classes/python_spec.rb b/spec/classes/python_spec.rb
new file mode 100644
index 0000000..9552ce4
--- /dev/null
+++ b/spec/classes/python_spec.rb
@@ -0,0 +1,228 @@
+require_relative '../../spec_helper'
+
+describe 'python', :type => :class do
+ context "on Debian OS" do
+ let :facts do
+ {
+ :id => 'root',
+ :kernel => 'Linux',
+ :lsbdistcodename => 'squeeze',
+ :osfamily => 'Debian',
+ :operatingsystem => 'Debian',
+ :operatingsystemrelease => '6',
+ :path => '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin',
+ :concat_basedir => '/dne',
+ }
+ end
+
+ it { is_expected.to contain_class("python::install") }
+ # Base debian packages.
+ it { is_expected.to contain_package("python") }
+ it { is_expected.to contain_package("python-dev") }
+ it { is_expected.to contain_package("python-pip") }
+ # Basic python packages (from pip)
+ it { is_expected.to contain_package("python-virtualenv")}
+
+ describe "with python::dev" do
+ context "true" do
+ let (:params) {{ :dev => true }}
+ it { is_expected.to contain_package("python-dev").with(
+ "ensure" => "present")
+ }
+ end
+ context "empty/default" do
+ it { is_expected.to contain_package("python-dev").with(
+ "ensure" => "absent")
+ }
+ end
+ end
+
+
+ describe "with manage_gunicorn" do
+ context "true" do
+ let (:params) {{ :manage_gunicorn => true }}
+ it { is_expected.to contain_package("gunicorn") }
+ end
+ context "empty args" do
+ #let (:params) {{ :manage_gunicorn => '' }}
+ it { is_expected.to contain_package("gunicorn") }
+ end
+ context "false" do
+ let (:params) {{ :manage_gunicorn => false }}
+ it {is_expected.not_to contain_package("gunicorn")}
+ end
+ end
+
+ describe "with python::provider" do
+ context "pip" do
+ let (:params) {{ :provider => 'pip' }}
+ it { is_expected.to contain_package("virtualenv").with(
+ "provider" => "pip"
+ )}
+ it { is_expected.to contain_package("pip").with(
+ "provider" => "pip"
+ )}
+ end
+
+ # python::provider
+ context "default" do
+ let (:params) {{ :provider => '' }}
+ it { is_expected.to contain_package("python-virtualenv")}
+ it { is_expected.to contain_package("python-pip")}
+
+ describe "with python::virtualenv" do
+ context "true" do
+ let (:params) {{
+ :provider => '',
+ :virtualenv => true
+ }}
+ it { is_expected.to contain_package("python-virtualenv").with(
+ "ensure" => "present"
+ )}
+ end
+ end
+
+ describe "with python::virtualenv" do
+ context "default/empty" do
+ let (:params) {{
+ :provider => '',
+ :virtualenv => ''
+ }}
+ it { is_expected.to contain_package("python-virtualenv").with(
+ "ensure" => "absent"
+ )}
+ end
+ end
+
+
+ end
+ end
+
+ describe "with python::dev" do
+ context "true" do
+ let (:params) {{ :dev => true }}
+ it { is_expected.to contain_package("python-dev").with(
+ "ensure" => "present")
+ }
+ end
+ context "default/empty" do
+ let (:params) {{ :dev => '' }}
+ it { is_expected.to contain_package("python-dev").with(
+ "ensure" => "absent")
+ }
+ end
+
+ end
+
+ context "on a Redhat 5 OS" do
+ let :facts do
+ {
+ :id => 'root',
+ :kernel => 'Linux',
+ :osfamily => 'RedHat',
+ :operatingsystem => 'RedHat',
+ :operatingsystemrelease => '5',
+ :concat_basedir => '/dne',
+ :path => '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin',
+ }
+ end
+ it { is_expected.to contain_class("python::install") }
+ # Base debian packages.
+ it { is_expected.to contain_package("python") }
+ it { is_expected.to contain_package("python-devel") }
+ it { is_expected.to contain_package("python-pip") }
+ # Basic python packages (from pip)
+ it { is_expected.to contain_package("python-virtualenv")}
+
+ describe "with python::dev" do
+ context "true" do
+ let (:params) {{ :dev => true }}
+ it { is_expected.to contain_package("python-devel").with(
+ "ensure" => "present")
+ }
+ end
+ context "empty/default" do
+ it { is_expected.to contain_package("python-devel").with(
+ "ensure" => "absent")
+ }
+ end
+ end
+
+
+ describe "with manage_gunicorn" do
+ context "true" do
+ let (:params) {{ :manage_gunicorn => true }}
+ it { is_expected.to contain_package("gunicorn") }
+ end
+ context "empty args" do
+ #let (:params) {{ :manage_gunicorn => '' }}
+ it { is_expected.to contain_package("gunicorn") }
+ end
+ context "false" do
+ let (:params) {{ :manage_gunicorn => false }}
+ it {is_expected.not_to contain_package("gunicorn")}
+ end
+ end
+
+ describe "with python::provider" do
+ context "pip" do
+ let (:params) {{ :provider => 'pip' }}
+ it { is_expected.to contain_package("virtualenv").with(
+ "provider" => "pip"
+ )}
+ it { is_expected.to contain_package("pip").with(
+ "provider" => "pip"
+ )}
+ end
+
+ # python::provider
+ context "default" do
+ let (:params) {{ :provider => '' }}
+ it { is_expected.to contain_package("python-virtualenv")}
+ it { is_expected.to contain_package("python-pip")}
+
+ describe "with python::virtualenv" do
+ context "true" do
+ let (:params) {{
+ :provider => '',
+ :virtualenv => true
+ }}
+ it { is_expected.to contain_package("python-virtualenv").with(
+ "ensure" => "present"
+ )}
+ end
+ end
+
+ describe "with python::virtualenv" do
+ context "default/empty" do
+ let (:params) {{
+ :provider => '',
+ :virtualenv => ''
+ }}
+ it { is_expected.to contain_package("python-virtualenv").with(
+ "ensure" => "absent"
+ )}
+ end
+ end
+
+
+ end
+ end
+
+ describe "with python::dev" do
+ context "true" do
+ let (:params) {{ :dev => true }}
+ it { is_expected.to contain_package("python-devel").with(
+ "ensure" => "present")
+ }
+ end
+ context "default/empty" do
+ let (:params) {{ :dev => '' }}
+ it { is_expected.to contain_package("python-devel").with(
+ "ensure" => "absent")
+ }
+ end
+ end
+ end
+ end
+end
diff --git a/spec/defines/requirements_spec.rb b/spec/defines/requirements_spec.rb
new file mode 100644
index 0000000..f8144f3
--- /dev/null
+++ b/spec/defines/requirements_spec.rb
@@ -0,0 +1,53 @@
+require_relative '../../spec_helper'
+
+describe 'python::requirements', :type => :define do
+ let (:title) { '/requirements.txt' }
+ context "on Debian OS" do
+ let :facts do
+ {
+ :id => 'root',
+ :kernel => 'Linux',
+ :lsbdistcodename => 'squeeze',
+ :osfamily => 'Debian',
+ :operatingsystem => 'Debian',
+ :operatingsystemrelease => '6',
+ :path => '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin',
+ :concat_basedir => '/dne',
+ }
+ end
+
+ describe "requirements as" do
+ context "/requirements.txt" do
+ let (:params) {{ :requirements => "/requirements.txt" }}
+ it { is_expected.to contain_file("/requirements.txt").with(
+ "mode" => "0644"
+
+ )}
+ end
+
+ describe "with owner" do
+ context "bob:bob" do
+ let (:params) {{
+ :owner => 'bob',
+ :group => 'bob'
+ }}
+ it do
+ expect {
+ should compile
+ }.to raise_error(Puppet::Error, /root user must be used when virtualenv is system/)
+ end
+
+ end
+ end
+
+ describe "with owner" do
+ context "default" do
+ it { is_expected.to contain_file("/requirements.txt").with(
+ "owner" => "root",
+ "group" => "root"
+ )}
+ end
+ end
+ end
+ end
+end
diff --git a/spec_helper.rb b/spec_helper.rb
new file mode 100644
index 0000000..65379ee
--- /dev/null
+++ b/spec_helper.rb
@@ -0,0 +1,25 @@
+require 'puppetlabs_spec_helper/module_spec_helper'
+
+RSpec.configure do |c|
+ c.treat_symbols_as_metadata_keys_with_true_values = true
+
+ c.before :each do
+ # Ensure that we don't accidentally cache facts and environment
+ # between test cases.
+ Facter::Util::Loader.any_instance.stubs(:load_all)
+ Facter.clear
+ Facter.clear_messages
+
+ # Store any environment variables away to be restored later
+ @old_env = {}
+ ENV.each_key {|k| @old_env[k] = ENV[k]}
+
+ if ENV['STRICT_VARIABLES'] == 'yes'
+ Puppet.settings[:strict_variables]=true
+ end
+ end
+end
+
+shared_examples :compile, :compile => true do
+ it { should compile.with_all_deps }
+end