vanagon 0.9.3 → 0.10.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,176 @@
1
+ require 'vanagon/environment'
2
+
3
+ describe "Vanagon::Environment" do
4
+ before :all do
5
+ @good_names = %w(name _name NAME _NAME NAME123 _123NAME)
6
+ @bad_names = ['no-name', '!name', '.name', '123name_', 1, '-name']
7
+ @good_values =[
8
+ 'valuable',
9
+ 'most\ valuable',
10
+ 'extremely-valuable',
11
+ 'VALUE_BEYOND_MEASURE',
12
+ 2004,
13
+ 2007,
14
+ ]
15
+ @bad_values = [
16
+ %w(an array of strings),
17
+ 19.81,
18
+ Object.new,
19
+ Tempfile.new('captain_planet'),
20
+ lambda { |x| "#{x}" }
21
+ ]
22
+
23
+ @good_hash = @good_names.zip(@good_values.shuffle).to_h
24
+ @bad_hash = @bad_names.zip(@bad_values.shuffle).to_h
25
+
26
+ @good_names_bad_values = @good_names.zip(@bad_values.shuffle).to_h
27
+ @bad_names_good_values = @bad_names.zip(@good_values.shuffle).to_h
28
+ end
29
+
30
+ before :each do
31
+ @local_env = Vanagon::Environment.new
32
+ end
33
+
34
+ describe "#[]" do
35
+ before do
36
+ @key = @good_names.sample
37
+ @value = @good_values.sample
38
+ @local_env[@key] = @value
39
+ end
40
+
41
+ it "returns values for matching keys" do
42
+ expect(@local_env[@key])
43
+ .to eq(@value)
44
+ end
45
+ end
46
+
47
+ describe "#[]=" do
48
+ it "accepts and assigns valid keys and values" do
49
+ @good_hash.each_pair do |key, value|
50
+ expect { @local_env[key] = value }
51
+ .to_not raise_error
52
+ end
53
+ end
54
+
55
+ it "raises an ArgumentError for invalid keys" do
56
+ @bad_names_good_values.each_pair do |key, value|
57
+ expect { @local_env[key] = value }
58
+ .to raise_error(ArgumentError)
59
+ end
60
+ end
61
+
62
+ it "raises an ArgumentError for invalid values" do
63
+ @good_names_bad_values.each_pair do |key, value|
64
+ expect { @local_env[key] = value }
65
+ .to raise_error(ArgumentError)
66
+ end
67
+ end
68
+ end
69
+
70
+ describe "#keys" do
71
+ before do
72
+ @good_hash.each_pair do |key, value|
73
+ @local_env[key] = value
74
+ end
75
+ end
76
+
77
+ it "returns an array of all keys in a populated Environment" do
78
+ # This is a little bit of a shell game. Array comparisons in Ruby rely
79
+ # on the order of the elements, not just the contents of the array.
80
+ # By randomizing our element order going in, and then using a set
81
+ # intersection (#&) and sorting the output, we can then compare the
82
+ # intersection against our sorted control group (@good_names).
83
+ # That should shake out if we have too many or too few keys.
84
+ expect(
85
+ (@local_env.keys.shuffle & @good_names.shuffle).sort
86
+ ).to eq(@good_names.sort)
87
+ end
88
+ end
89
+
90
+ describe "#values" do
91
+ before do
92
+ @good_hash.each_pair do |key, value|
93
+ @local_env[key] = value
94
+ end
95
+ end
96
+
97
+ it "returns an array of all values in a populated Environment" do
98
+ # Same "juggle some values" dance as #keys, except that #values
99
+ # may contain Integers or Strings and they are not directly comparable.
100
+ # We'll compare the hashed values of each element in the returned array
101
+ # against the hashed value of each element in the expected array instead.
102
+ expect(
103
+ (@local_env.values.shuffle & @good_values.shuffle)
104
+ .sort { |x, y| x.hash <=> y.hash }
105
+ ).to eq(@good_values.sort { |x, y| x.hash <=> y.hash })
106
+ end
107
+ end
108
+
109
+ describe "#merge" do
110
+ before do
111
+ @new_env = Vanagon::Environment.new
112
+ @new_env['__merge'] = "true"
113
+ @merged_values = @local_env.values + @new_env.values
114
+ @merged_keys = @local_env.keys + @new_env.keys
115
+ @merged_env = @local_env.merge(@new_env)
116
+ end
117
+
118
+ it "returns a new Environment Object" do
119
+ expect(@local_env.merge(@new_env).equal? @local_env)
120
+ .to be false
121
+ end
122
+
123
+ it "combines the keys of both Environments" do
124
+ expect(@merged_env.keys.sort { |x, y| x.hash <=> y.hash })
125
+ .to eq(@merged_keys.sort { |x, y| x.hash <=> y.hash })
126
+ end
127
+
128
+ it "combines the values of both Environments" do
129
+ expect(@merged_env.values.sort { |x, y| x.hash <=> y.hash })
130
+ .to eq(@merged_values.sort { |x, y| x.hash <=> y.hash })
131
+ end
132
+ end
133
+
134
+ describe "#merge!" do
135
+ before do
136
+ @new_env = Vanagon::Environment.new
137
+ @new_env['__merge'] = "true"
138
+ @merged_values = @local_env.values + @new_env.values
139
+ @merged_keys = @local_env.keys + @new_env.keys
140
+ @local_obj_id = @local_env.object_id
141
+ end
142
+
143
+ before do
144
+ @local_env.merge! @new_env
145
+ end
146
+
147
+ it "does not create a new Environment Object" do
148
+ expect(@local_env.object_id == @local_obj_id)
149
+ .to be true
150
+ end
151
+
152
+ it "combines the keys of both Environments" do
153
+ expect(@local_env.keys.sort { |x, y| x.hash <=> y.hash })
154
+ .to eq(@merged_keys.sort { |x, y| x.hash <=> y.hash })
155
+ end
156
+
157
+ it "combines the values of both Environments" do
158
+ expect(@local_env.values.sort { |x, y| x.hash <=> y.hash })
159
+ .to eq(@merged_values.sort { |x, y| x.hash <=> y.hash })
160
+ end
161
+ end
162
+
163
+ describe "#to_a" do
164
+ it "converts an Environment to an Array of Strings" do
165
+ expect(@local_env.to_a.select { |v| v.is_a? String }.sort)
166
+ .to eq(@local_env.to_a.sort)
167
+ end
168
+ end
169
+
170
+ describe "#to_s" do
171
+ it "correctly converts an Environment to a String" do
172
+ expect(@local_env.to_s.shellsplit)
173
+ .to eq(@local_env.to_a)
174
+ end
175
+ end
176
+ end
data/spec/spec_helper.rb CHANGED
@@ -1,15 +1,25 @@
1
- require 'tmpdir'
2
- require 'vanagon'
3
-
1
+ # Coverage configuration should come ahead of everything else.
2
+ # This will ensure that code paths are followed appropriately.
4
3
  if ENV["COVERAGE"]
5
4
  require 'simplecov'
6
5
  SimpleCov.start do
7
6
  add_filter '.bundle'
8
7
  add_filter 'spec'
9
8
  add_filter 'vendor'
9
+
10
+ # Define a minimum coverage score, and fail if it's not met.
11
+ # This should probably be a Float, not an Integer but as
12
+ # long as it's not a String it's probably fine.
13
+ #
14
+ # The coverage score on 2017-02-07 for commit 770b67db was 71.85
15
+ # - Ryan McKern, 2017-02-07
16
+ minimum_coverage ENV['MINIMUM_SCORE'] || 70.00
10
17
  end
11
18
  end
12
19
 
20
+ require 'tmpdir'
21
+ require 'vanagon'
22
+
13
23
  RSpec.configure do |c|
14
24
  c.before do
15
25
  allow_any_instance_of(Vanagon::Component::Source::Git).to receive(:puts)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vanagon
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.3
4
+ version: 0.10.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Puppet Labs
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-03-01 00:00:00.000000000 Z
11
+ date: 2017-02-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: git
@@ -96,6 +96,7 @@ files:
96
96
  - lib/vanagon/engine/hardware.rb
97
97
  - lib/vanagon/engine/local.rb
98
98
  - lib/vanagon/engine/pooler.rb
99
+ - lib/vanagon/environment.rb
99
100
  - lib/vanagon/errors.rb
100
101
  - lib/vanagon/extensions/hashable.rb
101
102
  - lib/vanagon/extensions/ostruct/json.rb
@@ -131,6 +132,7 @@ files:
131
132
  - resources/deb/preinst.erb
132
133
  - resources/deb/prerm.erb
133
134
  - resources/deb/rules.erb
135
+ - resources/metrics/profiling_shell.sh
134
136
  - resources/osx/postinstall.erb
135
137
  - resources/osx/preinstall.erb
136
138
  - resources/osx/project-installer.xml.erb
@@ -199,6 +201,7 @@ files:
199
201
  - spec/lib/vanagon/engine/hardware_spec.rb
200
202
  - spec/lib/vanagon/engine/local_spec.rb
201
203
  - spec/lib/vanagon/engine/pooler_spec.rb
204
+ - spec/lib/vanagon/environment_spec.rb
202
205
  - spec/lib/vanagon/extensions/ostruct/json_spec.rb
203
206
  - spec/lib/vanagon/extensions/set/json_spec.rb
204
207
  - spec/lib/vanagon/extensions/string_spec.rb
@@ -235,41 +238,42 @@ required_rubygems_version: !ruby/object:Gem::Requirement
235
238
  version: '0'
236
239
  requirements: []
237
240
  rubyforge_project:
238
- rubygems_version: 2.2.5
241
+ rubygems_version: 2.6.8
239
242
  signing_key:
240
243
  specification_version: 3
241
244
  summary: All of your packages will fit into this van with this one simple trick.
242
245
  test_files:
243
- - spec/lib/makefile_spec.rb
244
246
  - spec/lib/vanagon/common/pathname_spec.rb
245
247
  - spec/lib/vanagon/common/user_spec.rb
246
- - spec/lib/vanagon/component/dsl_spec.rb
247
- - spec/lib/vanagon/component/rules_spec.rb
248
248
  - spec/lib/vanagon/component/source/git_spec.rb
249
249
  - spec/lib/vanagon/component/source/http_spec.rb
250
250
  - spec/lib/vanagon/component/source/local_spec.rb
251
251
  - spec/lib/vanagon/component/source_spec.rb
252
- - spec/lib/vanagon/component_spec.rb
253
- - spec/lib/vanagon/driver_spec.rb
254
- - spec/lib/vanagon/engine/always_be_scheduling_spec.rb
252
+ - spec/lib/vanagon/component/dsl_spec.rb
253
+ - spec/lib/vanagon/component/rules_spec.rb
255
254
  - spec/lib/vanagon/engine/base_spec.rb
255
+ - spec/lib/vanagon/engine/always_be_scheduling_spec.rb
256
256
  - spec/lib/vanagon/engine/docker_spec.rb
257
257
  - spec/lib/vanagon/engine/ec2_spec.rb
258
258
  - spec/lib/vanagon/engine/hardware_spec.rb
259
259
  - spec/lib/vanagon/engine/local_spec.rb
260
260
  - spec/lib/vanagon/engine/pooler_spec.rb
261
- - spec/lib/vanagon/extensions/ostruct/json_spec.rb
262
- - spec/lib/vanagon/extensions/set/json_spec.rb
263
- - spec/lib/vanagon/extensions/string_spec.rb
264
- - spec/lib/vanagon/optparse_spec.rb
261
+ - spec/lib/vanagon/platform/solaris_11_spec.rb
265
262
  - spec/lib/vanagon/platform/deb_spec.rb
266
263
  - spec/lib/vanagon/platform/dsl_spec.rb
267
264
  - spec/lib/vanagon/platform/rpm/aix_spec.rb
268
265
  - spec/lib/vanagon/platform/rpm_spec.rb
269
- - spec/lib/vanagon/platform/solaris_11_spec.rb
270
266
  - spec/lib/vanagon/platform/windows_spec.rb
271
- - spec/lib/vanagon/platform_spec.rb
272
267
  - spec/lib/vanagon/project/dsl_spec.rb
268
+ - spec/lib/vanagon/extensions/ostruct/json_spec.rb
269
+ - spec/lib/vanagon/extensions/set/json_spec.rb
270
+ - spec/lib/vanagon/extensions/string_spec.rb
271
+ - spec/lib/vanagon/optparse_spec.rb
272
+ - spec/lib/vanagon/platform_spec.rb
273
273
  - spec/lib/vanagon/project_spec.rb
274
274
  - spec/lib/vanagon/utilities/shell_utilities_spec.rb
275
275
  - spec/lib/vanagon/utilities_spec.rb
276
+ - spec/lib/vanagon/environment_spec.rb
277
+ - spec/lib/vanagon/component_spec.rb
278
+ - spec/lib/vanagon/driver_spec.rb
279
+ - spec/lib/makefile_spec.rb