vanagon 0.8.2 → 0.9.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (36) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +1 -0
  3. data/bin/build +1 -1
  4. data/lib/vanagon/component/dsl.rb +14 -24
  5. data/lib/vanagon/component/source/git.rb +1 -6
  6. data/lib/vanagon/component/source/http.rb +7 -0
  7. data/lib/vanagon/component/source/local.rb +8 -2
  8. data/lib/vanagon/driver.rb +31 -11
  9. data/lib/vanagon/engine/always_be_scheduling.rb +92 -0
  10. data/lib/vanagon/engine/base.rb +1 -2
  11. data/lib/vanagon/engine/hardware.rb +1 -1
  12. data/lib/vanagon/engine/pooler.rb +42 -10
  13. data/lib/vanagon/optparse.rb +1 -0
  14. data/lib/vanagon/platform.rb +10 -7
  15. data/lib/vanagon/platform/dsl.rb +13 -2
  16. data/lib/vanagon/project.rb +41 -3
  17. data/lib/vanagon/project/dsl.rb +9 -4
  18. data/lib/vanagon/utilities.rb +10 -13
  19. data/resources/Makefile.erb +1 -1
  20. data/resources/rpm/project.spec.erb +9 -0
  21. data/spec/fixtures/files/fake_dir/fake_file.txt +0 -0
  22. data/spec/fixtures/files/fake_nested_dir/fake_dir/fake_file.txt +0 -0
  23. data/spec/lib/vanagon/component/dsl_spec.rb +51 -2
  24. data/spec/lib/vanagon/component/source/git_spec.rb +8 -0
  25. data/spec/lib/vanagon/component/source/http_spec.rb +15 -15
  26. data/spec/lib/vanagon/component/source/local_spec.rb +17 -1
  27. data/spec/lib/vanagon/component/source_spec.rb +1 -1
  28. data/spec/lib/vanagon/driver_spec.rb +33 -1
  29. data/spec/lib/vanagon/engine/always_be_scheduling_spec.rb +84 -0
  30. data/spec/lib/vanagon/engine/pooler_spec.rb +80 -16
  31. data/spec/lib/vanagon/platform/dsl_spec.rb +14 -0
  32. data/spec/lib/vanagon/platform/windows_spec.rb +2 -2
  33. data/spec/lib/vanagon/project_spec.rb +79 -5
  34. data/spec/lib/vanagon/utilities_spec.rb +5 -0
  35. data/spec/spec_helper.rb +22 -2
  36. metadata +29 -24
@@ -18,29 +18,93 @@ describe 'Vanagon::Engine::Pooler' do
18
18
  plat._platform
19
19
  }
20
20
 
21
+ before :each do
22
+ # suppress `#warn` output during tests
23
+ allow_any_instance_of(Vanagon::Platform::DSL).to receive(:warn)
24
+
25
+ # stubbing ENV doesn't actually intercept ENV because ENV
26
+ # is special and you aren't. So we have to mangle the value
27
+ # of ENV around each of these tests if we want to prevent
28
+ # actual user credentials from being loaded, or attempt to
29
+ # validate the way that credentials are read.
30
+ ENV['REAL_HOME'] = ENV.delete 'HOME'
31
+ ENV['REAL_VMPOOLER_TOKEN'] = ENV.delete 'VMPOOLER_TOKEN'
32
+ ENV['HOME'] = Dir.mktmpdir
33
+
34
+ # This should help maintain the ENV['HOME'] masquerade
35
+ allow(Dir).to receive(:home).and_return(ENV['HOME'])
36
+ end
37
+
38
+ after :each do
39
+ # Altering ENV directly is a legitimate code-smell.
40
+ # We should at least clean up after ourselves.
41
+ ENV['HOME'] = ENV.delete 'REAL_HOME'
42
+ ENV['VMPOOLER_TOKEN'] = ENV.delete 'REAL_VMPOOLER_TOKEN'
43
+ end
44
+
45
+ # We don't want to run the risk of reading legitimate user
46
+ # data from a user who is unfortunate enough to be running spec
47
+ # tests on their local machine. This means we have to intercept
48
+ # and stub out a very specific environment, where:
49
+ # 1) an environment variable exists
50
+ # 2) the env. var is unset, and only a ~/.vmpooler-token file exists
51
+ # 3) the env. var is unset, and only a ~/.vmfloaty.yml file exists
21
52
  describe "#load_token" do
