racker 0.1.6 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.md +5 -0
- data/README.md +27 -13
- data/Rakefile +2 -2
- data/bin/racker +20 -33
- data/lib/racker.rb +1 -0
- data/lib/racker/builders/amazon.rb +3 -4
- data/lib/racker/builders/builder.rb +6 -5
- data/lib/racker/builders/digitalocean.rb +4 -5
- data/lib/racker/builders/docker.rb +3 -4
- data/lib/racker/builders/google.rb +4 -5
- data/lib/racker/builders/null.rb +4 -5
- data/lib/racker/builders/openstack.rb +3 -4
- data/lib/racker/builders/parallels.rb +3 -4
- data/lib/racker/builders/qemu.rb +3 -4
- data/lib/racker/builders/virtualbox.rb +4 -5
- data/lib/racker/builders/vmware.rb +4 -5
- data/lib/racker/cli.rb +59 -34
- data/lib/racker/log_support.rb +47 -0
- data/lib/racker/processor.rb +10 -23
- data/lib/racker/smash/deep_merge_modified.rb +1 -1
- data/lib/racker/template.rb +10 -10
- data/lib/racker/version.rb +2 -2
- data/spec/fixtures/high_priority_template.rb +6 -0
- data/spec/fixtures/low_priority_template.rb +7 -0
- data/spec/integration/output_to_file_spec.rb +21 -0
- data/spec/integration/output_to_stdout_spec.rb +16 -0
- data/spec/spec_helper.rb +19 -0
- data/spec/unit/cli_spec.rb +201 -0
- data/spec/unit/log_support_spec.rb +62 -0
- data/spec/unit/processor_spec.rb +163 -0
- metadata +14 -5
@@ -0,0 +1,62 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
RSpec.describe Racker::LogSupport do
|
4
|
+
before(:all) do
|
5
|
+
# Must call described_class outside of Class.new block so method lookup
|
6
|
+
# resolves against test scope rather than block scope
|
7
|
+
klass = described_class
|
8
|
+
DummyClass = Class.new { include klass }
|
9
|
+
@instance = DummyClass.new
|
10
|
+
end
|
11
|
+
|
12
|
+
context '::logger' do
|
13
|
+
it 'returns the global Log4r logger for racker' do
|
14
|
+
expect(described_class.logger).to eq(Log4r::Logger['racker'])
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
context '::level=' do
|
19
|
+
it 'sets the logger level based on the provided level string' do
|
20
|
+
described_class.level = 'error'
|
21
|
+
expect(described_class.logger.level).to eq(Log4r::ERROR)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
context '::log4r_log_level_for' do
|
26
|
+
it 'returns Log4r::DEBUG for values matching debug' do
|
27
|
+
expect(described_class.log4r_level_for('debug')).to eq(Log4r::DEBUG)
|
28
|
+
expect(described_class.log4r_level_for(:debug)).to eq(Log4r::DEBUG)
|
29
|
+
end
|
30
|
+
|
31
|
+
it 'returns Log4r::ERROR for values matching error' do
|
32
|
+
expect(described_class.log4r_level_for('error')).to eq(Log4r::ERROR)
|
33
|
+
expect(described_class.log4r_level_for(:error)).to eq(Log4r::ERROR)
|
34
|
+
end
|
35
|
+
|
36
|
+
it 'returns Log4r::FATAL for values matching fatal' do
|
37
|
+
expect(described_class.log4r_level_for('fatal')).to eq(Log4r::FATAL)
|
38
|
+
expect(described_class.log4r_level_for(:fatal)).to eq(Log4r::FATAL)
|
39
|
+
end
|
40
|
+
|
41
|
+
it 'returns Log4r::INFO for values matching info' do
|
42
|
+
expect(described_class.log4r_level_for('info')).to eq(Log4r::INFO)
|
43
|
+
expect(described_class.log4r_level_for(:info)).to eq(Log4r::INFO)
|
44
|
+
end
|
45
|
+
|
46
|
+
it 'returns Log4r::WARN for values matching warn' do
|
47
|
+
expect(described_class.log4r_level_for('warn')).to eq(Log4r::WARN)
|
48
|
+
expect(described_class.log4r_level_for(:warn)).to eq(Log4r::WARN)
|
49
|
+
end
|
50
|
+
|
51
|
+
it 'returns Log4r::INFO otherwise' do
|
52
|
+
expect(described_class.log4r_level_for('emergency')).to eq(Log4r::INFO)
|
53
|
+
expect(described_class.log4r_level_for(:emergency)).to eq(Log4r::INFO)
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
context '#logger' do
|
58
|
+
it 'returns the global Log4r logger for racker' do
|
59
|
+
expect(@instance.logger).to eq(Log4r::Logger['racker'])
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
@@ -0,0 +1,163 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'fileutils'
|
3
|
+
require 'securerandom'
|
4
|
+
|
5
|
+
RSpec.describe Racker::Processor do
|
6
|
+
DUMMY_TEMPLATE_PROC = proc { |t| nil }
|
7
|
+
|
8
|
+
context '::register_template' do
|
9
|
+
before(:all) do
|
10
|
+
@instance = described_class.new({})
|
11
|
+
end
|
12
|
+
|
13
|
+
it 'takes a block and an optional version argument' do
|
14
|
+
the_version = 'my_version'
|
15
|
+
the_block = DUMMY_TEMPLATE_PROC
|
16
|
+
|
17
|
+
captured_templates = @instance.capture_templates do
|
18
|
+
described_class.register_template(the_version, &the_block)
|
19
|
+
end
|
20
|
+
version, captured_template = captured_templates.first
|
21
|
+
expect(version).to eq(the_version)
|
22
|
+
expect(captured_template).to eq(the_block)
|
23
|
+
end
|
24
|
+
|
25
|
+
it 'uses a default value of "1" for version if none is provided' do
|
26
|
+
default_version = '1'
|
27
|
+
captured_templates = @instance.capture_templates do
|
28
|
+
described_class.register_template(&DUMMY_TEMPLATE_PROC)
|
29
|
+
end
|
30
|
+
version = captured_templates.first.first
|
31
|
+
expect(version).to eq(default_version)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
context '#capture_templates' do
|
36
|
+
before(:all) do
|
37
|
+
@instance = described_class.new(:quiet => true)
|
38
|
+
end
|
39
|
+
|
40
|
+
it 'captures [version, template_proc] pairs for each call to ::register_template' do
|
41
|
+
template_count = 5
|
42
|
+
dummy_templates = Hash.new do |hash, key|
|
43
|
+
hash[key] = DUMMY_TEMPLATE_PROC.dup
|
44
|
+
end
|
45
|
+
|
46
|
+
captured_templates = @instance.capture_templates do
|
47
|
+
template_count.times do |version|
|
48
|
+
described_class.register_template(version, &dummy_templates[version])
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
expect(captured_templates.length).to eq(template_count)
|
53
|
+
expect(captured_templates.flatten).to eq(dummy_templates.to_a.flatten)
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
context '#execute!' do
|
58
|
+
before(:all) do
|
59
|
+
@options = {
|
60
|
+
:output => "/tmp/#{SecureRandom.uuid}/this_directory_should_not_exist/template.json",
|
61
|
+
:knockout => '~~',
|
62
|
+
:quiet => true,
|
63
|
+
}
|
64
|
+
@output_path = @options[:output]
|
65
|
+
@instance = described_class.new(@options)
|
66
|
+
end
|
67
|
+
|
68
|
+
it 'raises a RuntimeError if any of the provided templates do not exist' do
|
69
|
+
@options[:templates] = [ '/tmp/this_template_should_not_exists.json' ]
|
70
|
+
expect { @instance.execute! }.to raise_error(RuntimeError)
|
71
|
+
end
|
72
|
+
|
73
|
+
it 'merges the templates with a knockout_prefix matching the provided knockout option' do
|
74
|
+
@options[:templates] = [
|
75
|
+
fixture_path('low_priority_template.rb'),
|
76
|
+
fixture_path('high_priority_template.rb'),
|
77
|
+
]
|
78
|
+
template = @instance.execute!
|
79
|
+
|
80
|
+
result = JSON.parse(template)
|
81
|
+
expect(result['variables']['password']).to eq(nil)
|
82
|
+
end
|
83
|
+
|
84
|
+
it 'merges the templates such that each template takes presedence over its predecessors' do
|
85
|
+
@options[:templates] = [
|
86
|
+
fixture_path('low_priority_template.rb'),
|
87
|
+
fixture_path('high_priority_template.rb'),
|
88
|
+
]
|
89
|
+
template = @instance.execute!
|
90
|
+
|
91
|
+
result = JSON.parse(template)
|
92
|
+
expect(result['variables']['iso_url']).to eq('priority.img')
|
93
|
+
end
|
94
|
+
|
95
|
+
it 'removes nil values from the generated template' do
|
96
|
+
@options[:templates] = [
|
97
|
+
fixture_path('low_priority_template.rb'),
|
98
|
+
fixture_path('high_priority_template.rb'),
|
99
|
+
]
|
100
|
+
template = @instance.execute!
|
101
|
+
|
102
|
+
result = JSON.parse(template)
|
103
|
+
expect(result['variables'].key?('nil')).to eq(false)
|
104
|
+
end
|
105
|
+
|
106
|
+
it 'outputs the computed template in JSON format' do
|
107
|
+
@options[:templates] = [
|
108
|
+
fixture_path('low_priority_template.rb'),
|
109
|
+
]
|
110
|
+
template = @instance.execute!
|
111
|
+
|
112
|
+
expect(JSON.parse(template)).to eq(parsed_low_priority_template)
|
113
|
+
end
|
114
|
+
|
115
|
+
end
|
116
|
+
|
117
|
+
context '#initialize' do
|
118
|
+
it 'sets the options instance variable to the given argument' do
|
119
|
+
opts = {}
|
120
|
+
instance = described_class.new(opts)
|
121
|
+
expect(instance.instance_variable_get(:@options).object_id).to eq(opts.object_id)
|
122
|
+
end
|
123
|
+
end
|
124
|
+
|
125
|
+
context '#load' do
|
126
|
+
before(:all) do
|
127
|
+
@fixture = fixture_path('low_priority_template.rb')
|
128
|
+
@options = {}
|
129
|
+
@instance = described_class.new(@options)
|
130
|
+
end
|
131
|
+
|
132
|
+
it 'puts the template file if a falsy :quiet option was provided' do
|
133
|
+
expect(@instance).to receive(:puts).exactly(3).times
|
134
|
+
|
135
|
+
@options.delete(:quiet)
|
136
|
+
@instance.load([@fixture])
|
137
|
+
@options[:quiet] = nil
|
138
|
+
@instance.load([@fixture])
|
139
|
+
@options[:quiet] = false
|
140
|
+
@instance.load([@fixture])
|
141
|
+
end
|
142
|
+
|
143
|
+
it 'puts no output if a truthy :quiet option was provided' do
|
144
|
+
expect(@instance).to_not receive(:puts)
|
145
|
+
|
146
|
+
@options[:quiet] = true
|
147
|
+
@instance.load([@fixture])
|
148
|
+
@options[:quiet] = Object.new
|
149
|
+
@instance.load([@fixture])
|
150
|
+
end
|
151
|
+
|
152
|
+
it 'loads each given template path' do
|
153
|
+
expect(Kernel).to receive(:load).with(@fixture).exactly(3).times
|
154
|
+
|
155
|
+
@options[:quiet] = true
|
156
|
+
@instance.load([
|
157
|
+
@fixture,
|
158
|
+
@fixture,
|
159
|
+
@fixture,
|
160
|
+
])
|
161
|
+
end
|
162
|
+
end
|
163
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: racker
|
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:
|
12
|
+
date: 2016-03-01 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: multi_json
|
@@ -210,7 +210,7 @@ dependencies:
|
|
210
210
|
requirements:
|
211
211
|
- - ~>
|
212
212
|
- !ruby/object:Gem::Version
|
213
|
-
version:
|
213
|
+
version: 0.26.1
|
214
214
|
type: :development
|
215
215
|
prerelease: false
|
216
216
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -218,7 +218,7 @@ dependencies:
|
|
218
218
|
requirements:
|
219
219
|
- - ~>
|
220
220
|
- !ruby/object:Gem::Version
|
221
|
-
version:
|
221
|
+
version: 0.26.1
|
222
222
|
- !ruby/object:Gem::Dependency
|
223
223
|
name: ruby_gntp
|
224
224
|
requirement: !ruby/object:Gem::Requirement
|
@@ -287,6 +287,7 @@ files:
|
|
287
287
|
- lib/racker/builders/virtualbox.rb
|
288
288
|
- lib/racker/builders/vmware.rb
|
289
289
|
- lib/racker/cli.rb
|
290
|
+
- lib/racker/log_support.rb
|
290
291
|
- lib/racker/processor.rb
|
291
292
|
- lib/racker/smash/deep_merge_modified.rb
|
292
293
|
- lib/racker/smash/mash.rb
|
@@ -294,7 +295,15 @@ files:
|
|
294
295
|
- lib/racker/template.rb
|
295
296
|
- lib/racker/version.rb
|
296
297
|
- lib/racker.rb
|
298
|
+
- spec/fixtures/high_priority_template.rb
|
299
|
+
- spec/fixtures/low_priority_template.rb
|
300
|
+
- spec/integration/output_to_file_spec.rb
|
301
|
+
- spec/integration/output_to_stdout_spec.rb
|
297
302
|
- spec/rcov.opts
|
303
|
+
- spec/spec_helper.rb
|
304
|
+
- spec/unit/cli_spec.rb
|
305
|
+
- spec/unit/log_support_spec.rb
|
306
|
+
- spec/unit/processor_spec.rb
|
298
307
|
- README.md
|
299
308
|
- LICENSE
|
300
309
|
- NOTICE
|
@@ -321,7 +330,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
321
330
|
version: '0'
|
322
331
|
segments:
|
323
332
|
- 0
|
324
|
-
hash:
|
333
|
+
hash: 259630501444106927
|
325
334
|
requirements: []
|
326
335
|
rubyforge_project:
|
327
336
|
rubygems_version: 1.8.23.2
|