fizzgig 0.2.1 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.md +5 -0
- data/TODO.org +1 -0
- data/fizzgig.gemspec +1 -1
- data/lib/fizzgig.rb +26 -3
- data/spec/example_spec.rb +1 -1
- data/spec/fizzgig_spec.rb +27 -11
- data/spec/manifests/site.pp +3 -0
- metadata +2 -2
data/CHANGELOG.md
CHANGED
data/TODO.org
CHANGED
@@ -73,6 +73,7 @@ That's not so cool :(
|
|
73
73
|
** DONE nodes
|
74
74
|
See govuk_nodes_spec_optional for examples of this.
|
75
75
|
the rspec-puppet equivalent is :type => :host
|
76
|
+
** DONE implement defined types from ruby hashes
|
76
77
|
** TODO implementation-independent dependency assertions
|
77
78
|
** TODO Test standalone puppet modules
|
78
79
|
** 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.3.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'
|
data/lib/fizzgig.rb
CHANGED
@@ -3,13 +3,32 @@ require 'fizzgig/matchers'
|
|
3
3
|
require 'fizzgig/function_stubs'
|
4
4
|
require 'lspace'
|
5
5
|
|
6
|
+
class Puppet::Resource::TypeCollection
|
7
|
+
alias_method :find_or_load_real, :find_or_load
|
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
|
+
|
6
14
|
module Fizzgig
|
7
|
-
def self.instantiate(
|
15
|
+
def self.instantiate(type,title,params={},options = {})
|
8
16
|
LSpace.with(:function_stubs => options[:stubs]) do
|
9
17
|
setup_puppet
|
10
18
|
compiler = make_compiler(options[:facts])
|
11
|
-
|
12
|
-
|
19
|
+
scope = compiler.newscope(nil)
|
20
|
+
scope.source = Puppet::Resource::Type.new(:node,'localhost')
|
21
|
+
# we need to force loading the type; normally this would be
|
22
|
+
# handled by Puppet::Parser::AST::Resource calling
|
23
|
+
# scope.resolve_type_and_titles
|
24
|
+
scope.find_defined_resource_type(type)
|
25
|
+
|
26
|
+
resource = Puppet::Parser::Resource.new(
|
27
|
+
type,
|
28
|
+
title,
|
29
|
+
:scope => scope,
|
30
|
+
:parameters => munge_params(params))
|
31
|
+
resource.evaluate
|
13
32
|
compiler.catalog
|
14
33
|
end
|
15
34
|
end
|
@@ -33,6 +52,10 @@ module Fizzgig
|
|
33
52
|
end
|
34
53
|
end
|
35
54
|
|
55
|
+
def self.munge_params(params)
|
56
|
+
params.collect {|k,v| Puppet::Parser::Resource::Param.new(:name => k, :value => v)}
|
57
|
+
end
|
58
|
+
|
36
59
|
def self.make_compiler(facts,hostname='localhost')
|
37
60
|
node = Puppet::Node.new(hostname)
|
38
61
|
node.merge(facts) if facts
|
data/spec/example_spec.rb
CHANGED
@@ -2,7 +2,7 @@ require 'spec_helper'
|
|
2
2
|
require 'fizzgig'
|
3
3
|
|
4
4
|
describe 'nginx::site' do
|
5
|
-
subject { Fizzgig.instantiate
|
5
|
+
subject { Fizzgig.instantiate 'nginx::site','www.foo.com' }
|
6
6
|
it { should contain_file('/etc/nginx/sites-available/www.foo.com').
|
7
7
|
with_content(/server_name\s+www.foo.com;/) }
|
8
8
|
it { should contain_file('/etc/nginx/sites-enabled/www.foo.com').
|
data/spec/fizzgig_spec.rb
CHANGED
@@ -69,26 +69,30 @@ describe Fizzgig do
|
|
69
69
|
end
|
70
70
|
|
71
71
|
describe '#instantiate' do
|
72
|
-
subject { Fizzgig.instantiate(
|
72
|
+
subject { Fizzgig.instantiate(type, title, params, :stubs => stubs, :facts => facts) }
|
73
73
|
let(:stubs) { {} }
|
74
74
|
let(:facts) { {} }
|
75
|
+
let(:params) { {} }
|
75
76
|
|
76
77
|
describe 'params' do
|
78
|
+
let(:type) {'params_test'}
|
79
|
+
let(:title) { 'foo' }
|
77
80
|
context 'when specifying one parameter' do
|
78
|
-
let(:
|
81
|
+
let(:params) { {:param => 'bar'} }
|
79
82
|
it { should contain_file('foo-param').with_source('bar') }
|
80
83
|
it { should contain_notify('foo-default').with_message('default_val') }
|
81
84
|
end
|
82
85
|
context 'when specifying both paramaters' do
|
83
|
-
let(:
|
86
|
+
let(:params) { {:param => 'bar', :param_with_default => 'baz'} }
|
84
87
|
it { should contain_file('foo-param').with_source('bar') }
|
85
88
|
it { should contain_notify('foo-default').with_message('baz') }
|
86
89
|
end
|
87
90
|
end
|
88
91
|
|
89
92
|
describe 'nginx::simple_server' do
|
93
|
+
let(:type) {'nginx::simple_server'}
|
94
|
+
let(:title) {'foo'}
|
90
95
|
context 'basic functionality' do
|
91
|
-
let(:code) { %q[nginx::simple_server {'foo':}] }
|
92
96
|
it { should contain_nginx__site('foo').
|
93
97
|
with_content(/server_name foo;/)
|
94
98
|
}
|
@@ -97,13 +101,14 @@ describe Fizzgig do
|
|
97
101
|
|
98
102
|
context 'functions::define_test with function stubs' do
|
99
103
|
let(:stubs) { {:extlookup => {['ssh-key-barry'] => 'the key of S'}} }
|
100
|
-
let(:
|
104
|
+
let(:type) {'functions::define_test'}
|
105
|
+
let(:title) {'foo'}
|
101
106
|
it { should contain_ssh_authorized_key('barry').with_key('the key of S') }
|
102
107
|
end
|
103
108
|
|
104
109
|
describe 'facts::define_test' do
|
105
|
-
let(:
|
106
|
-
let(:
|
110
|
+
let(:type) {'facts::define_test'}
|
111
|
+
let(:title) {'test'}
|
107
112
|
let(:facts) {
|
108
113
|
{ 'unqualified_fact' => 'no qualifications',
|
109
114
|
'qualified_fact' => 'cse ungraded in metalwork'}
|
@@ -114,9 +119,20 @@ describe Fizzgig do
|
|
114
119
|
end
|
115
120
|
|
116
121
|
describe '#node' do
|
117
|
-
subject { Fizzgig.node(
|
118
|
-
|
119
|
-
|
120
|
-
|
122
|
+
subject { Fizzgig.node(hostname, :facts => facts) }
|
123
|
+
let(:facts) { {} }
|
124
|
+
context 'simple node' do
|
125
|
+
let(:hostname) {'foo.com'}
|
126
|
+
it { should contain_nginx__site('foo.com') }
|
127
|
+
end
|
128
|
+
context 'default node' do
|
129
|
+
let(:hostname) {'foo.invalid'}
|
130
|
+
it { should contain_notify('oops, default') }
|
131
|
+
end
|
132
|
+
context 'node with facts specified' do
|
133
|
+
let(:hostname) {'fact.com'}
|
134
|
+
let(:facts) { { 'fact_site' => 'facts.org' } }
|
135
|
+
it { should contain_nginx__site('facts.org') }
|
136
|
+
end
|
121
137
|
end
|
122
138
|
end
|
data/spec/manifests/site.pp
CHANGED
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.3.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-
|
12
|
+
date: 2013-04-09 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: puppet
|