22
- after(:each) { ENV['VMPOOLER_TOKEN'] = nil }
53
+ let(:environment_value) { 'cafebeef' }
54
+ let(:token_value) { 'decade' }
55
+ let(:pooler_token_file) { File.expand_path('~/.vanagon-token') }
56
+ let(:floaty_config) { File.expand_path('~/.vmfloaty.yml') }
57
+
58
+ it 'prefers the VMPOOLER_TOKEN environment variable to a config file' do
59
+ allow(ENV).to receive(:[])
60
+ .with('VMPOOLER_TOKEN')
61
+ .and_return(environment_value)
62
+
63
+ expect(Vanagon::Engine::Pooler.new(platform).token)
64
+ .to_not eq(token_value)
23
65
 
24
- let(:token_file) { double(File) }
25
- let(:token_filename) { 'abcd' }
66
+ expect(Vanagon::Engine::Pooler.new(platform).token)
67
+ .to eq(environment_value)
68
+ end
69
+
70
+ it %(reads a token from '~/.vanagon-token' if the environment variable is not set) do
71
+ allow(File).to receive(:exist?)
72
+ .with(pooler_token_file)
73
+ .and_return(true)
26
74
 
27
- it 'prefers an env var to a file' do
28
- ENV['VMPOOLER_TOKEN'] = 'abcd'
29
- expect(File).to_not receive(:expand_path).with('~/.vanagon-token')
30
- expect(Vanagon::Engine::Pooler.new(platform).token).to eq('abcd')
75
+ allow(File).to receive(:read)
76
+ .with(pooler_token_file)
77
+ .and_return(token_value)
78
+
79
+ expect(Vanagon::Engine::Pooler.new(platform).token)
80
+ .to eq(token_value)
31
81
  end
32
82
 
