jamie 0.1.0.beta3 → 0.1.0.beta4

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,226 @@
1
+ # -*- encoding: utf-8 -*-
2
+ #
3
+ # Author:: Fletcher Nichol (<fnichol@nichol.ca>)
4
+ #
5
+ # Copyright (C) 2012, Fletcher Nichol
6
+ #
7
+ # Licensed under the Apache License, Version 2.0 (the "License");
8
+ # you may not use this file except in compliance with the License.
9
+ # You may obtain a copy of the License at
10
+ #
11
+ # http://www.apache.org/licenses/LICENSE-2.0
12
+ #
13
+ # Unless required by applicable law or agreed to in writing, software
14
+ # distributed under the License is distributed on an "AS IS" BASIS,
15
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
+ # See the License for the specific language governing permissions and
17
+ # limitations under the License.
18
+
19
+ require_relative '../spec_helper'
20
+
21
+ describe Jamie::Config do
22
+ include FakeFS::SpecHelpers
23
+
24
+ let(:config) { Jamie::Config.new("/tmp/.jamie.yml") }
25
+
26
+ before do
27
+ FileUtils.mkdir_p("/tmp")
28
+ end
29
+
30
+ describe "#platforms" do
31
+
32
+ it "returns platforms loaded from a jamie.yml" do
33
+ stub_yaml!({ 'platforms' => [{ 'name' => 'one' }, { 'name' => 'two' }] })
34
+ config.platforms.size.must_equal 2
35
+ config.platforms[0].name.must_equal 'one'
36
+ config.platforms[1].name.must_equal 'two'
37
+ end
38
+
39
+ it "returns an empty Array if no platforms are given" do
40
+ stub_yaml!({})
41
+ config.platforms.must_equal []
42
+ end
43
+ end
44
+
45
+ describe "#suites" do
46
+
47
+ it "returns suites loaded from a jamie.yml" do
48
+ stub_yaml!({ 'suites' => [
49
+ { 'name' => 'one', 'run_list' => [] },
50
+ { 'name' => 'two', 'run_list' => [] },
51
+ ] })
52
+ config.suites.size.must_equal 2
53
+ config.suites[0].name.must_equal 'one'
54
+ config.suites[1].name.must_equal 'two'
55
+ end
56
+
57
+ it "returns an empty Array if no suites are given" do
58
+ stub_yaml!({})
59
+ config.suites.must_equal []
60
+ end
61
+
62
+ it "returns a suite with nil for data_bags_path by default" do
63
+ stub_yaml!({ 'suites' => [{ 'name' => 'one', 'run_list' => [] }] })
64
+ config.suites.first.data_bags_path.must_be_nil
65
+ end
66
+
67
+ it "retuns a suite with a common data_bags_path set" do
68
+ stub_yaml!({ 'suites' => [{ 'name' => 'one', 'run_list' => [] }] })
69
+ config.test_base_path = "/tmp/base"
70
+ FileUtils.mkdir_p "/tmp/base/data_bags"
71
+ config.suites.first.data_bags_path.must_equal "/tmp/base/data_bags"
72
+ end
73
+
74
+ it "retuns a suite with a suite-specific data_bags_path set" do
75
+ stub_yaml!({ 'suites' => [{ 'name' => 'cool', 'run_list' => [] }] })
76
+ config.test_base_path = "/tmp/base"
77
+ FileUtils.mkdir_p "/tmp/base/cool/data_bags"
78
+ config.suites.first.data_bags_path.must_equal "/tmp/base/cool/data_bags"
79
+ end
80
+
81
+ it "returns a suite with nil for roles_path by default" do
82
+ stub_yaml!({ 'suites' => [{ 'name' => 'one', 'run_list' => [] }] })
83
+ config.suites.first.roles_path.must_be_nil
84
+ end
85
+
86
+ it "returns a suite with a common roles_path set" do
87
+ stub_yaml!({ 'suites' => [{ 'name' => 'one', 'run_list' => [] }] })
88
+ config.test_base_path = "/tmp/base"
89
+ FileUtils.mkdir_p "/tmp/base/roles"
90
+ config.suites.first.roles_path.must_equal "/tmp/base/roles"
91
+ end
92
+
93
+ it "returns a suite with a suite-specific roles_path set" do
94
+ stub_yaml!({ 'suites' => [{ 'name' => 'mysuite', 'run_list' => [] }] })
95
+ config.test_base_path = "/tmp/base"
96
+ FileUtils.mkdir_p "/tmp/base/mysuite/roles"
97
+ config.suites.first.roles_path.must_equal "/tmp/base/mysuite/roles"
98
+ end
99
+ end
100
+
101
+ describe "#instances" do
102
+
103
+ it "returns instances loaded from a jamie.yml" do
104
+ stub_yaml!({
105
+ 'platforms' => [
106
+ { 'name' => 'p1' },
107
+ { 'name' => 'p2' },
108
+ ],
109
+ 'suites' => [
110
+ { 'name' => 's1', 'run_list' => [] },
111
+ { 'name' => 's2', 'run_list' => [] },
112
+ ]
113
+ })
114
+ config.instances.size.must_equal 4
115
+ config.instances.map { |i| i.name }.must_equal %w{s1-p1 s1-p2 s2-p1 s2-p2}
116
+ end
117
+
118
+ it "returns an instance containing a driver instance" do
119
+ stub_yaml!({
120
+ 'platforms' => [{ 'name' => 'platform', 'driver_plugin' => 'dummy' }],
121
+ 'suites' => [{ 'name' => 'suite', 'run_list' => [] }]
122
+ })
123
+ config.instances.first.driver.must_be_instance_of Jamie::Driver::Dummy
124
+ end
125
+
126
+ it "returns an instance with a driver initialized with jamie_root" do
127
+ stub_yaml!({
128
+ 'platforms' => [{ 'name' => 'platform', 'driver_plugin' => 'dummy' }],
129
+ 'suites' => [{ 'name' => 'suite', 'run_list' => [] }]
130
+ })
131
+ config.instances.first.driver[:jamie_root].must_equal "/tmp"
132
+ end
133
+
134
+ it "returns an instance with a driver initialized with passed in config" do
135
+ stub_yaml!({
136
+ 'platforms' => [
137
+ { 'name' => 'platform', 'driver_plugin' => 'dummy',
138
+ 'driver_config' => { 'foo' => 'bar' }
139
+ }
140
+ ],
141
+ 'suites' => [{ 'name' => 'suite', 'run_list' => [] }]
142
+ })
143
+ config.instances.first.driver[:foo].must_equal "bar"
144
+ end
145
+ end
146
+
147
+ describe "jamie.local.yml" do
148
+
149
+ it "merges in configuration with jamie.yml" do
150
+ stub_yaml!(".jamie.yml", {
151
+ 'platforms' => [{ 'name' => 'p1', 'driver_plugin' => 'dummy' }],
152
+ 'suites' => [{ 'name' => 's1', 'run_list' => [] }]
153
+ })
154
+ stub_yaml!(".jamie.local.yml", {
155
+ 'driver_config' => { 'foo' => 'bar' }
156
+ })
157
+ config.instances.first.driver[:foo].must_equal 'bar'
158
+ end
159
+
160
+ it "merges over configuration in jamie.yml" do
161
+ stub_yaml!(".jamie.yml", {
162
+ 'driver_config' => { 'foo' => 'nope' },
163
+ 'platforms' => [{ 'name' => 'p1', 'driver_plugin' => 'dummy' }],
164
+ 'suites' => [{ 'name' => 's1', 'run_list' => [] }]
165
+ })
166
+ stub_yaml!(".jamie.local.yml", {
167
+ 'driver_config' => { 'foo' => 'bar' }
168
+ })
169
+ config.instances.first.driver[:foo].must_equal 'bar'
170
+ end
171
+ end
172
+
173
+ describe "erb filtering" do
174
+
175
+ it "evaluates jamie.yml through erb before loading" do
176
+ FileUtils.mkdir_p "/tmp"
177
+ File.open("/tmp/.jamie.yml", "wb") do |f|
178
+ f.write <<-YAML.gsub(/^ {10}/, '')
179
+ ---
180
+ driver_plugin: dummy
181
+ platforms:
182
+ - name: <%= "AHH".downcase + "choo" %>
183
+ YAML
184
+ end
185
+ config.platforms.first.name.must_equal "ahhchoo"
186
+ end
187
+
188
+ it "evaluates jamie.local.yml through erb before loading" do
189
+ stub_yaml!({
190
+ 'platforms' => [{ 'name' => 'p1', 'driver_plugin' => 'dummy' }],
191
+ 'suites' => [{ 'name' => 's1', 'run_list' => [] }]
192
+ })
193
+ FileUtils.mkdir_p "/tmp"
194
+ File.open("/tmp/.jamie.local.yml", "wb") do |f|
195
+ f.write <<-YAML.gsub(/^ {10}/, '')
196
+ ---
197
+ driver_config:
198
+ <% %w{noodle mushroom}.each do |kind| %>
199
+ <%= kind %>: soup
200
+ <% end %>
201
+ YAML
202
+ end
203
+ config.instances.first.driver[:noodle].must_equal "soup"
204
+ config.instances.first.driver[:mushroom].must_equal "soup"
205
+ end
206
+ end
207
+
208
+ describe "#log_level" do
209
+
210
+ it "returns a default log_level of info" do
211
+ config.log_level.must_equal :info
212
+ end
213
+
214
+ it "returns an overridden log_level" do
215
+ config.log_level = :error
216
+ config.log_level.must_equal :error
217
+ end
218
+ end
219
+
220
+ private
221
+
222
+ def stub_yaml!(name = ".jamie.yml", hash)
223
+ FileUtils.mkdir_p "/tmp"
224
+ File.open("/tmp/#{name}", "wb") { |f| f.write(hash.to_yaml) }
225
+ end
226
+ end
@@ -0,0 +1,159 @@
1
+ # -*- encoding: utf-8 -*-
2
+ #
3
+ # Author:: Fletcher Nichol (<fnichol@nichol.ca>)
4
+ #
5
+ # Copyright (C) 2012, Fletcher Nichol
6
+ #
7
+ # Licensed under the Apache License, Version 2.0 (the "License");
8
+ # you may not use this file except in compliance with the License.
9
+ # You may obtain a copy of the License at
10
+ #
11
+ # http://www.apache.org/licenses/LICENSE-2.0
12
+ #
13
+ # Unless required by applicable law or agreed to in writing, software
14
+ # distributed under the License is distributed on an "AS IS" BASIS,
15
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
+ # See the License for the specific language governing permissions and
17
+ # limitations under the License.
18
+
19
+ require_relative '../spec_helper'
20
+
21
+ describe Jamie::Instance do
22
+
23
+ let(:suite) do
24
+ Jamie::Suite.new({ :name => 'suite',
25
+ :run_list => 'suite_list', :attributes => { :s => 'ss' } })
26
+ end
27
+
28
+ let(:platform) do
29
+ Jamie::Platform.new({ :name => 'platform',
30
+ :run_list => 'platform_list', :attributes => { :p => 'pp' } })
31
+ end
32
+
33
+ let(:driver) { Jamie::Driver::Dummy.new({}) }
34
+
35
+ let(:jr) { Jamie::Jr.new(suite.name) }
36
+
37
+ let(:opts) do
38
+ { :suite => suite, :platform => platform, :driver => driver, :jr => jr }
39
+ end
40
+
41
+ let(:instance) { Jamie::Instance.new(opts) }
42
+
43
+ before do
44
+ Celluloid.logger = Logger.new(StringIO.new)
45
+ end
46
+
47
+ it "raises an ArgumentError if suite is missing" do
48
+ opts.delete(:suite)
49
+ proc { Jamie::Instance.new(opts) }.must_raise Jamie::ClientError
50
+ end
51
+
52
+ it "raises an ArgumentError if platform is missing" do
53
+ opts.delete(:platform)
54
+ proc { Jamie::Instance.new(opts) }.must_raise Jamie::ClientError
55
+ end
56
+
57
+ it "returns suite" do
58
+ instance.suite.must_equal suite
59
+ end
60
+
61
+ it "returns platform" do
62
+ instance.platform.must_equal platform
63
+ end
64
+
65
+ it "returns an instance of Jr" do
66
+ instance.jr.must_be_instance_of Jamie::Jr
67
+ end
68
+
69
+ describe "#name" do
70
+
71
+ def combo(suite_name, platform_name)
72
+ opts[:suite] = Jamie::Suite.new(
73
+ :name => suite_name, :run_list => []
74
+ )
75
+ opts[:platform] = Jamie::Platform.new(
76
+ :name => platform_name
77
+ )
78
+ Jamie::Instance.new(opts)
79
+ end
80
+
81
+ it "combines the suite and platform names with a dash" do
82
+ combo('suite', 'platform').name.must_equal "suite-platform"
83
+ end
84
+
85
+ it "squashes periods" do
86
+ combo('suite.ness', 'platform').name.must_equal "suiteness-platform"
87
+ combo('suite', 'platform.s').name.must_equal "suite-platforms"
88
+ combo('s.s.', '.p.p').name.must_equal "ss-pp"
89
+ end
90
+
91
+ it "transforms underscores to dashes" do
92
+ combo('suite_ness', 'platform').name.must_equal "suite-ness-platform"
93
+ combo('suite', 'platform-s').name.must_equal "suite-platform-s"
94
+ combo('_s__s_', 'pp_').name.must_equal "-s--s--pp-"
95
+ end
96
+ end
97
+
98
+ describe "#run_list" do
99
+
100
+ def combo(suite_list, platform_list)
101
+ opts[:suite] = Jamie::Suite.new(
102
+ :name => 'suite', :run_list => suite_list
103
+ )
104
+ opts[:platform] = Jamie::Platform.new(
105
+ :name => 'platform', :run_list => platform_list
106
+ )
107
+ Jamie::Instance.new(opts)
108
+ end
109
+
110
+ it "combines the platform then suite run_lists" do
111
+ combo(%w{s1 s2}, %w{p1 p2}).run_list.must_equal %w{p1 p2 s1 s2}
112
+ end
113
+
114
+ it "uses the suite run_list only when platform run_list is empty" do
115
+ combo(%w{sa sb}, nil).run_list.must_equal %w{sa sb}
116
+ end
117
+
118
+ it "returns an emtpy Array if both run_lists are empty" do
119
+ combo([], nil).run_list.must_equal []
120
+ end
121
+ end
122
+
123
+ describe "#attributes" do
124
+
125
+ def combo(suite_attrs, platform_attrs)
126
+ opts[:suite] = Jamie::Suite.new(
127
+ :name => 'suite', :run_list => [], :attributes => suite_attrs
128
+ )
129
+ opts[:platform] = Jamie::Platform.new(
130
+ :name => 'platform', :attributes => platform_attrs
131
+ )
132
+ Jamie::Instance.new(opts)
133
+ end
134
+
135
+ it "merges suite and platform hashes together" do
136
+ combo(
137
+ { :suite => { :s1 => 'sv1' } },
138
+ { :suite => { :p1 => 'pv1' }, :platform => 'pp' }
139
+ ).attributes.must_equal({
140
+ :suite => { :s1 => 'sv1', :p1 => 'pv1' },
141
+ :platform => 'pp'
142
+ })
143
+ end
144
+
145
+ it "merges suite values over platform values" do
146
+ combo(
147
+ { :common => { :c1 => 'xxx' } },
148
+ { :common => { :c1 => 'cv1', :c2 => 'cv2' } },
149
+ ).attributes.must_equal({
150
+ :common => { :c1 => 'xxx', :c2 => 'cv2' }
151
+ })
152
+ end
153
+ end
154
+
155
+ it "#dna combines attributes with the run_list" do
156
+ instance.dna.must_equal({ :s => 'ss', :p => 'pp',
157
+ :run_list => ['platform_list', 'suite_list'] })
158
+ end
159
+ end
@@ -0,0 +1,45 @@
1
+ # -*- encoding: utf-8 -*-
2
+ #
3
+ # Author:: Fletcher Nichol (<fnichol@nichol.ca>)
4
+ #
5
+ # Copyright (C) 2012, Fletcher Nichol
6
+ #
7
+ # Licensed under the Apache License, Version 2.0 (the "License");
8
+ # you may not use this file except in compliance with the License.
9
+ # You may obtain a copy of the License at
10
+ #
11
+ # http://www.apache.org/licenses/LICENSE-2.0
12
+ #
13
+ # Unless required by applicable law or agreed to in writing, software
14
+ # distributed under the License is distributed on an "AS IS" BASIS,
15
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
+ # See the License for the specific language governing permissions and
17
+ # limitations under the License.
18
+
19
+ require_relative '../spec_helper'
20
+
21
+ describe Jamie::Platform do
22
+
23
+ let(:opts) do ; { :name => 'plata' } ; end
24
+ let(:platform) { Jamie::Platform.new(opts) }
25
+
26
+ it "raises an ArgumentError if name is missing" do
27
+ opts.delete(:name)
28
+ proc { Jamie::Platform.new(opts) }.must_raise Jamie::ClientError
29
+ end
30
+
31
+ it "returns an empty Array given no run_list" do
32
+ platform.run_list.must_equal []
33
+ end
34
+
35
+ it "returns an empty Hash given no attributes" do
36
+ platform.attributes.must_equal Hash.new
37
+ end
38
+
39
+ it "returns attributes from constructor" do
40
+ opts.merge!({ :run_list => ['a', 'b'], :attributes => { :c => 'd' } })
41
+ platform.name.must_equal 'plata'
42
+ platform.run_list.must_equal ['a', 'b']
43
+ platform.attributes.must_equal({ :c => 'd' })
44
+ end
45
+ end
@@ -0,0 +1,57 @@
1
+ # -*- encoding: utf-8 -*-
2
+ #
3
+ # Author:: Fletcher Nichol (<fnichol@nichol.ca>)
4
+ #
5
+ # Copyright (C) 2012, Fletcher Nichol
6
+ #
7
+ # Licensed under the Apache License, Version 2.0 (the "License");
8
+ # you may not use this file except in compliance with the License.
9
+ # You may obtain a copy of the License at
10
+ #
11
+ # http://www.apache.org/licenses/LICENSE-2.0
12
+ #
13
+ # Unless required by applicable law or agreed to in writing, software
14
+ # distributed under the License is distributed on an "AS IS" BASIS,
15
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
+ # See the License for the specific language governing permissions and
17
+ # limitations under the License.
18
+
19
+ require_relative '../spec_helper'
20
+
21
+ describe Jamie::Suite do
22
+
23
+ let(:opts) do ; { :name => 'suitezy', :run_list => ['doowah'] } ; end
24
+ let(:suite) { Jamie::Suite.new(opts) }
25
+
26
+ it "raises an ArgumentError if name is missing" do
27
+ opts.delete(:name)
28
+ proc { Jamie::Suite.new(opts) }.must_raise Jamie::ClientError
29
+ end
30
+
31
+ it "raises an ArgumentError if run_list is missing" do
32
+ opts.delete(:run_list)
33
+ proc { Jamie::Suite.new(opts) }.must_raise Jamie::ClientError
34
+ end
35
+
36
+ it "returns an empty Hash given no attributes" do
37
+ suite.attributes.must_equal Hash.new
38
+ end
39
+
40
+ it "returns nil given no data_bags_path" do
41
+ suite.data_bags_path.must_be_nil
42
+ end
43
+
44
+ it "returns nil given no roles_path" do
45
+ suite.roles_path.must_be_nil
46
+ end
47
+
48
+ it "returns attributes from constructor" do
49
+ opts.merge!({ :attributes => { :a => 'b' }, :data_bags_path => 'crazy',
50
+ :roles_path => 'town' })
51
+ suite.name.must_equal 'suitezy'
52
+ suite.run_list.must_equal ['doowah']
53
+ suite.attributes.must_equal({ :a => 'b' })
54
+ suite.data_bags_path.must_equal 'crazy'
55
+ suite.roles_path.must_equal 'town'
56
+ end
57
+ end