fizzgig 0.1.1 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +1 -1
- data/README.asciidoc +7 -18
- data/TODO.org +5 -1
- data/fizzgig.gemspec +1 -1
- data/lib/fizzgig/function_stubs.rb +2 -2
- data/spec/example_spec.rb +11 -0
- data/spec/extra_modules/webapp/manifests/init.pp +8 -0
- data/spec/fizzgig/function_stubs_spec.rb +39 -0
- data/spec/fizzgig_spec.rb +20 -19
- data/spec/modules/functions/manifests/function_with_multiple_arguments.pp +5 -0
- data/spec/modules/nginx/manifests/site.pp +5 -4
- data/spec/spec_helper.rb +1 -1
- metadata +10 -4
- data/spec/modules/webapp/manifests/init.pp +0 -4
data/.gitignore
CHANGED
data/README.asciidoc
CHANGED
@@ -5,24 +5,13 @@ Fizzgig is a library to help write fast unit tests.
|
|
5
5
|
|
6
6
|
[source,ruby]
|
7
7
|
-------------------------------------------
|
8
|
-
describe '
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
}
|
16
|
-
END
|
17
|
-
catalog.should contain_file('/etc/ganglia/scripts/tiger')
|
18
|
-
.with_content('tiger content')
|
19
|
-
.with_mode('0755')
|
20
|
-
|
21
|
-
catalog.should contain_cron('ganglia-tiger')
|
22
|
-
.with_command('/etc/ganglia/scripts/tiger')
|
23
|
-
.with_minute('*')
|
24
|
-
.with_user('root')
|
25
|
-
end
|
8
|
+
describe 'nginx::site' do
|
9
|
+
subject { Fizzgig.instantiate %q[nginx::site{'www.foo.com':}] }
|
10
|
+
it { should contain_file('/etc/nginx/sites-available/www.foo.com').
|
11
|
+
with_content(/server_name\s+www.foo.com;/) }
|
12
|
+
it { should contain_file('/etc/nginx/sites-enabled/www.foo.com').
|
13
|
+
with_ensure('link').
|
14
|
+
with_target('/etc/nginx/sites-available/www.foo.com') }
|
26
15
|
end
|
27
16
|
-------------------------------------------
|
28
17
|
|
data/TODO.org
CHANGED
@@ -44,7 +44,7 @@ Can we isolate the compiler from the settings?
|
|
44
44
|
|
45
45
|
Answer seems to be yes -- use puppetlabs_spec_helper or directly
|
46
46
|
Puppet::Test::TestHelper to tear down Puppet.settings after each test.
|
47
|
-
**
|
47
|
+
** DONE Ensure that modulepath can take multiple directories
|
48
48
|
- in govuk/puppet, we had trouble having multiple directories on
|
49
49
|
the module path, so we ended up doing this:
|
50
50
|
|
@@ -69,13 +69,17 @@ Puppet::Test::TestHelper to tear down Puppet.settings after each test.
|
|
69
69
|
That's not so cool :(
|
70
70
|
|
71
71
|
** DONE Rename
|
72
|
+
** DONE functions with multiple arguments
|
72
73
|
** TODO implementation-independent dependency assertions
|
73
74
|
** TODO Test standalone puppet modules
|
74
75
|
** TODO better test output for files with large content
|
75
76
|
** TODO Test puppet types (ie from lib/puppet/parser/types)
|
76
77
|
** TODO Test templates in isolation
|
78
|
+
maybe testing functions more generally?
|
77
79
|
** TODO Test custom facts
|
78
80
|
** TODO Virtual/exported resources
|
81
|
+
@dcarley's trick of using a precondition with a collector might be
|
82
|
+
helpful here
|
79
83
|
** TODO Parameterized classes
|
80
84
|
** TODO Preconditions (do I actually want this?)
|
81
85
|
** TODO nodes
|
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.2.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'
|
@@ -3,11 +3,11 @@ module Fizzgig::FunctionStubs
|
|
3
3
|
def self.has_stub?(fname,args)
|
4
4
|
stubs = LSpace[:function_stubs] || {}
|
5
5
|
stubs.has_key?(fname.to_sym) &&
|
6
|
-
stubs[fname.to_sym].has_key?(args
|
6
|
+
stubs[fname.to_sym].has_key?(args)
|
7
7
|
end
|
8
8
|
|
9
9
|
def self.get_stub(fname,args)
|
10
|
-
LSpace[:function_stubs][fname.to_sym][args
|
10
|
+
LSpace[:function_stubs][fname.to_sym][args]
|
11
11
|
end
|
12
12
|
end
|
13
13
|
|
@@ -0,0 +1,11 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'fizzgig'
|
3
|
+
|
4
|
+
describe 'nginx::site' do
|
5
|
+
subject { Fizzgig.instantiate %q[nginx::site{'www.foo.com':}] }
|
6
|
+
it { should contain_file('/etc/nginx/sites-available/www.foo.com').
|
7
|
+
with_content(/server_name\s+www.foo.com;/) }
|
8
|
+
it { should contain_file('/etc/nginx/sites-enabled/www.foo.com').
|
9
|
+
with_ensure('link').
|
10
|
+
with_target('/etc/nginx/sites-available/www.foo.com') }
|
11
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
require_relative '../spec_helper'
|
2
|
+
require 'fizzgig/function_stubs'
|
3
|
+
|
4
|
+
describe Fizzgig::FunctionStubs do
|
5
|
+
describe '.has_stub?' do
|
6
|
+
subject { LSpace.with(:function_stubs => stubs) { Fizzgig::FunctionStubs.has_stub?(fname, args) } }
|
7
|
+
|
8
|
+
context 'single arg fn' do
|
9
|
+
let(:stubs) { { :myfn => {['foo'] => 'bar'}} }
|
10
|
+
let(:fname) {:myfn}
|
11
|
+
let(:args) {['foo']}
|
12
|
+
it {should be_true}
|
13
|
+
end
|
14
|
+
|
15
|
+
context 'multi arg fn' do
|
16
|
+
let(:stubs) { { :myfn => {['foo','bar'] => 'giraffe'}} }
|
17
|
+
let(:fname) {:myfn}
|
18
|
+
let(:args) {['foo','bar']}
|
19
|
+
it {should be_true}
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
describe '.get_stub' do
|
24
|
+
subject { LSpace.with(:function_stubs => stubs) { Fizzgig::FunctionStubs.get_stub(fname, args) } }
|
25
|
+
context 'single arg fn' do
|
26
|
+
let(:stubs) { { :myfn => {['foo'] => 'bar'}} }
|
27
|
+
let(:fname) {:myfn}
|
28
|
+
let(:args) {['foo']}
|
29
|
+
it {should == 'bar'}
|
30
|
+
end
|
31
|
+
|
32
|
+
context 'multi arg fn' do
|
33
|
+
let(:stubs) { { :myfn => {['foo','bar'] => 'giraffe'}} }
|
34
|
+
let(:fname) {:myfn}
|
35
|
+
let(:args) {['foo','bar']}
|
36
|
+
it {should == 'giraffe'}
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
data/spec/fizzgig_spec.rb
CHANGED
@@ -11,12 +11,19 @@ describe Fizzgig do
|
|
11
11
|
let(:classname) {'webapp'}
|
12
12
|
|
13
13
|
it { should contain_nginx__site('webapp') }
|
14
|
+
it 'should check multiple matchers for a single parameter' do
|
15
|
+
should contain_file('/etc/nginx/nginx.conf').
|
16
|
+
with_content(/fee fie foe fum/)
|
17
|
+
should_not contain_file('/etc/nginx/nginx.conf').
|
18
|
+
with_content(/pattern not present in file/).
|
19
|
+
with_content(/fee fie foe fum/)
|
20
|
+
end
|
14
21
|
end
|
15
22
|
|
16
23
|
describe 'functions::class_test' do
|
17
24
|
let(:classname) {'functions::class_test'}
|
18
25
|
context 'with extlookup stubbed out' do
|
19
|
-
let(:stubs) { {:extlookup => {'ssh-key-barry' => 'the key of S'}} }
|
26
|
+
let(:stubs) { {:extlookup => {['ssh-key-barry'] => 'the key of S'}} }
|
20
27
|
it { should contain_ssh_authorized_key('barry').with_key('the key of S') }
|
21
28
|
end
|
22
29
|
|
@@ -32,12 +39,21 @@ describe Fizzgig do
|
|
32
39
|
let(:classname) {'functions::recursive_extlookup_test'}
|
33
40
|
let(:stubs) {
|
34
41
|
{:extlookup =>
|
35
|
-
{ 'ssh-key-barry' => 'rsa-key-barry',
|
36
|
-
'rsa-key-barry' => 'the key of S'}}
|
42
|
+
{ ['ssh-key-barry'] => 'rsa-key-barry',
|
43
|
+
['rsa-key-barry'] => 'the key of S'}}
|
37
44
|
}
|
38
45
|
it { should contain_ssh_authorized_key('barry').with_key('the key of S') }
|
39
46
|
end
|
40
47
|
|
48
|
+
describe 'functions::function_with_multiple_arguments' do
|
49
|
+
let(:classname) {'functions::function_with_multiple_arguments'}
|
50
|
+
let(:stubs) {
|
51
|
+
{:hiera =>
|
52
|
+
{['hiera_key','default value'] => 'correct result'}}
|
53
|
+
}
|
54
|
+
it { should contain_file('/tmp/multiarg_fn_test').with_content('correct result') }
|
55
|
+
end
|
56
|
+
|
41
57
|
describe 'facts::class_test' do
|
42
58
|
let(:classname) {'facts::class_test'}
|
43
59
|
let(:facts) {
|
@@ -70,21 +86,6 @@ describe Fizzgig do
|
|
70
86
|
end
|
71
87
|
end
|
72
88
|
|
73
|
-
describe 'nginx::site' do
|
74
|
-
context 'basic functionality' do
|
75
|
-
let(:code) { %q[nginx::site {'foo': content => 'dontcare'}] }
|
76
|
-
it { should contain_file('/etc/nginx/sites-enabled/foo').
|
77
|
-
with_ensure('present').
|
78
|
-
with_mode('0440')
|
79
|
-
}
|
80
|
-
it { should_not contain_file('/etc/nginx/sites-enabled/foo').
|
81
|
-
with_ensure(/text not present/). # test that this doesn't get ignored
|
82
|
-
with_ensure(/present/)
|
83
|
-
}
|
84
|
-
it { should contain_user('www-data') }
|
85
|
-
end
|
86
|
-
end
|
87
|
-
|
88
89
|
describe 'nginx::simple_server' do
|
89
90
|
context 'basic functionality' do
|
90
91
|
let(:code) { %q[nginx::simple_server {'foo':}] }
|
@@ -95,7 +96,7 @@ describe Fizzgig do
|
|
95
96
|
end
|
96
97
|
|
97
98
|
context 'functions::define_test with function stubs' do
|
98
|
-
let(:stubs) { {:extlookup => {'ssh-key-barry' => 'the key of S'}} }
|
99
|
+
let(:stubs) { {:extlookup => {['ssh-key-barry'] => 'the key of S'}} }
|
99
100
|
let(:code) { %[functions::define_test{'foo': }] }
|
100
101
|
it { should contain_ssh_authorized_key('barry').with_key('the key of S') }
|
101
102
|
end
|
@@ -1,9 +1,10 @@
|
|
1
|
-
define nginx::site (
|
2
|
-
file {"/etc/nginx/sites-
|
1
|
+
define nginx::site () {
|
2
|
+
file {"/etc/nginx/sites-available/$title":
|
3
3
|
ensure => present,
|
4
|
-
mode => 0440,
|
5
4
|
content => template('nginx/vhost.erb'),
|
6
5
|
}
|
7
|
-
|
6
|
+
file {"/etc/nginx/sites-enabled/$title":
|
7
|
+
ensure => link,
|
8
|
+
target => "/etc/nginx/sites-available/${title}",
|
8
9
|
}
|
9
10
|
}
|
data/spec/spec_helper.rb
CHANGED
@@ -4,7 +4,7 @@ require 'fizzgig'
|
|
4
4
|
HERE = File.expand_path(File.dirname(__FILE__))
|
5
5
|
|
6
6
|
RSpec.configure do |c|
|
7
|
-
c.modulepath = File.join(HERE, 'modules')
|
7
|
+
c.modulepath = "#{File.join(HERE, 'modules')}:#{File.join(HERE, 'extra_modules')}"
|
8
8
|
|
9
9
|
c.include Fizzgig::CatalogMatchers
|
10
10
|
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.2.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-03-
|
12
|
+
date: 2013-03-28 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: puppet
|
@@ -75,18 +75,21 @@ files:
|
|
75
75
|
- lib/fizzgig.rb
|
76
76
|
- lib/fizzgig/function_stubs.rb
|
77
77
|
- lib/fizzgig/matchers.rb
|
78
|
+
- spec/example_spec.rb
|
79
|
+
- spec/extra_modules/webapp/manifests/init.pp
|
80
|
+
- spec/fizzgig/function_stubs_spec.rb
|
78
81
|
- spec/fizzgig_spec.rb
|
79
82
|
- spec/modules/facts/manifests/class_test.pp
|
80
83
|
- spec/modules/facts/manifests/define_test.pp
|
81
84
|
- spec/modules/facts/templates/template-test.erb
|
82
85
|
- spec/modules/functions/manifests/class_test.pp
|
83
86
|
- spec/modules/functions/manifests/define_test.pp
|
87
|
+
- spec/modules/functions/manifests/function_with_multiple_arguments.pp
|
84
88
|
- spec/modules/functions/manifests/recursive_extlookup_test.pp
|
85
89
|
- spec/modules/nginx/manifests/simple_server.pp
|
86
90
|
- spec/modules/nginx/manifests/site.pp
|
87
91
|
- spec/modules/nginx/templates/vhost.erb
|
88
92
|
- spec/modules/params_test/manifests/init.pp
|
89
|
-
- spec/modules/webapp/manifests/init.pp
|
90
93
|
- spec/spec_helper.rb
|
91
94
|
homepage: https://github.com/philandstuff/fizzgig
|
92
95
|
licenses: []
|
@@ -113,16 +116,19 @@ signing_key:
|
|
113
116
|
specification_version: 3
|
114
117
|
summary: Tools for writing fast unit tests for Puppet
|
115
118
|
test_files:
|
119
|
+
- spec/example_spec.rb
|
120
|
+
- spec/extra_modules/webapp/manifests/init.pp
|
121
|
+
- spec/fizzgig/function_stubs_spec.rb
|
116
122
|
- spec/fizzgig_spec.rb
|
117
123
|
- spec/modules/facts/manifests/class_test.pp
|
118
124
|
- spec/modules/facts/manifests/define_test.pp
|
119
125
|
- spec/modules/facts/templates/template-test.erb
|
120
126
|
- spec/modules/functions/manifests/class_test.pp
|
121
127
|
- spec/modules/functions/manifests/define_test.pp
|
128
|
+
- spec/modules/functions/manifests/function_with_multiple_arguments.pp
|
122
129
|
- spec/modules/functions/manifests/recursive_extlookup_test.pp
|
123
130
|
- spec/modules/nginx/manifests/simple_server.pp
|
124
131
|
- spec/modules/nginx/manifests/site.pp
|
125
132
|
- spec/modules/nginx/templates/vhost.erb
|
126
133
|
- spec/modules/params_test/manifests/init.pp
|
127
|
-
- spec/modules/webapp/manifests/init.pp
|
128
134
|
- spec/spec_helper.rb
|