33
- it 'falls back to a file if the env var is not set' do
34
- expect(File).to receive(:expand_path).with('~/.vanagon-token').and_return(token_filename)
35
- expect(File).to receive(:exist?).with(token_filename).and_return(true)
36
- expect(File).to receive(:open).with(token_filename).and_return(token_file)
37
- expect(token_file).to receive(:read).and_return('abcd')
38
- expect(Vanagon::Engine::Pooler.new(platform).token).to eq('abcd')
83
+ it %(reads a token from '~/.vmfloaty.yml' if '~/.vanagon-token' doesn't exist) do
84
+ allow(File).to receive(:exist?)
85
+ .with(pooler_token_file)
86
+ .and_return(false)
87
+
88
+ allow(File).to receive(:exist?)
89
+ .with(floaty_config)
90
+ .and_return(true)
91
+
92
+ allow(YAML).to receive(:load_file)
93
+ .with(floaty_config)
94
+ .and_return({'token' => token_value})
95
+
96
+ expect(Vanagon::Engine::Pooler.new(platform).token).to eq(token_value)
39
97
  end
40
98
 
41
- it 'returns nil if there is no env var or file' do
42
- expect(File).to receive(:expand_path).with('~/.vanagon-token').and_return(token_filename)
43
- expect(File).to receive(:exist?).with(token_filename).and_return(false)
99
+ it %(returns 'nil' if no vmpooler token configuration exists) do
100
+ allow(File).to receive(:exist?)
101
+ .with(pooler_token_file)
102
+ .and_return(false)
103
+
104
+ allow(File).to receive(:exist?)
105
+ .with(floaty_config)
106
+ .and_return(false)
107
+
44
108
  expect(Vanagon::Engine::Pooler.new(platform).token).to be_nil
45
109
  end
46
110
  end
@@ -20,6 +20,11 @@ describe 'Vanagon::Platform::DSL' do
20
20
 
21
21
  let(:hex_value) { "906264d248061b0edb1a576cc9c8f6c7" }
22
22
 
23
+ before :each do
24
+ # suppress `#warn` output during tests
25
+ allow_any_instance_of(Vanagon::Platform::DSL).to receive(:warn)
26
+ end
27
+
23
28
  # These apt_repo, yum_repo, and zypper_repo methods are all deprecated.
24
29
  describe '#apt_repo' do
25
30
  it "grabs the file and adds .list to it" do
@@ -106,6 +111,15 @@ describe 'Vanagon::Platform::DSL' do
106
111
  end
107
112
  end
108
113
 
114
+ describe '#abs_resource_name' do
115
+ it 'sets the instance variable on platform' do
116
+ plat = Vanagon::Platform::DSL.new('solaris-test-fixture')
117
+ plat.instance_eval(solaris_10_platform_block)
118
+ plat.abs_resource_name 'solaris-10-x86_64'
119
+ expect(plat._platform.abs_resource_name).to eq('solaris-10-x86_64')
120
+ end
121
+ end
122
+
109
123
  describe '#vmpooler_template' do
110
124
  it 'sets the instance variable on platform' do
111
125
  plat = Vanagon::Platform::DSL.new('solaris-test-fixture')
@@ -135,7 +135,7 @@ HERE
135
135
 
136
136
  it "Copies Hierarchy of files from Product Specific Directory to output directory with ERB translation as necessary" do
137
137
  # setup source directories and run artifact generation
138
- FileUtils.cp_r("#{WIXTESTFILES}/", "#{PROJ_ROOT}/resources/windows/", :verbose => true)
138
+ FileUtils.cp_r("#{WIXTESTFILES}/", "#{PROJ_ROOT}/resources/windows/")
139
139
  cur_plat._platform.generate_msi_packaging_artifacts(WORKDIR, plat[:projname], binding)
140
140
  # check the result
141
141
  expect(File).to exist("#{WORKDIR}/wix/file-1.wxs")
@@ -154,7 +154,7 @@ HERE
154
154
 
155
155
  it "Copies Hierarchy of files from vanagon directory to output directory with ERB translation as necessary" do
156
156
  # setup source directories and run artifact generation
157
- FileUtils.cp_r("#{WIXTESTFILES}/", "#{VANAGON_ROOT}/resources/windows/", :verbose => true)
157
+ FileUtils.cp_r("#{WIXTESTFILES}/", "#{VANAGON_ROOT}/resources/windows/")
158
158
  cur_plat._platform.generate_msi_packaging_artifacts(WORKDIR, plat[:projname], binding)
159
159
  # check the result
160
160
  expect(File).to exist("#{WORKDIR}/wix/file-1.wxs")
@@ -11,13 +11,15 @@ describe 'Vanagon::Project' do
11
11
  end"
12
12
  }
13
13
 
14
- before do
15
- allow_any_instance_of(Vanagon::Project::DSL).to receive(:puts)
16
- allow(Vanagon::Driver).to receive(:configdir).and_return(configdir)
17
- allow(Vanagon::Component).to receive(:load_component).with('some-component', any_args).and_return(component)
18
- end
19
14
 
20
15
  describe '#get_root_directories' do
16
+
17
+ before do
18
+ allow_any_instance_of(Vanagon::Project::DSL).to receive(:puts)
19
+ allow(Vanagon::Driver).to receive(:configdir).and_return(configdir)
20
+ allow(Vanagon::Component).to receive(:load_component).with('some-component', any_args).and_return(component)
21
+ end
22
+
21
23
  let(:test_sets) do
