cucumber-puppet 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION.yml ADDED
@@ -0,0 +1,5 @@
1
+ ---
2
+ :build:
3
+ :patch: 2
4
+ :minor: 0
5
+ :major: 0
@@ -0,0 +1,28 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ unless ARGV[0]
4
+ puts "Usage: cucumber-puppet <feature> [<feature> <feature> ...]"
5
+ exit 1
6
+ end
7
+
8
+ ARGV.each { |f|
9
+ unless File.exists?(f)
10
+ puts "No such file or directory: #{f}"
11
+ exit 1
12
+ end
13
+ }
14
+
15
+ # XXX be more creative, finding this directory
16
+ features_dir = "features"
17
+ unless File.directory?(features_dir)
18
+ puts "Cannot find '#{features_dir}' directory."
19
+ exit 1
20
+ end
21
+
22
+ command = ""
23
+ command << "cucumber "
24
+ command << "--strict "
25
+ command << "--require #{features_dir} "
26
+ command << ARGV.join(' ')
27
+
28
+ system(command) ? exit(0) : exit(1)
@@ -0,0 +1,54 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'rubygems'
4
+ require 'cucumber-puppet'
5
+ require 'templater'
6
+
7
+ module CucumberPuppetGenerators
8
+
9
+ extend Templater::Manifold
10
+
11
+ class FeatureGenerator < Templater::Generator
12
+ def source_root
13
+ File.join(File.dirname(__FILE__), '..', 'lib', 'generators', 'feature')
14
+ end
15
+
16
+ desc <<-DESC
17
+ Generate a cucumber feature.
18
+ cucumber-puppet-gen feature <module-name> <feature-name>
19
+ DESC
20
+
21
+ first_argument :mod, :required => true, :desc => "Module name"
22
+ second_argument :feature, :required => true, :desc => "Feature name"
23
+
24
+ template :feature do |template|
25
+ template.source = "%feature_name%.feature"
26
+ template.destination = "features/modules/#{mod}/#{feature}.feature"
27
+ end
28
+ end
29
+
30
+ class WorldGenerator < Templater::Generator
31
+ def source_root
32
+ File.join(File.dirname(__FILE__), '..', 'lib', 'generators', 'world')
33
+ end
34
+
35
+ def destination_root
36
+ File.join(@destination_root, 'features')
37
+ end
38
+
39
+ desc <<-DESC
40
+ Generate cucumber step and support files.
41
+ cucumber-puppet-gen world
42
+ DESC
43
+
44
+ directory('steps', 'steps')
45
+ directory('support', 'support')
46
+ end
47
+
48
+ desc "Generators for cucumber-puppet"
49
+ add :feature, FeatureGenerator
50
+ add :world, WorldGenerator
51
+
52
+ end
53
+
54
+ CucumberPuppetGenerators.run_cli Dir.pwd, 'cucumber-puppet-gen', CucumberPuppet::VERSION, ARGV
@@ -0,0 +1,6 @@
1
+ require 'yaml'
2
+
3
+ class CucumberPuppet
4
+ version = YAML.load_file(File.dirname(__FILE__) + '/../VERSION.yml')
5
+ VERSION = [version[:major], version[:minor], version[:patch], version[:build]].compact.join('.')
6
+ end
@@ -0,0 +1,60 @@
1
+ require 'puppet'
2
+ require 'puppet/network/client'
3
+
4
+ class CucumberPuppet
5
+ def initialize
6
+ @confdir = "/etc/puppet"
7
+ @manifest = @confdir + "/manifest/site.pp"
8
+
9
+ # default facts
10
+ @facts = {
11
+ 'architecture' => "",
12
+ 'domain' => "no.domain",
13
+ 'environment' => "production",
14
+ 'hostname' => "testnode",
15
+ 'lsbdistcodename' => "",
16
+ 'network_eth0' => "127.0.0.0",
17
+ 'operatingsystem' => "",
18
+ }
19
+
20
+ Puppet::Util::Log.newdestination(:console)
21
+ Puppet::Util::Log.level = :notice
22
+ end
23
+
24
+ def debug
25
+ Puppet::Util::Log.level = :debug
26
+ end
27
+
28
+ def klass=(klass)
29
+ @klass = klass.to_a
30
+ end
31
+
32
+ def compile_catalog
33
+ Puppet[:confdir] = @confdir
34
+ Puppet[:manifest] = @manifest
35
+ Puppet.parse_config
36
+
37
+ node = Puppet::Node.new(@facts['hostname'], :classes => @klass)
38
+ node.merge(@facts)
39
+
40
+ begin
41
+ # Compile our catalog
42
+ @catalog = Puppet::Node::Catalog.find(node.name, :use_node => node)
43
+ rescue => detail
44
+ if Puppet[:trace]
45
+ puts detail.backtrace
46
+ end
47
+ if detail.is_a?(XMLRPC::FaultException)
48
+ $stderr.puts detail.message
49
+ else
50
+ $stderr.puts detail
51
+ end
52
+ exit 1
53
+ end
54
+ end
55
+
56
+ def resource(title)
57
+ resource = @catalog.resource(title)
58
+ return resource
59
+ end
60
+ end
@@ -0,0 +1,9 @@
1
+ Feature: <%= feature %>
2
+ In order to <business value>
3
+ As a <role>
4
+ I want <something to happen / do something>
5
+
6
+ Scenario: <title>
7
+ Given a node of class ""
8
+ When I compile the catalog
9
+ Then
@@ -0,0 +1,29 @@
1
+ Then /^the file should be a symlink to "([^\"]*)"$/ do |target|
2
+ fail unless @resource["ensure"] == target
3
+ end
4
+
5
+ Then /^the file should contain "([^\"]*)"$/ do |text|
6
+ fail unless @resource["content"].include?(text)
7
+ end
8
+
9
+ Then /^the (file|script) should have standard permissions$/ do |type|
10
+ if type == "file"
11
+ mode = "0444"
12
+ elsif type == "script"
13
+ mode = "0555"
14
+ end
15
+
16
+ steps %Q{
17
+ Then the file should have a "group" of "root"
18
+ And the file should have a "mode" of "#{mode}"
19
+ And the file should have an "owner" of "root"
20
+ }
21
+ end
22
+
23
+ Then /^there should be a (file|script) "([^\"]*)"$/ do |type, name|
24
+ steps %Q{
25
+ Then there should be a resource "File[#{name}]"
26
+ And the state should be "present"
27
+ And the #{type} should have standard permissions
28
+ }
29
+ end
@@ -0,0 +1,14 @@
1
+ Then /^package "([^\"]*)" should be "([^\"]*)"$/ do |package, state|
2
+ steps %Q{
3
+ Then there should be a resource "Package[#{package}]"
4
+ And the state should be "#{state}"
5
+ And the package should require "Exec[update_apt]"
6
+ }
7
+ end
8
+
9
+
10
+ Then /^package "([^\"]*)" should not be installed$/ do |package|
11
+ steps %Q{
12
+ Then there should be no resource "Package[#{package}]"
13
+ }
14
+ end
@@ -0,0 +1,65 @@
1
+ Given /^a node of class "([^\"]*)"$/ do |klass|
2
+ @klass = klass
3
+ end
4
+
5
+ Given /^a node named "([^\"]*)"$/ do |name|
6
+ @facts['hostname'] = name
7
+ end
8
+
9
+ Given /^a node in network "([^\"]*)"$/ do |network|
10
+ @facts['network_eth0'] = network
11
+ end
12
+
13
+ Given /^it is a virtual node$/ do
14
+ @facts['processor0'] = "QEMU Virtual CPU version 0.11.0"
15
+ end
16
+
17
+ When /^I compile the catalog$/ do
18
+ compile_catalog
19
+ end
20
+
21
+ Then /^the [a-z]* should have "([^\"]*)" set to "(false|true)"$/ do |res, bool|
22
+ if bool == "false"
23
+ fail unless @resource[res] == false
24
+ else
25
+ fail unless @resource[res] == true
26
+ end
27
+ end
28
+
29
+ Then /^the [a-z]* should have an? "([^\"]*)" of "([^\"]*)"$/ do |property, value|
30
+ fail unless @resource[property] == value
31
+ end
32
+
33
+ Then /^the [a-z]* should notify "([^\"]*)"$/ do |res|
34
+ fail unless @resource["notify"].to_s == res
35
+ end
36
+
37
+ Then /^the [a-z]* should require "([^\"]*)"$/ do |resource|
38
+ req = @resource["require"]
39
+ if req.is_a?(Array)
40
+ found = false
41
+ req.each do |r|
42
+ if r.to_s == resource
43
+ found = true
44
+ break
45
+ end
46
+ end
47
+ fail unless found
48
+ else
49
+ fail unless req.to_s == resource
50
+ end
51
+ end
52
+
53
+ Then /^the state should be "([^\"]*)"$/ do |state|
54
+ fail unless @resource["ensure"] == state
55
+ end
56
+
57
+ Then /^there should be a resource "([^\"]*)"$/ do |res|
58
+ @resource = resource(res)
59
+ fail unless @resource
60
+ end
61
+
62
+ Then /^there should be no resource "([^\"]*)"$/ do |res|
63
+ @resource = resource(res)
64
+ fail if @resource
65
+ end
@@ -0,0 +1,14 @@
1
+ Then /^service "([^\"]*)" should be "([^\"]*)"$/ do |name, state|
2
+ steps %Q{
3
+ Then there should be a resource "Service[#{name}]"
4
+ }
5
+ if state == "disabled"
6
+ steps %Q{
7
+ Then the service should have "enable" set to "false"
8
+ }
9
+ elsif state == "running"
10
+ steps %Q{
11
+ Then the state should be "#{state}"
12
+ }
13
+ end
14
+ end
@@ -0,0 +1,3 @@
1
+ Then /^the user should be in groups "([^\"]*)"$/ do |groups|
2
+ fail unless @resource["groups"] == groups
3
+ end
@@ -0,0 +1,6 @@
1
+ Before do
2
+ # local configuration
3
+ @confdir = File.dirname(__FILE__) + "/../../"
4
+ # adjust facts like this
5
+ @facts['architecture'] = "i386"
6
+ end
@@ -0,0 +1,5 @@
1
+ require 'cucumber-puppet/puppet'
2
+
3
+ World do
4
+ CucumberPuppet.new
5
+ end
metadata ADDED
@@ -0,0 +1,101 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: cucumber-puppet
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 0
8
+ - 2
9
+ version: 0.0.2
10
+ platform: ruby
11
+ authors:
12
+ - Nikolay Sturm
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2010-04-17 00:00:00 +02:00
18
+ default_executable:
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: cucumber
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - ">="
26
+ - !ruby/object:Gem::Version
27
+ segments:
28
+ - 0
29
+ - 6
30
+ - 4
31
+ version: 0.6.4
32
+ type: :runtime
33
+ version_requirements: *id001
34
+ - !ruby/object:Gem::Dependency
35
+ name: templater
36
+ prerelease: false
37
+ requirement: &id002 !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - ">="
40
+ - !ruby/object:Gem::Version
41
+ segments:
42
+ - 1
43
+ - 0
44
+ version: "1.0"
45
+ type: :runtime
46
+ version_requirements: *id002
47
+ description: cucumber-puppet allows you writing behavioural tests for your puppet manifest
48
+ email: cucumber-puppet@erisiandiscord.de
49
+ executables:
50
+ - cucumber-puppet
51
+ - cucumber-puppet-gen
52
+ extensions: []
53
+
54
+ extra_rdoc_files: []
55
+
56
+ files:
57
+ - bin/cucumber-puppet
58
+ - bin/cucumber-puppet-gen
59
+ - lib/cucumber-puppet.rb
60
+ - lib/cucumber-puppet/puppet.rb
61
+ - lib/generators/feature/%feature_name%.feature
62
+ - lib/generators/world/steps/file.rb
63
+ - lib/generators/world/steps/package.rb
64
+ - lib/generators/world/steps/puppet.rb
65
+ - lib/generators/world/steps/service.rb
66
+ - lib/generators/world/steps/user.rb
67
+ - lib/generators/world/support/hooks.rb
68
+ - lib/generators/world/support/world.rb
69
+ - VERSION.yml
70
+ has_rdoc: true
71
+ homepage: http://github.com/nistude/cucumber-puppet/
72
+ licenses: []
73
+
74
+ post_install_message:
75
+ rdoc_options: []
76
+
77
+ require_paths:
78
+ - lib
79
+ required_ruby_version: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - ">="
82
+ - !ruby/object:Gem::Version
83
+ segments:
84
+ - 0
85
+ version: "0"
86
+ required_rubygems_version: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - ">="
89
+ - !ruby/object:Gem::Version
90
+ segments:
91
+ - 0
92
+ version: "0"
93
+ requirements: []
94
+
95
+ rubyforge_project:
96
+ rubygems_version: 1.3.6
97
+ signing_key:
98
+ specification_version: 3
99
+ summary: Puppet manifest testing with Cucumber
100
+ test_files: []
101
+