dployr 0.0.1

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.
data/spec/init_spec.rb ADDED
@@ -0,0 +1,27 @@
1
+ require 'spec_helper'
2
+
3
+ describe Dployr::Init do
4
+ describe "instance configuration" do
5
+ pwd = Dir.pwd
6
+ fixtures = File.join File.dirname(__FILE__), 'fixtures'
7
+
8
+ before :all do
9
+ Dir.chdir fixtures
10
+ @dployr = Dployr::Init.new
11
+ end
12
+
13
+ after :all do
14
+ Dir.chdir pwd
15
+ end
16
+
17
+ describe "file discovery" do
18
+ it "should discover the file" do
19
+ @dployr.file_path.should eql "#{fixtures}/Dployrfile"
20
+ end
21
+
22
+ it "should create a new config instance" do
23
+ @dployr.config.should be_instance_of Dployr::Configuration
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,2 @@
1
+ require 'rubygems'
2
+ require 'dployr'
@@ -0,0 +1,317 @@
1
+ require 'spec_helper'
2
+ require 'dployr/utils'
3
+
4
+ describe Dployr::Utils do
5
+
6
+ describe :has do
7
+ context "when exists" do
8
+ let(:hash) {
9
+ { key: "val", key: "another" }
10
+ }
11
+
12
+ it "should exist a string key" do
13
+ Dployr::Utils.has(hash, 'key').should be_true
14
+ end
15
+
16
+ it "should exist a symbol key" do
17
+ Dployr::Utils.has(hash, :key).should be_true
18
+ end
19
+ end
20
+
21
+ context "when not exists" do
22
+ it "should exist a string key" do
23
+ Dployr::Utils.has(hash, 'key').should be_false
24
+ end
25
+
26
+ it "should exist a symbol key" do
27
+ Dployr::Utils.has(hash, :key).should be_false
28
+ end
29
+ end
30
+ end
31
+
32
+ describe :get_by_key do
33
+ context "when exists" do
34
+ let(:hash) {
35
+ { "key" => "val", key: "another", "str" => "text" }
36
+ }
37
+
38
+ it "should get a value by string key" do
39
+ Dployr::Utils.get_by_key(hash, 'key').should eql "val"
40
+ end
41
+
42
+ it "should get a value by symbol key" do
43
+ Dployr::Utils.get_by_key(hash, :key).should eql "another"
44
+ end
45
+
46
+ it "should get a value by symbol key" do
47
+ Dployr::Utils.get_by_key(hash, "str").should eql "text"
48
+ end
49
+ end
50
+
51
+ context "when not exists" do
52
+ it "should get a value by string key" do
53
+ Dployr::Utils.get_by_key({}, 'key').should eql nil
54
+ end
55
+
56
+ it "should get a value by symbol key" do
57
+ Dployr::Utils.get_by_key({}, :key).should eql nil
58
+ end
59
+ end
60
+ end
61
+
62
+ describe :merge do
63
+ describe "multiple hashes with one level" do
64
+ before do
65
+ x = { a: 10, b: 20 }
66
+ y = { a: 100, c: 200 }
67
+ z = { c: 300, d: 400 }
68
+ @result = Dployr::Utils.merge x, y, z
69
+ end
70
+
71
+ it "should override the :a value" do
72
+ @result[:a].should eq 100
73
+ end
74
+
75
+ it "should not merge the :b value" do
76
+ @result[:b].should eq 20
77
+ end
78
+
79
+ it "should override the :c value" do
80
+ @result[:c].should eq 300
81
+ end
82
+
83
+ it "should override the :c value" do
84
+ @result[:d].should eq 400
85
+ end
86
+ end
87
+
88
+ describe "nested hashes with strings and arrays" do
89
+ before do
90
+ x = { a: 10, b: { a: [1], b: "b" } }
91
+ y = { a: 100, b: { a: [2,3], c: "c" } }
92
+ @result = Dployr::Utils.merge x, y
93
+ end
94
+
95
+ it "should override the :a value" do
96
+ @result[:a].should eq 100
97
+ end
98
+
99
+ context "merge :b" do
100
+ subject { @result[:b] }
101
+ it { should be_a Hash }
102
+ it { should have(2).items }
103
+ end
104
+ end
105
+ end
106
+
107
+ describe :parse_matrix do
108
+ describe "replacement using hash" do
109
+ data = "name=dployr ; lang = ruby"
110
+
111
+ before do
112
+ @result = Dployr::Utils.parse_matrix data
113
+ end
114
+
115
+ it "should return a valid type" do
116
+ @result.should be_a Hash
117
+ end
118
+
119
+ it "should have a valid number of items" do
120
+ @result.should have(2).items
121
+ end
122
+
123
+ it "should exists the name key" do
124
+ @result.should have_key 'name'
125
+ end
126
+
127
+ it "should have a valid value" do
128
+ @result['name'].should eql 'dployr'
129
+ end
130
+
131
+ it "should exists the lang key" do
132
+ @result.should have_key 'lang'
133
+ end
134
+
135
+ it "should have a valid value" do
136
+ @result['lang'].should eql 'ruby'
137
+ end
138
+ end
139
+ end
140
+
141
+ describe :parse_flags do
142
+ describe "replacement using hash" do
143
+ data = "--name dployr --lang ruby "
144
+
145
+ before do
146
+ @result = Dployr::Utils.parse_flags data
147
+ end
148
+
149
+ it "should return a valid type" do
150
+ @result.should be_a Hash
151
+ end
152
+
153
+ it "should have a valid number of items" do
154
+ @result.should have(2).items
155
+ end
156
+
157
+ it "should exists the name key" do
158
+ @result.should have_key 'name'
159
+ end
160
+
161
+ it "should have a valid value" do
162
+ @result['name'].should eql 'dployr'
163
+ end
164
+
165
+ it "should exists the lang key" do
166
+ @result.should have_key 'lang'
167
+ end
168
+
169
+ it "should have a valid value" do
170
+ @result['lang'].should eql 'ruby'
171
+ end
172
+ end
173
+ end
174
+
175
+ describe :replace_env_vars do
176
+ describe "environment variable" do
177
+ before :all do
178
+ ENV['DPLOYR'] = 'sample value'
179
+ end
180
+
181
+ before :all do
182
+ @result = Dployr::Utils.replace_env_vars "Env var: ${DPLOYR}"
183
+ end
184
+
185
+ after :all do
186
+ ENV.delete 'DPLOYR'
187
+ end
188
+
189
+ it "should replace the name" do
190
+ @result.should eql "Env var: sample value"
191
+ end
192
+ end
193
+
194
+ describe "nonexistent" do
195
+ before :all do
196
+ @result = Dployr::Utils.replace_env_vars "Env var: ${NONEXISTENT}"
197
+ end
198
+
199
+ it "should replace the name" do
200
+ @result.should eql "Env var: "
201
+ end
202
+ end
203
+ end
204
+
205
+ describe :replace_placeholders do
206
+ describe "replacement using hash" do
207
+ let(:data) {
208
+ { name: "John" }
209
+ }
210
+
211
+ before do
212
+ @result = Dployr::Utils.replace_placeholders "My name is %{name}", data
213
+ end
214
+
215
+ it "should replace the name" do
216
+ @result.should eql "My name is John"
217
+ end
218
+ end
219
+
220
+ describe "non existent values" do
221
+ let(:data) {
222
+ { salutation: "Hi" }
223
+ }
224
+
225
+ it "should replace raise an error if value do not exists" do
226
+ begin
227
+ @result = Dployr::Utils.replace_placeholders "%{salutation}, my name is %{name}", data
228
+ rescue Exception => e
229
+ e.should be_instance_of KeyError
230
+ end
231
+ end
232
+ end
233
+ end
234
+
235
+ describe :template do
236
+ describe "replacement using hash" do
237
+ let(:data) {
238
+ { name: "John" }
239
+ }
240
+
241
+ before do
242
+ @result = Dployr::Utils.template "My name is %{name}", data
243
+ end
244
+
245
+ it "should replace the name" do
246
+ @result.should eql "My name is John"
247
+ end
248
+ end
249
+
250
+ describe "multiple values" do
251
+ let(:data) {
252
+ { name: "John", salutation: "Hi" }
253
+ }
254
+
255
+ before do
256
+ @result = Dployr::Utils.template "%{salutation}, my name is %{name}", data
257
+ end
258
+
259
+ it "should replace both values" do
260
+ @result.should eql "Hi, my name is John"
261
+ end
262
+ end
263
+
264
+ describe "non existent values" do
265
+ let(:data) {
266
+ { salutation: "Hi" }
267
+ }
268
+
269
+ it "should raise an exception error if do not exist the variable" do
270
+ begin
271
+ @result = Dployr::Utils.template "%{salutation}, my name is %{name}", data
272
+ rescue Exception => e
273
+ e.should be_instance_of ArgumentError
274
+ end
275
+ end
276
+ end
277
+ end
278
+
279
+ describe :traverse_map do
280
+ describe "multi-type hash" do
281
+ let(:hash) {
282
+ {
283
+ text: { name: "My name is %{name}" },
284
+ array: [ "Another %{name}", { type: "%{type}"} ],
285
+ nonexistent: "this is %{name}"
286
+ }
287
+ }
288
+
289
+ let(:values) {
290
+ { name: "Beaker", type: "muppet" }
291
+ }
292
+
293
+ before do
294
+ @result = Dployr::Utils.traverse_map(hash) do |str|
295
+ Dployr::Utils.template str, values
296
+ end
297
+ end
298
+
299
+ it "should replace the name" do
300
+ @result[:text][:name].should eql "My name is Beaker"
301
+ end
302
+
303
+ it "should replace the value in an array" do
304
+ @result[:array][0].should eql "Another Beaker"
305
+ end
306
+
307
+ it "should replace the value from the nested hash in array" do
308
+ @result[:array][1][:type].should eql "muppet"
309
+ end
310
+
311
+ it "should remove nonexistent template values" do
312
+ @result[:nonexistent].should eql "this is Beaker"
313
+ end
314
+ end
315
+ end
316
+
317
+ end
metadata ADDED
@@ -0,0 +1,146 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: dployr
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Tomas Aparicio
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-04-21 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: fog
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '1.21'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.21'
27
+ - !ruby/object:Gem::Dependency
28
+ name: deep_merge
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: '1.0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: '1.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ~>
46
+ - !ruby/object:Gem::Version
47
+ version: '10'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: '10'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: '2'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ~>
67
+ - !ruby/object:Gem::Version
68
+ version: '2'
69
+ description: Multicloud management and deployment with asteroids made simple with
70
+ a rich programmatic API and featured CLI
71
+ email:
72
+ - nerds@innotechapp.com
73
+ executables:
74
+ - dployr
75
+ extensions: []
76
+ extra_rdoc_files:
77
+ - README.md
78
+ files:
79
+ - .editorconfig
80
+ - .gitignore
81
+ - .travis.yml
82
+ - Gemfile
83
+ - LICENSE
84
+ - README.md
85
+ - Rakefile
86
+ - bin/dployr
87
+ - dployr.gemspec
88
+ - lib/dployr.rb
89
+ - lib/dployr/cli/cli.rb
90
+ - lib/dployr/cli/commands.rb
91
+ - lib/dployr/cli/commands/config.rb
92
+ - lib/dployr/compute/client.rb
93
+ - lib/dployr/config/constants.rb
94
+ - lib/dployr/config/create.rb
95
+ - lib/dployr/config/file_utils.rb
96
+ - lib/dployr/config/instance.rb
97
+ - lib/dployr/configuration.rb
98
+ - lib/dployr/init.rb
99
+ - lib/dployr/logger.rb
100
+ - lib/dployr/utils.rb
101
+ - lib/dployr/version.rb
102
+ - spec/config_file_utils_spec.rb
103
+ - spec/config_instance_spec.rb
104
+ - spec/configuration_spec.rb
105
+ - spec/fixtures/Dployrfile
106
+ - spec/fixtures/Dployrfile.yml
107
+ - spec/fog_spec_.rb
108
+ - spec/init_spec.rb
109
+ - spec/spec_helper.rb
110
+ - spec/utils_spec.rb
111
+ homepage: https://github.com/innotech/dployr
112
+ licenses:
113
+ - MIT
114
+ metadata: {}
115
+ post_install_message:
116
+ rdoc_options:
117
+ - --charset=UTF-8
118
+ require_paths:
119
+ - lib
120
+ required_ruby_version: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - '>='
123
+ - !ruby/object:Gem::Version
124
+ version: 1.9.3
125
+ required_rubygems_version: !ruby/object:Gem::Requirement
126
+ requirements:
127
+ - - '>='
128
+ - !ruby/object:Gem::Version
129
+ version: '0'
130
+ requirements: []
131
+ rubyforge_project: dployr
132
+ rubygems_version: 2.0.6
133
+ signing_key:
134
+ specification_version: 4
135
+ summary: Multicloud management and deployment with asteroids made simple
136
+ test_files:
137
+ - spec/config_file_utils_spec.rb
138
+ - spec/config_instance_spec.rb
139
+ - spec/configuration_spec.rb
140
+ - spec/fixtures/Dployrfile
141
+ - spec/fixtures/Dployrfile.yml
142
+ - spec/fog_spec_.rb
143
+ - spec/init_spec.rb
144
+ - spec/spec_helper.rb
145
+ - spec/utils_spec.rb
146
+ has_rdoc: