fizzgig 0.3.0 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.md +15 -0
- data/README.asciidoc +7 -3
- data/TODO.org +1 -0
- data/fizzgig.gemspec +2 -1
- data/lib/fizzgig.rb +29 -25
- data/lib/fizzgig/function_stubs.rb +22 -21
- data/spec/example_spec.rb +2 -1
- data/spec/fizzgig_spec.rb +4 -3
- data/spec/spec_helper.rb +4 -4
- data/test/example_test.rb +19 -0
- metadata +20 -3
- data/lib/fizzgig/matchers.rb +0 -81
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,18 @@
|
|
1
|
+
# 0.4.0
|
2
|
+
* Changed configuration style:
|
3
|
+
* Removed RSpec.configure interface
|
4
|
+
* Added OO interface to Fizzgig to allow storing configuration in
|
5
|
+
the Fizzgig instance
|
6
|
+
* Removed RSpec matchers; you can use the matchers from rspec-puppet
|
7
|
+
instead:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
require 'rspec-puppet/matchers'
|
11
|
+
RSpec.configure do |c|
|
12
|
+
c.include RSpec::Puppet::ManifestMatchers
|
13
|
+
end
|
14
|
+
```
|
15
|
+
|
1
16
|
# 0.3.0
|
2
17
|
|
3
18
|
* Changed API for #instantiate to take ruby Hash of params rather
|
data/README.asciidoc
CHANGED
@@ -5,8 +5,12 @@ Fizzgig is a library to help write fast unit tests.
|
|
5
5
|
|
6
6
|
[source,ruby]
|
7
7
|
-------------------------------------------
|
8
|
+
require 'spec_helper'
|
9
|
+
require 'fizzgig'
|
10
|
+
|
8
11
|
describe 'nginx::site' do
|
9
|
-
|
12
|
+
let(:fizzgig) { Fizzgig.new({modulepath:MODULEPATH,manifestdir:MANIFESTDIR}) }
|
13
|
+
subject { fizzgig.instantiate 'nginx::site','www.foo.com',{} }
|
10
14
|
it { should contain_file('/etc/nginx/sites-available/www.foo.com').
|
11
15
|
with_content(/server_name\s+www.foo.com;/) }
|
12
16
|
it { should contain_file('/etc/nginx/sites-enabled/www.foo.com').
|
@@ -23,7 +27,7 @@ which will instantiate a defined type and include a class
|
|
23
27
|
respectively:
|
24
28
|
|
25
29
|
[source,ruby]
|
26
|
-
catalog = Fizzgig.instantiate
|
30
|
+
catalog = Fizzgig.instantiate 'nginx::site', 'foo.com', { max_age => 300 }
|
27
31
|
|
28
32
|
[source,ruby]
|
29
33
|
catalog = Fizzgig.include 'nginx'
|
@@ -104,7 +108,7 @@ And I write this test:
|
|
104
108
|
|
105
109
|
[source,ruby]
|
106
110
|
-------------
|
107
|
-
catalog Fizzgig.instantiate
|
111
|
+
catalog Fizzgig.instantiate 'nginx::ssl_site','foo'
|
108
112
|
catalog.should contain_nginx__site('foo') # ok, will pass
|
109
113
|
catalog.should contain_file('/etc/nginx/sites-enabled/foo') # ERROR, will fail
|
110
114
|
-------------
|
data/TODO.org
CHANGED
@@ -74,6 +74,7 @@ That's not so cool :(
|
|
74
74
|
See govuk_nodes_spec_optional for examples of this.
|
75
75
|
the rspec-puppet equivalent is :type => :host
|
76
76
|
** DONE implement defined types from ruby hashes
|
77
|
+
** DONE update README to reflect defined type API change
|
77
78
|
** TODO implementation-independent dependency assertions
|
78
79
|
** TODO Test standalone puppet modules
|
79
80
|
** TODO better test output for files with large content
|
data/fizzgig.gemspec
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
2
|
s.name = 'fizzgig'
|
3
|
-
s.version = '0.
|
3
|
+
s.version = '0.4.0'
|
4
4
|
s.homepage = 'https://github.com/philandstuff/fizzgig'
|
5
5
|
s.summary = 'Tools for writing fast unit tests for Puppet'
|
6
6
|
s.description = 'Tools for writing fast unit tests for Puppet'
|
@@ -11,6 +11,7 @@ Gem::Specification.new do |s|
|
|
11
11
|
s.add_dependency 'puppet'
|
12
12
|
s.add_dependency 'lspace'
|
13
13
|
s.add_development_dependency 'rspec'
|
14
|
+
s.add_development_dependency 'rspec-puppet'
|
14
15
|
|
15
16
|
s.authors = ['Philip Potter']
|
16
17
|
s.email = 'philip.g.potter@gmail.com'
|
data/lib/fizzgig.rb
CHANGED
@@ -1,20 +1,11 @@
|
|
1
1
|
require 'puppet'
|
2
|
-
require 'fizzgig/matchers'
|
3
2
|
require 'fizzgig/function_stubs'
|
4
3
|
require 'lspace'
|
5
4
|
|
6
|
-
class
|
7
|
-
|
8
|
-
def find_or_laod(namespaces, name, type)
|
9
|
-
$stderr.puts "Resourcing #{name} #{type} in #{namespaces}"
|
10
|
-
find_or_load_real(namespaces,name,type)
|
11
|
-
end
|
12
|
-
end
|
13
|
-
|
14
|
-
module Fizzgig
|
15
|
-
def self.instantiate(type,title,params={},options = {})
|
5
|
+
class Fizzgig
|
6
|
+
def self.instantiate(type,title,params,options = {})
|
16
7
|
LSpace.with(:function_stubs => options[:stubs]) do
|
17
|
-
|
8
|
+
setup_fizzgig({modulepath: options[:modulepath],manifestdir: options[:manifestdir]})
|
18
9
|
compiler = make_compiler(options[:facts])
|
19
10
|
scope = compiler.newscope(nil)
|
20
11
|
scope.source = Puppet::Resource::Type.new(:node,'localhost')
|
@@ -35,7 +26,7 @@ module Fizzgig
|
|
35
26
|
|
36
27
|
def self.include(klass,options = {})
|
37
28
|
LSpace.with(:function_stubs => options[:stubs]) do
|
38
|
-
|
29
|
+
setup_fizzgig({modulepath: options[:modulepath],manifestdir: options[:manifestdir]})
|
39
30
|
compiler = make_compiler(options[:facts])
|
40
31
|
compile("include #{klass}",compiler)
|
41
32
|
compiler.catalog
|
@@ -44,7 +35,7 @@ module Fizzgig
|
|
44
35
|
|
45
36
|
def self.node(hostname,options = {})
|
46
37
|
LSpace.with(:function_stubs => options[:stubs]) do
|
47
|
-
|
38
|
+
setup_fizzgig({modulepath: options[:modulepath],manifestdir: options[:manifestdir]})
|
48
39
|
Puppet[:code] = '' # we want puppet to import the Puppet[:manifest] file
|
49
40
|
compiler = make_compiler(options[:facts], hostname)
|
50
41
|
compiler.send :evaluate_ast_node
|
@@ -80,21 +71,34 @@ module Fizzgig
|
|
80
71
|
parser.parse(code)
|
81
72
|
end
|
82
73
|
|
83
|
-
def self.
|
74
|
+
def self.setup_fizzgig(settings={})
|
84
75
|
Puppet[:code] = ' ' # hack to suppress puppet from looking at Puppet[:manifest]
|
85
|
-
Puppet[:modulepath] =
|
86
|
-
Puppet[:manifestdir] =
|
76
|
+
Puppet[:modulepath] = settings[:modulepath] || '/etc/puppet/modules'
|
77
|
+
Puppet[:manifestdir] = settings[:manifestdir] || nil
|
87
78
|
# stop template() fn from complaining about missing vardir config
|
88
79
|
Puppet[:vardir] ||= ""
|
80
|
+
# FIXME: decide if these are needed
|
81
|
+
#c.add_setting :manifest, :default => nil
|
82
|
+
#c.add_setting :template_dir, :default => nil
|
83
|
+
#c.add_setting :config, :default => nil
|
89
84
|
end
|
90
|
-
end
|
91
85
|
|
92
|
-
|
93
|
-
|
94
|
-
|
86
|
+
# ===== OO interface ======
|
87
|
+
# basically a glorified curried function to store the configuration
|
88
|
+
|
89
|
+
def initialize(settings={})
|
90
|
+
@modulepath = settings[:modulepath]
|
91
|
+
@manifestdir = settings[:manifestdir]
|
92
|
+
end
|
93
|
+
|
94
|
+
def instantiate(type,title,params,options={})
|
95
|
+
Fizzgig.instantiate(type,title,params,options.merge({modulepath: @modulepath, manifestdir: @manifestdir}))
|
96
|
+
end
|
95
97
|
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
98
|
+
def include(classname,options={})
|
99
|
+
Fizzgig.include(classname,options.merge({modulepath: @modulepath, manifestdir: @manifestdir}))
|
100
|
+
end
|
101
|
+
def node(hostname,options={})
|
102
|
+
Fizzgig.node(hostname,options.merge({modulepath: @modulepath, manifestdir: @manifestdir}))
|
103
|
+
end
|
100
104
|
end
|
@@ -1,28 +1,29 @@
|
|
1
|
+
class Fizzgig
|
2
|
+
module FunctionStubs
|
3
|
+
def self.has_stub?(fname,args)
|
4
|
+
stubs = LSpace[:function_stubs] || {}
|
5
|
+
stubs.has_key?(fname.to_sym) &&
|
6
|
+
stubs[fname.to_sym].has_key?(args)
|
7
|
+
end
|
1
8
|
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
stubs.has_key?(fname.to_sym) &&
|
6
|
-
stubs[fname.to_sym].has_key?(args)
|
7
|
-
end
|
8
|
-
|
9
|
-
def self.get_stub(fname,args)
|
10
|
-
LSpace[:function_stubs][fname.to_sym][args]
|
9
|
+
def self.get_stub(fname,args)
|
10
|
+
LSpace[:function_stubs][fname.to_sym][args]
|
11
|
+
end
|
11
12
|
end
|
12
|
-
end
|
13
13
|
|
14
|
-
class Puppet::Parser::AST
|
15
|
-
|
16
|
-
|
14
|
+
class Puppet::Parser::AST
|
15
|
+
class Function < AST::Branch
|
16
|
+
alias_method :orig_evaluate, :evaluate
|
17
17
|
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
18
|
+
def evaluate(scope)
|
19
|
+
#FIXME: are there implications around potential
|
20
|
+
#double-evaluation here?
|
21
|
+
args = @arguments.safeevaluate(scope).map { |x| x == :undef ? '' : x }
|
22
|
+
if Fizzgig::FunctionStubs.has_stub?(@name,args)
|
23
|
+
Fizzgig::FunctionStubs.get_stub(@name,args)
|
24
|
+
else
|
25
|
+
orig_evaluate(scope)
|
26
|
+
end
|
26
27
|
end
|
27
28
|
end
|
28
29
|
end
|
data/spec/example_spec.rb
CHANGED
@@ -2,7 +2,8 @@ require 'spec_helper'
|
|
2
2
|
require 'fizzgig'
|
3
3
|
|
4
4
|
describe 'nginx::site' do
|
5
|
-
|
5
|
+
let(:fizzgig) { Fizzgig.new({modulepath:MODULEPATH,manifestdir:MANIFESTDIR}) }
|
6
|
+
subject { fizzgig.instantiate 'nginx::site','www.foo.com',{} }
|
6
7
|
it { should contain_file('/etc/nginx/sites-available/www.foo.com').
|
7
8
|
with_content(/server_name\s+www.foo.com;/) }
|
8
9
|
it { should contain_file('/etc/nginx/sites-enabled/www.foo.com').
|
data/spec/fizzgig_spec.rb
CHANGED
@@ -2,8 +2,9 @@ require 'spec_helper'
|
|
2
2
|
require 'fizzgig'
|
3
3
|
|
4
4
|
describe Fizzgig do
|
5
|
+
let(:fizzgig) { Fizzgig.new({modulepath: MODULEPATH, manifestdir: MANIFESTDIR}) }
|
5
6
|
describe '#include' do
|
6
|
-
subject {
|
7
|
+
subject { fizzgig.include(classname, :stubs => stubs, :facts => facts) }
|
7
8
|
let(:stubs) { {} }
|
8
9
|
let(:facts) { {} }
|
9
10
|
|
@@ -69,7 +70,7 @@ describe Fizzgig do
|
|
69
70
|
end
|
70
71
|
|
71
72
|
describe '#instantiate' do
|
72
|
-
subject {
|
73
|
+
subject { fizzgig.instantiate(type, title, params, :stubs => stubs, :facts => facts) }
|
73
74
|
let(:stubs) { {} }
|
74
75
|
let(:facts) { {} }
|
75
76
|
let(:params) { {} }
|
@@ -119,7 +120,7 @@ describe Fizzgig do
|
|
119
120
|
end
|
120
121
|
|
121
122
|
describe '#node' do
|
122
|
-
subject {
|
123
|
+
subject { fizzgig.node(hostname, :facts => facts) }
|
123
124
|
let(:facts) { {} }
|
124
125
|
context 'simple node' do
|
125
126
|
let(:hostname) {'foo.com'}
|
data/spec/spec_helper.rb
CHANGED
@@ -1,11 +1,11 @@
|
|
1
1
|
require 'rspec/autorun'
|
2
2
|
require 'fizzgig'
|
3
|
+
require 'rspec-puppet/matchers'
|
3
4
|
|
4
5
|
HERE = File.expand_path(File.dirname(__FILE__))
|
6
|
+
MODULEPATH = "#{File.join(HERE, 'modules')}:#{File.join(HERE, 'extra_modules')}"
|
7
|
+
MANIFESTDIR = File.join(HERE,'manifests')
|
5
8
|
|
6
9
|
RSpec.configure do |c|
|
7
|
-
c.
|
8
|
-
c.manifestdir = File.join(HERE,'manifests')
|
9
|
-
|
10
|
-
c.include Fizzgig::CatalogMatchers
|
10
|
+
c.include RSpec::Puppet::ManifestMatchers
|
11
11
|
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'minitest/autorun'
|
2
|
+
require 'fizzgig'
|
3
|
+
|
4
|
+
HERE = File.expand_path(File.dirname(__FILE__))
|
5
|
+
|
6
|
+
MODULEPATH = "#{File.join(HERE, '../spec/modules')}:#{File.join(HERE, '../spec/extra_modules')}"
|
7
|
+
MANIFESTDIR = File.join(HERE,'../spec/manifests')
|
8
|
+
|
9
|
+
class TestNginxSite < MiniTest::Unit::TestCase
|
10
|
+
def setup
|
11
|
+
@fizzgig = Fizzgig.new({modulepath: MODULEPATH, manifestdir: MANIFESTDIR})
|
12
|
+
@catalog = @fizzgig.instantiate 'nginx::site','www.foo.com',{}
|
13
|
+
end
|
14
|
+
|
15
|
+
def test_has_sites_available_file
|
16
|
+
assert @catalog.resource('file',
|
17
|
+
'/etc/nginx/sites-available/www.foo.com')
|
18
|
+
end
|
19
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fizzgig
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-04-
|
12
|
+
date: 2013-04-20 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: puppet
|
@@ -59,6 +59,22 @@ dependencies:
|
|
59
59
|
- - ! '>='
|
60
60
|
- !ruby/object:Gem::Version
|
61
61
|
version: '0'
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: rspec-puppet
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ! '>='
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
70
|
+
type: :development
|
71
|
+
prerelease: false
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ! '>='
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
62
78
|
description: Tools for writing fast unit tests for Puppet
|
63
79
|
email: philip.g.potter@gmail.com
|
64
80
|
executables: []
|
@@ -74,7 +90,6 @@ files:
|
|
74
90
|
- fizzgig.gemspec
|
75
91
|
- lib/fizzgig.rb
|
76
92
|
- lib/fizzgig/function_stubs.rb
|
77
|
-
- lib/fizzgig/matchers.rb
|
78
93
|
- spec/example_spec.rb
|
79
94
|
- spec/extra_modules/webapp/manifests/init.pp
|
80
95
|
- spec/fizzgig/function_stubs_spec.rb
|
@@ -92,6 +107,7 @@ files:
|
|
92
107
|
- spec/modules/nginx/templates/vhost.erb
|
93
108
|
- spec/modules/params_test/manifests/init.pp
|
94
109
|
- spec/spec_helper.rb
|
110
|
+
- test/example_test.rb
|
95
111
|
homepage: https://github.com/philandstuff/fizzgig
|
96
112
|
licenses: []
|
97
113
|
post_install_message:
|
@@ -134,3 +150,4 @@ test_files:
|
|
134
150
|
- spec/modules/nginx/templates/vhost.erb
|
135
151
|
- spec/modules/params_test/manifests/init.pp
|
136
152
|
- spec/spec_helper.rb
|
153
|
+
- test/example_test.rb
|
data/lib/fizzgig/matchers.rb
DELETED
@@ -1,81 +0,0 @@
|
|
1
|
-
require 'rspec'
|
2
|
-
module Fizzgig
|
3
|
-
module CatalogMatchers
|
4
|
-
extend RSpec::Matchers::DSL
|
5
|
-
|
6
|
-
class CatalogMatcher
|
7
|
-
# matcher :contain_file do |expected_title|
|
8
|
-
def initialize(expected_type,expected_title)
|
9
|
-
@expected_type = expected_type
|
10
|
-
@expected_title = expected_title
|
11
|
-
@referenced_type = referenced_type(expected_type)
|
12
|
-
end
|
13
|
-
|
14
|
-
def matches?(catalog)
|
15
|
-
@catalog = catalog
|
16
|
-
resource = catalog.resource(@referenced_type,@expected_title)
|
17
|
-
if resource then
|
18
|
-
(@expected_params || {}).all? do |name,expected_vals|
|
19
|
-
expected_vals.all? do |expected_val|
|
20
|
-
if expected_val.kind_of?(Regexp)
|
21
|
-
resource[name] =~ expected_val
|
22
|
-
else
|
23
|
-
resource[name] == expected_val
|
24
|
-
end
|
25
|
-
end
|
26
|
-
end
|
27
|
-
else
|
28
|
-
false
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
32
|
-
def failure_message_for_should
|
33
|
-
"expected #{actual_string} to contain #{expected_string}"
|
34
|
-
end
|
35
|
-
|
36
|
-
def failure_message_for_should_not
|
37
|
-
"expected #{actual_string} not to contain #{expected_string}"
|
38
|
-
end
|
39
|
-
|
40
|
-
def method_missing(method, *args, &block)
|
41
|
-
if method.to_s =~ /^with_/
|
42
|
-
param = method.to_s.gsub(/^with_/,'')
|
43
|
-
@expected_params ||= {}
|
44
|
-
@expected_params[param] ||= []
|
45
|
-
@expected_params[param] << args[0]
|
46
|
-
self
|
47
|
-
else
|
48
|
-
super
|
49
|
-
end
|
50
|
-
end
|
51
|
-
|
52
|
-
private
|
53
|
-
|
54
|
-
def actual_string
|
55
|
-
possible_resource = @catalog.resource(@referenced_type,@expected_title)
|
56
|
-
possible_resource ? possible_resource.inspect : "the catalog"
|
57
|
-
end
|
58
|
-
|
59
|
-
def expected_string
|
60
|
-
param_string = ""
|
61
|
-
if @expected_params
|
62
|
-
param_string = " with parameters #{@expected_params.inspect}"
|
63
|
-
end
|
64
|
-
"#{@referenced_type}[#{@expected_title}]#{param_string}"
|
65
|
-
end
|
66
|
-
|
67
|
-
def referenced_type(type)
|
68
|
-
type.split('__').map { |r| r.capitalize }.join('::')
|
69
|
-
end
|
70
|
-
end
|
71
|
-
|
72
|
-
def method_missing(method, *args, &block)
|
73
|
-
if method.to_s =~ /^contain_/
|
74
|
-
resource_type = method.to_s.gsub(/^contain_/,'')
|
75
|
-
CatalogMatcher.new(resource_type,args[0])
|
76
|
-
else
|
77
|
-
super
|
78
|
-
end
|
79
|
-
end
|
80
|
-
end
|
81
|
-
end
|