22
24
  [
23
25
  {
@@ -41,4 +43,76 @@ describe 'Vanagon::Project' do
41
43
  end
42
44
  end
43
45
  end
46
+
47
+ describe "#filter_component" do
48
+
49
+ # All of the following tests should be run with one project level
50
+ # component that isn't included in the build_deps of another component
51
+ before(:each) do
52
+ @proj = Vanagon::Project.new('test-fixture-with-comps', {})
53
+ @not_included_comp = Vanagon::Component.new('test-fixture-not-included', {}, {})
54
+ @proj.components << @not_included_comp
55
+ end
56
+
57
+ it "returns nil when given a component that doesn't exist" do
58
+ expect(@proj.filter_component("fake")).to eq([])
59
+ end
60
+
61
+ it "returns only the component with no build deps" do
62
+ comp = Vanagon::Component.new('test-fixture1', {}, {})
63
+ @proj.components << comp
64
+ expect(@proj.filter_component(comp.name)).to eq([comp])
65
+ end
66
+
67
+ it "returns component and one build dep" do
68
+ comp1 = Vanagon::Component.new('test-fixture1', {}, {})
69
+ comp2 = Vanagon::Component.new('test-fixture2', {}, {})
70
+ comp1.build_requires << comp2.name
71
+ @proj.components << comp1
72
+ @proj.components << comp2
73
+ expect(@proj.filter_component(comp1.name)).to eq([comp1, comp2])
74
+ end
75
+
76
+ it "returns only the component with build deps that are not components of the @project" do
77
+ comp = Vanagon::Component.new('test-fixture1', {}, {})
78
+ comp.build_requires << "fake-name"
79
+ @proj.components << comp
80
+ expect(@proj.filter_component(comp.name)).to eq([comp])
81
+ end
82
+
83
+ it "returns the component and build deps with both @project components and external build deps" do
84
+ comp1 = Vanagon::Component.new('test-fixture1', {}, {})
85
+ comp2 = Vanagon::Component.new('test-fixture2', {}, {})
86
+ comp1.build_requires << comp2.name
87
+ comp1.build_requires << "fake-name"
88
+ @proj.components << comp1
89
+ @proj.components << comp2
90
+ expect(@proj.filter_component(comp1.name)).to eq([comp1, comp2])
91
+ end
92
+
93
+ it "returns the component and multiple build deps" do
94
+ comp1 = Vanagon::Component.new('test-fixture1', {}, {})
95
+ comp2 = Vanagon::Component.new('test-fixture2', {}, {})
96
+ comp3 = Vanagon::Component.new('test-fixture3', {}, {})
97
+ comp1.build_requires << comp2.name
98
+ comp1.build_requires << comp3.name
99
+ @proj.components << comp1
100
+ @proj.components << comp2
101
+ @proj.components << comp3
102
+ expect(@proj.filter_component(comp1.name)).to eq([comp1, comp2, comp3])
103
+ end
104
+
105
+ it "returns the component and multiple build deps with external build deps" do
106
+ comp1 = Vanagon::Component.new('test-fixture1', {}, {})
107
+ comp2 = Vanagon::Component.new('test-fixture2', {}, {})
108
+ comp3 = Vanagon::Component.new('test-fixture3', {}, {})
109
+ comp1.build_requires << comp2.name
110
+ comp1.build_requires << comp3.name
111
+ comp1.build_requires << "another-fake-name"
112
+ @proj.components << comp1
113
+ @proj.components << comp2
114
+ @proj.components << comp3
115
+ expect(@proj.filter_component(comp1.name)).to eq([comp1, comp2, comp3])
116
+ end
117
+ end
44
118
  end
@@ -2,6 +2,11 @@ require 'vanagon/utilities'
2
2
  require 'tmpdir'
3
3
 
4
4
  describe "Vanagon::Utilities" do
5
+ before :each do
6
+ # suppress `#warn` output during tests
7
+ allow(Vanagon::Utilities).to receive(:warn)
8
+ end
9
+
5
10
  describe "#find_program_on_path" do
6
11
  let(:command) { "thingie" }
7
12
 
data/spec/spec_helper.rb CHANGED
@@ -1,6 +1,26 @@
1
+ require 'tmpdir'
2
+ require 'vanagon'
3
+
4
+ if ENV["COVERAGE"]
5
+ require 'simplecov'
6
+ SimpleCov.start do
7
+ add_filter '.bundle'
8
+ add_filter 'spec'
9
+ add_filter 'vendor'
10
+ end
11
+ end
12
+
1
13
  RSpec.configure do |c|
2
14
  c.before do
3
- allow($stdout).to receive(:puts)
4
- allow($stderr).to receive(:puts)
15
+ allow_any_instance_of(Vanagon::Component::Source::Git).to receive(:puts)
16
+ allow_any_instance_of(Vanagon::Component::Source::Http).to receive(:puts)
17
+ allow_any_instance_of(Vanagon::Component::Source::Local).to receive(:puts)
18
+
19
+ class Vanagon
20
+ module Utilities
21
+ def puts(*args)
22
+ end
23
+ end
24
+ end
5
25
  end
6
26
  end
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.8.2
4
+ version: 0.9.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Puppet Labs
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-09-30 00:00:00.000000000 Z
11
+ date: 2017-01-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: git
@@ -87,6 +87,7 @@ files:
87
87
  - lib/vanagon/component/source/http.rb
88
88
  - lib/vanagon/component/source/local.rb
89
89
  - lib/vanagon/driver.rb
90
+ - lib/vanagon/engine/always_be_scheduling.rb
90
91
  - lib/vanagon/engine/base.rb
91
92
  - lib/vanagon/engine/docker.rb
92
93
  - lib/vanagon/engine/ec2.rb
@@ -149,6 +150,7 @@ files:
149
150
  - spec/fixtures/component/mcollective.service
150
151
  - spec/fixtures/component/test-fixture.json
151
152
  - spec/fixtures/files/fake_dir.tar.gz
153
+ - spec/fixtures/files/fake_dir/fake_file.txt
152
154
  - spec/fixtures/files/fake_file.txt
153
155
  - spec/fixtures/files/fake_file_ext.7z
154
156
  - spec/fixtures/files/fake_file_ext.bz
@@ -167,6 +169,7 @@ files:
167
169
  - spec/fixtures/files/fake_file_ext.xz
168
170
  - spec/fixtures/files/fake_file_ext.z
169
171
  - spec/fixtures/files/fake_file_ext.zip
172
+ - spec/fixtures/files/fake_nested_dir/fake_dir/fake_file.txt
170
173
  - spec/fixtures/wix/resources/windows/wix/file-1.wxs
171
174
  - spec/fixtures/wix/resources/windows/wix/file-2.wxs
172
175
  - spec/fixtures/wix/resources/windows/wix/file-3.wxs.erb
@@ -187,6 +190,7 @@ files:
187
190
  - spec/lib/vanagon/component/source_spec.rb
188
191
  - spec/lib/vanagon/component_spec.rb
189
192
  - spec/lib/vanagon/driver_spec.rb
193
+ - spec/lib/vanagon/engine/always_be_scheduling_spec.rb
190
194
  - spec/lib/vanagon/engine/base_spec.rb
191
195
  - spec/lib/vanagon/engine/docker_spec.rb
192
196
  - spec/lib/vanagon/engine/ec2_spec.rb
@@ -229,40 +233,41 @@ required_rubygems_version: !ruby/object:Gem::Requirement
229
233
  version: '0'
230
234
  requirements: []
231
235
  rubyforge_project:
232
- rubygems_version: 2.5.1
236
+ rubygems_version: 2.5.2
233
237
  signing_key:
234
238
  specification_version: 3
235
239
  summary: All of your packages will fit into this van with this one simple trick.
236
240
  test_files:
237
241
  - spec/lib/makefile_spec.rb
242
+ - spec/lib/vanagon/common/pathname_spec.rb
243
+ - spec/lib/vanagon/common/user_spec.rb
244
+ - spec/lib/vanagon/component/dsl_spec.rb
245
+ - spec/lib/vanagon/component/rules_spec.rb
246
+ - spec/lib/vanagon/component/source/git_spec.rb
238
247
  - spec/lib/vanagon/component/source/http_spec.rb
239
248
  - spec/lib/vanagon/component/source/local_spec.rb
240
- - spec/lib/vanagon/component/source/git_spec.rb
241
- - spec/lib/vanagon/component/rules_spec.rb
242
- - spec/lib/vanagon/component/dsl_spec.rb
243
249
  - spec/lib/vanagon/component/source_spec.rb
244
- - spec/lib/vanagon/common/user_spec.rb
245
- - spec/lib/vanagon/common/pathname_spec.rb
246
- - spec/lib/vanagon/extensions/set/json_spec.rb
247
- - spec/lib/vanagon/extensions/ostruct/json_spec.rb
248
- - spec/lib/vanagon/extensions/string_spec.rb
249
- - spec/lib/vanagon/utilities/shell_utilities_spec.rb
250
- - spec/lib/vanagon/platform/deb_spec.rb
251
- - spec/lib/vanagon/platform/solaris_11_spec.rb
252
- - spec/lib/vanagon/platform/rpm_spec.rb
253
- - spec/lib/vanagon/platform/dsl_spec.rb
254
- - spec/lib/vanagon/platform/windows_spec.rb
255
- - spec/lib/vanagon/platform/rpm/aix_spec.rb
256
- - spec/lib/vanagon/optparse_spec.rb
257
- - spec/lib/vanagon/project_spec.rb
258
250
  - spec/lib/vanagon/component_spec.rb
251
+ - spec/lib/vanagon/driver_spec.rb
252
+ - spec/lib/vanagon/engine/always_be_scheduling_spec.rb
259
253
  - spec/lib/vanagon/engine/base_spec.rb
260
- - spec/lib/vanagon/engine/pooler_spec.rb
254
+ - spec/lib/vanagon/engine/docker_spec.rb
261
255
  - spec/lib/vanagon/engine/ec2_spec.rb
262
256
  - spec/lib/vanagon/engine/hardware_spec.rb
263
257
  - spec/lib/vanagon/engine/local_spec.rb
264
- - spec/lib/vanagon/engine/docker_spec.rb
265
- - spec/lib/vanagon/driver_spec.rb
258
+ - spec/lib/vanagon/engine/pooler_spec.rb
259
+ - spec/lib/vanagon/extensions/ostruct/json_spec.rb
260
+ - spec/lib/vanagon/extensions/set/json_spec.rb
261
+ - spec/lib/vanagon/extensions/string_spec.rb
262
+ - spec/lib/vanagon/optparse_spec.rb
263
+ - spec/lib/vanagon/platform/deb_spec.rb
264
+ - spec/lib/vanagon/platform/dsl_spec.rb
265
+ - spec/lib/vanagon/platform/rpm/aix_spec.rb
266
+ - spec/lib/vanagon/platform/rpm_spec.rb
267
+ - spec/lib/vanagon/platform/solaris_11_spec.rb
268
+ - spec/lib/vanagon/platform/windows_spec.rb
269
+ - spec/lib/vanagon/platform_spec.rb
266
270
  - spec/lib/vanagon/project/dsl_spec.rb
271
+ - spec/lib/vanagon/project_spec.rb
272
+ - spec/lib/vanagon/utilities/shell_utilities_spec.rb
267
273
  - spec/lib/vanagon/utilities_spec.rb
268
- - spec/lib/vanagon/platform_spec.rb