Skip to content

Commit

Permalink
Added tests that validate #159
Browse files Browse the repository at this point in the history
  • Loading branch information
Dylan Ratcliffe committed Mar 8, 2018
1 parent aee1579 commit 22b36cf
Show file tree
Hide file tree
Showing 18 changed files with 214 additions and 1 deletion.
7 changes: 6 additions & 1 deletion features/run.feature
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
@run
Feature: Run rspec and acceptance test suits
Feature: Run rspec and acceptance test suites
Onceover should allow to run rspec and acceptance test for all profvile and role classes
or for any part of them. Use should set if he wants to see only summary of tests or full
log info.
Expand Down Expand Up @@ -41,3 +41,8 @@ Feature: Run rspec and acceptance test suits
And I make local modifications
And I run onceover command "run spec --force"
Then I should see message pattern "Overwriting local modifications"

Scenario: Run correct spec tests
Given control repo "function_mocking"
When I run onceover command "run spec"
Then I should not see any errors
1 change: 1 addition & 0 deletions spec/fixtures/controlrepos/function_mocking/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.onceover
3 changes: 3 additions & 0 deletions spec/fixtures/controlrepos/function_mocking/Gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
source 'https://rubygems.org'

gem 'onceover'
17 changes: 17 additions & 0 deletions spec/fixtures/controlrepos/function_mocking/Puppetfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
forge "http://forge.puppetlabs.com"
#
# I want to download some modules to check if r10k feature in Onceover works correctly.
#

# Versions should be updated to be the latest at the time you start
mod "puppetlabs/stdlib", '4.11.0'

# Modules from Git
# Examples: https://github.com/puppetlabs/r10k/blob/master/doc/puppetfile.mkd#examples
mod 'apache',
:git => 'https://github.com/puppetlabs/puppetlabs-apache',
:commit => '83401079053dca11d61945bd9beef9ecf7576cbf'

#mod 'apache',
# :git => 'https://github.com/puppetlabs/puppetlabs-apache',
# :branch => 'docs_experiment'
1 change: 1 addition & 0 deletions spec/fixtures/controlrepos/function_mocking/Rakefile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
require 'onceover/rake_tasks'
2 changes: 2 additions & 0 deletions spec/fixtures/controlrepos/function_mocking/environment.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
modulepath = site:modules:$basemodulepath
config_version = 'scripts/config_version.sh $environmentpath $environment'
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
---
message: "This node is using common data"
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
---
32 changes: 32 additions & 0 deletions spec/fixtures/controlrepos/function_mocking/manifests/site.pp
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
## site.pp ##

# This file (/etc/puppetlabs/puppet/manifests/site.pp) is the main entry point
# used when an agent connects to a master and asks for an updated configuration.
#
# Global objects like filebuckets and resource defaults should go in this file,
# as should the default node definition. (The default node can be omitted
# if you use the console and don't define any other nodes in site.pp. See
# http://docs.puppetlabs.com/guides/language_guide.html#nodes for more on
# node definitions.)

## Active Configurations ##

# Disable filebucket by default for all File resources:
#https://docs.puppet.com/pe/2015.3/release_notes.html#filebucket-resource-no-longer-created-by-default
File { backup => false }

# DEFAULT NODE
# Node definitions in this file are merged with node data from the console. See
# http://docs.puppetlabs.com/guides/language_guide.html#nodes for more on
# node definitions.

# The default node definition matches any node lacking a more specific node
# definition. If there are no other nodes in this file, classes declared here
# will be included in every node's catalog, *in addition* to any classes
# specified in the console for that node.

