infra-testing-helpers 0.0.3 → 0.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +1 -1
- data/infra-testing-helpers.gemspec +1 -1
- data/lib/infra_testing_helpers/box.rb +2 -3
- data/lib/infra_testing_helpers/helper.rb +3 -3
- data/lib/infra_testing_helpers/site.rb +10 -2
- data/spec/functional_spec_helper.rb +1 -1
- data/spec/unit/puppet_vagrant/box_spec.rb +5 -5
- data/spec/unit/puppet_vagrant/site_spec.rb +8 -2
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 46cab553c44d5eee82696bfae7180b99fa9d436b
|
4
|
+
data.tar.gz: 10ff278b9b6f191f32d7ee828e49fcc78f0c0740
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0bfeec87961e3c2301d7f47c457228377763e50f9dcfd2428b92e68422ef5480244fac267125eb7716c776fd2bbaba9a535315be52a73dde640a0e21da663af6
|
7
|
+
data.tar.gz: 46e087ff2a8bde92dc47fef571744229756377e152238239da4cb1f742213fc73ddce3925136067584c604bbabd0d6b40d8d9e272265420e1a6598e8b52fb38e
|
data/README.md
CHANGED
@@ -13,7 +13,7 @@ Next, lets have a look at your `spec_helper.rb` (probably generated by Serverspe
|
|
13
13
|
...
|
14
14
|
require 'infra_testing_helpers'
|
15
15
|
InfraTestingHelpers.project_root = File.expand_path(File.dirname(__FILE__) + '/../')
|
16
|
-
InfraTestingHelpers.module_path = 'modules/:another_module_path/'
|
16
|
+
InfraTestingHelpers.module_path = ['modules/:another_module_path/']
|
17
17
|
InfraTestingHelpers.site_pp = 'Exec { path => "/sbin:/usr/sbin:/bin:/usr/bin" }'
|
18
18
|
InfraTestingHelpers.vagrant_shared_folder = '/etc/puppet'
|
19
19
|
...
|
@@ -4,7 +4,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
4
|
|
5
5
|
Gem::Specification.new do |spec|
|
6
6
|
spec.name = "infra-testing-helpers"
|
7
|
-
spec.version = '0.0.
|
7
|
+
spec.version = '0.0.4'
|
8
8
|
spec.authors = ["Ryan Doyle"]
|
9
9
|
spec.email = ["ryan@doylenet.net"]
|
10
10
|
spec.summary = %q{Integrations with RSpec, Puppet and Vagrant to help infrastructure testing}
|
@@ -1,9 +1,8 @@
|
|
1
1
|
module InfraTestingHelpers
|
2
2
|
class PuppetApplyFailed < StandardError; end
|
3
3
|
class Box
|
4
|
-
def initialize(name
|
4
|
+
def initialize(name)
|
5
5
|
@name = name
|
6
|
-
@project_mount_point = project_mount_point
|
7
6
|
@applied = false
|
8
7
|
end
|
9
8
|
|
@@ -11,7 +10,7 @@ module InfraTestingHelpers
|
|
11
10
|
|
12
11
|
def apply(manifest)
|
13
12
|
manifest.manifest_file do |file|
|
14
|
-
exit_code = run_command("sudo puppet apply --detailed-exitcode --modulepath #{
|
13
|
+
exit_code = run_command("sudo puppet apply --detailed-exitcode --modulepath #{manifest.module_path} #{file}")
|
15
14
|
raise PuppetApplyFailed unless exit_code == 0 or exit_code == 2
|
16
15
|
@applied = true
|
17
16
|
end
|
@@ -6,7 +6,7 @@ module InfraTestingHelpers
|
|
6
6
|
|
7
7
|
def apply_manifest(manifest_code)
|
8
8
|
if box.applied?
|
9
|
-
local_site = InfraTestingHelpers::Site.new(InfraTestingHelpers.site_pp, InfraTestingHelpers.module_path, InfraTestingHelpers.project_root)
|
9
|
+
local_site = InfraTestingHelpers::Site.new(InfraTestingHelpers.site_pp, InfraTestingHelpers.module_path, InfraTestingHelpers.project_root, InfraTestingHelpers.vagrant_shared_folder)
|
10
10
|
local_site.add_manifest(manifest_code)
|
11
11
|
box.apply(local_site)
|
12
12
|
else
|
@@ -22,11 +22,11 @@ module InfraTestingHelpers
|
|
22
22
|
private
|
23
23
|
|
24
24
|
def global_site
|
25
|
-
@@global_site ||= InfraTestingHelpers::Site.new(InfraTestingHelpers.site_pp, InfraTestingHelpers.module_path, InfraTestingHelpers.project_root)
|
25
|
+
@@global_site ||= InfraTestingHelpers::Site.new(InfraTestingHelpers.site_pp, InfraTestingHelpers.module_path, InfraTestingHelpers.project_root, InfraTestingHelpers.vagrant_shared_folder)
|
26
26
|
end
|
27
27
|
|
28
28
|
def box
|
29
|
-
@@box ||= InfraTestingHelpers::Box.new('default'
|
29
|
+
@@box ||= InfraTestingHelpers::Box.new('default')
|
30
30
|
end
|
31
31
|
|
32
32
|
end
|
@@ -3,15 +3,23 @@ require 'tempfile'
|
|
3
3
|
module InfraTestingHelpers
|
4
4
|
class Site
|
5
5
|
|
6
|
-
def initialize(site_code, module_path, project_root)
|
6
|
+
def initialize(site_code, module_path, project_root, project_mount_point)
|
7
7
|
@site_code = site_code
|
8
8
|
@module_path = module_path
|
9
9
|
@project_root = project_root
|
10
|
+
@project_mount_point = project_mount_point
|
10
11
|
@manifest_code = ""
|
11
12
|
end
|
12
13
|
|
13
14
|
attr_reader :module_path
|
14
15
|
|
16
|
+
def module_path
|
17
|
+
@module_path.inject('') do |memo, path|
|
18
|
+
memo << "#{@project_mount_point}/#{path}:"
|
19
|
+
memo
|
20
|
+
end[0...-1]
|
21
|
+
end
|
22
|
+
|
15
23
|
def add_manifest(manifest)
|
16
24
|
@manifest_code << "#{manifest}\n"
|
17
25
|
end
|
@@ -21,7 +29,7 @@ module InfraTestingHelpers
|
|
21
29
|
begin
|
22
30
|
file.puts puppet_code
|
23
31
|
file.fsync
|
24
|
-
yield(File.basename(file.path)) if block_given?
|
32
|
+
yield("#{@project_mount_point}/#{File.basename(file.path)}") if block_given?
|
25
33
|
ensure
|
26
34
|
file.close
|
27
35
|
file.unlink
|
@@ -5,7 +5,7 @@ require 'net/ssh'
|
|
5
5
|
require 'tempfile'
|
6
6
|
require 'infra_testing_helpers'
|
7
7
|
|
8
|
-
InfraTestingHelpers.module_path = 'spec/functional/modules/'
|
8
|
+
InfraTestingHelpers.module_path = ['spec/functional/modules/']
|
9
9
|
InfraTestingHelpers.site_pp = 'notify {"This is my site.pp":}
|
10
10
|
$extlookup_precedence = ["hosts/%{fqdn}", "domains/%{domain}", "common"]
|
11
11
|
'
|
@@ -5,14 +5,14 @@ require 'infra_testing_helpers/box'
|
|
5
5
|
describe InfraTestingHelpers::Box do
|
6
6
|
|
7
7
|
let(:manifest) { double('Manifest') }
|
8
|
-
let(:box) { described_class.new('default'
|
8
|
+
let(:box) { described_class.new('default') }
|
9
9
|
|
10
10
|
before do
|
11
11
|
allow_message_expectations_on_nil
|
12
12
|
allow($?).to receive(:exitstatus).and_return(0)
|
13
|
-
allow(manifest).to receive(:module_path).and_return('modules/')
|
13
|
+
allow(manifest).to receive(:module_path).and_return('/vagrant/modules/')
|
14
14
|
allow(manifest).to receive(:puppet_code).and_return('include some_manifest')
|
15
|
-
allow(manifest).to receive(:manifest_file).and_yield('tempfile_path.pp')
|
15
|
+
allow(manifest).to receive(:manifest_file).and_yield('/vagrant/tempfile_path.pp')
|
16
16
|
end
|
17
17
|
|
18
18
|
describe '#apply' do
|
@@ -65,7 +65,7 @@ describe InfraTestingHelpers::Box do
|
|
65
65
|
end
|
66
66
|
|
67
67
|
it 'runs the command on the box with the box name' do
|
68
|
-
box = described_class.new('somebox'
|
68
|
+
box = described_class.new('somebox')
|
69
69
|
expect(box).to receive(:system).with('vagrant ssh somebox --command "some_command"')
|
70
70
|
box.run_command('some_command')
|
71
71
|
end
|
@@ -89,7 +89,7 @@ describe InfraTestingHelpers::Box do
|
|
89
89
|
end
|
90
90
|
|
91
91
|
it 'has a name if specified' do
|
92
|
-
box = described_class.new('somebox'
|
92
|
+
box = described_class.new('somebox')
|
93
93
|
expect(box.name).to eql 'somebox'
|
94
94
|
end
|
95
95
|
end
|
@@ -4,7 +4,7 @@ require 'infra_testing_helpers/site'
|
|
4
4
|
|
5
5
|
describe InfraTestingHelpers::Site do
|
6
6
|
|
7
|
-
let(:site) { described_class.new('site.pp code', '
|
7
|
+
let(:site) { described_class.new('site.pp code', ['modules', 'other_modules'], '/some/project/root', '/vagrant') }
|
8
8
|
let(:tempfile) { double('Tempfile') }
|
9
9
|
|
10
10
|
describe '#puppet_code' do
|
@@ -32,6 +32,12 @@ describe InfraTestingHelpers::Site do
|
|
32
32
|
end
|
33
33
|
end
|
34
34
|
|
35
|
+
describe '#module_path' do
|
36
|
+
it 'returns the module path as a flattened path' do
|
37
|
+
expect(site.module_path).to eql '/vagrant/modules:/vagrant/other_modules'
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
35
41
|
describe '#manifest_file' do
|
36
42
|
before do
|
37
43
|
allow(Tempfile).to receive(:new).with(['infra-testing-helpers', '.pp'], '/some/project/root').and_return tempfile
|
@@ -53,7 +59,7 @@ describe InfraTestingHelpers::Site do
|
|
53
59
|
it 'yeilds the base filename of the tempfile' do
|
54
60
|
allow(tempfile).to receive(:path).and_return('/tmp/tempfile_base_path.pp')
|
55
61
|
|
56
|
-
expect { |b| site.manifest_file(&b) }.to yield_with_args('tempfile_base_path.pp')
|
62
|
+
expect { |b| site.manifest_file(&b) }.to yield_with_args('/vagrant/tempfile_base_path.pp')
|
57
63
|
end
|
58
64
|
it 'closes the file after yielding' do
|
59
65
|
expect(tempfile).to receive(:close)
|