node default {
# This is where you can declare classes for all nodes.
# Example:
# class { 'my_class': }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class profile::base {

#the base profile should include component modules that will be on all nodes

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
class profile::example {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
class role::database_server {

#This role would be made of all the profiles that need to be included to make a database server work
#All roles should include the base profile
include profile::base

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
class role::example {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# == Class: role::test_functions
#
class role::test_functions {
unless string('foo') =~ String {
fail('string() did not return a string')
}
unless number('foo') =~ Numeric {
fail('string() did not return a string')
}
unless boolean('foo') =~ Boolean {
fail('string() did not return a string')
}
unless array('foo') =~ Array {
fail('string() did not return a string')
}
unless hash('foo') =~ Hash {
fail('string() did not return a string')
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
class role::webserver {

#This role would be made of all the profiles that need to be included to make a webserver work
#All roles should include the base profile
include profile::base

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Factsets

This directory is where we put any custom factsets that we want to use. They can be generated by running `puppet facts` on the target system.

**Hot tip:** If you already have factsets in here when you run `onceover init` they will be picked up and added to the config file Automatically

More info: https://github.com/dylanratcliffe/onceover#factsets
74 changes: 74 additions & 0 deletions spec/fixtures/controlrepos/function_mocking/spec/onceover.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
# Classes to be tested
classes:
- role::database_server
- role::webserver
- role::example

# Nodes to tests classes on, this refers to a 'factset' or 'nodeset'
# depending on weather you are running 'spec' or 'acceptance' tests
nodes:
- AIX-7.1-powerpc
- SLES-12.1-64
- Debian-6.0.10-32
- CentOS-6.6-64
- Ubuntu-12.04-32
- Ubuntu-12.04-64
- CentOS-6.6-32
- Debian-6.0.10-64
- AIX-6.1-powerpc
- Windows_Server-2012r2-64
- Debian-7.8-32
- Windows_Server-2008r2-64
- SLES-11.3-64
- Debian-7.8-64
- solaris-10_u9-sparc-64
- solaris-11.2-sparc-64
- Ubuntu-14.04-32
- CentOS-5.11-64
- CentOS-5.11-32
- CentOS-7.0-64
- Ubuntu-14.04-64

# You can group classes here to save typing
class_groups:

# You can group nodes here to save typing
# We have created a 'non_windows_nodes' group because we can't
# give you Windows vagrant boxes to test with because licensing,
# we can give you fact sets though so go crazy with spec testing!
node_groups:
windows_nodes:
- Windows_Server-2012r2-64
- Windows_Server-2008r2-64
non_windows_nodes:
include: 'all_nodes'
exclude: 'windows_nodes'

test_matrix:
- all_nodes:
classes: 'all_classes'
tests: 'spec'
- non_windows_nodes:
classes: 'all_classes'
tests: 'acceptance'

functions:
string:
type: rvalue
returns: "string"
number:
type: rvalue
returns: 400
boolean:
type: rvalue
returns: true
array:
type: rvalue
returns:
- 1
- 2
- 3
hash:
type: rvalue
returns:
foo: bar
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Pre Conditions

This folder should contain any \*.pp files that you want to be included in every test.

A common use of this is defining resources that may not exist in the catalog when you are running tests. For example, if we are using a resource that tries to restart the `pe-puppetserver` service, unless it is compiled on a Puppet Maser the `pe-puppetserver` service will not exist and the catalog will fail to compile. To get around this we can create a .pp file and define the resource like so:

``` puppet
# We are not going to actually have this service anywhere on our servers but
# our code needs to refresh it. This is to trick puppet into doing nothing
service { 'pe-puppetserver':
ensure => 'running',
enable => false,
hasrestart => false, # Force Puppet to use start and stop to restart
start => 'echo "Start"', # This will always exit 0
stop => 'echo "Stop"', # This will also always exit 0
hasstatus => false, # Force puppet to use our command for status
status => 'echo "Status"', # This will always exit 0 and therefore Puppet will think the service is running
provider => 'base',
}
```

This will mean that the `pe-puppetserver` service is in the catalog for spec testing and will even allow you to try to restart it during acceptance tests without the service actually being present.

More info: https://github.com/dylanratcliffe/onceover#using-workarounds

0 comments on commit 22b36cf

Please sign in to comment.