buildpack-support 1.0.0

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.
Files changed (122) hide show
  1. data/LICENSE +202 -0
  2. data/NOTICE +2 -0
  3. data/docs/cache.md +77 -0
  4. data/docs/component.md +1 -0
  5. data/docs/configuration.md +27 -0
  6. data/docs/logging.md +54 -0
  7. data/docs/other.md +1 -0
  8. data/docs/rake.md +1 -0
  9. data/docs/repository.md +116 -0
  10. data/docs/test.md +1 -0
  11. data/lib/buildpack_support.rb +18 -0
  12. data/lib/buildpack_support/base_buildpack.rb +166 -0
  13. data/lib/buildpack_support/buildpack_version.rb +124 -0
  14. data/lib/buildpack_support/cache.rb +24 -0
  15. data/lib/buildpack_support/cache/application_cache.rb +41 -0
  16. data/lib/buildpack_support/cache/cached_file.rb +103 -0
  17. data/lib/buildpack_support/cache/download_cache.rb +280 -0
  18. data/lib/buildpack_support/cache/inferred_network_failure.rb +26 -0
  19. data/lib/buildpack_support/cache/internet_availability.rb +64 -0
  20. data/lib/buildpack_support/component.rb +24 -0
  21. data/lib/buildpack_support/component/application.rb +76 -0
  22. data/lib/buildpack_support/component/base_component.rb +78 -0
  23. data/lib/buildpack_support/component/base_droplet.rb +96 -0
  24. data/lib/buildpack_support/component/downloads.rb +88 -0
  25. data/lib/buildpack_support/component/services.rb +84 -0
  26. data/lib/buildpack_support/component/versioned_dependency_component.rb +71 -0
  27. data/lib/buildpack_support/component/versioned_downloads.rb +57 -0
  28. data/lib/buildpack_support/component/with_timing.rb +40 -0
  29. data/lib/buildpack_support/configuration_utils.rb +58 -0
  30. data/lib/buildpack_support/constantize.rb +46 -0
  31. data/lib/buildpack_support/dash_case.rb +29 -0
  32. data/lib/buildpack_support/directory_finder.rb +45 -0
  33. data/lib/buildpack_support/filtering_pathname.rb +227 -0
  34. data/lib/buildpack_support/format_duration.rb +57 -0
  35. data/lib/buildpack_support/logging.rb +22 -0
  36. data/lib/buildpack_support/logging/delegating_logger.rb +48 -0
  37. data/lib/buildpack_support/logging/logger_factory.rb +148 -0
  38. data/lib/buildpack_support/qualify_path.rb +36 -0
  39. data/lib/buildpack_support/rake.rb +22 -0
  40. data/lib/buildpack_support/rake/buildpack_stage_task.rb +86 -0
  41. data/lib/buildpack_support/rake/cached_artifact_finder.rb +99 -0
  42. data/lib/buildpack_support/rake/check_api_doc_task.rb +70 -0
  43. data/lib/buildpack_support/rake/dependency_cache_task.rb +87 -0
  44. data/lib/buildpack_support/rake/disable_remote_downloads_task.rb +80 -0
  45. data/lib/buildpack_support/rake/package_task.rb +133 -0
  46. data/lib/buildpack_support/rake/package_zip_task.rb +80 -0
  47. data/lib/buildpack_support/rake/repository_configuration_finder.rb +66 -0
  48. data/lib/buildpack_support/rake/write_version_file_task.rb +82 -0
  49. data/lib/buildpack_support/repository.rb +24 -0
  50. data/lib/buildpack_support/repository/configured_item.rb +81 -0
  51. data/lib/buildpack_support/repository/repository_index.rb +98 -0
  52. data/lib/buildpack_support/repository/wildcard_version_resolver.rb +75 -0
  53. data/lib/buildpack_support/shell.rb +41 -0
  54. data/lib/buildpack_support/snake_case.rb +30 -0
  55. data/lib/buildpack_support/space_case.rb +29 -0
  56. data/lib/buildpack_support/test/application_helper.rb +41 -0
  57. data/lib/buildpack_support/test/base_component_helper.rb +59 -0
  58. data/lib/buildpack_support/test/base_droplet_helper.rb +36 -0
  59. data/lib/buildpack_support/test/console_helper.rb +57 -0
  60. data/lib/buildpack_support/test/environment_helper.rb +32 -0
  61. data/lib/buildpack_support/test/internet_availability_helper.rb +29 -0
  62. data/lib/buildpack_support/test/logging_helper.rb +50 -0
  63. data/lib/buildpack_support/test/scratch_helper.rb +32 -0
  64. data/lib/buildpack_support/test/versioned_dependency_component_helper.rb +32 -0
  65. data/lib/buildpack_support/test/with_load_path_helper.rb +27 -0
  66. data/lib/buildpack_support/to_b.rb +38 -0
  67. data/lib/buildpack_support/tokenized_version.rb +157 -0
  68. data/lib/buildpack_support/version.rb +23 -0
  69. data/spec/buildpack_support/base_buildpack_spec.rb +112 -0
  70. data/spec/buildpack_support/buildpack_version_spec.rb +122 -0
  71. data/spec/buildpack_support/cache/application_cache_spec.rb +56 -0
  72. data/spec/buildpack_support/cache/cached_file_spec.rb +94 -0
  73. data/spec/buildpack_support/cache/download_cache_spec.rb +293 -0
  74. data/spec/buildpack_support/cache/internet_availability_spec.rb +57 -0
  75. data/spec/buildpack_support/cache/yield_file_with_content.rb +30 -0
  76. data/spec/buildpack_support/component/application_spec.rb +81 -0
  77. data/spec/buildpack_support/component/base_component_spec.rb +81 -0
  78. data/spec/buildpack_support/component/base_droplet_spec.rb +72 -0
  79. data/spec/buildpack_support/component/downloads_spec.rb +63 -0
  80. data/spec/buildpack_support/component/services_spec.rb +80 -0
  81. data/spec/buildpack_support/component/versioned_dependency_component_spec.rb +58 -0
  82. data/spec/buildpack_support/component/versioned_downloads_spec.rb +58 -0
  83. data/spec/buildpack_support/component/with_timing_spec.rb +30 -0
  84. data/spec/buildpack_support/configuration_utils_spec.rb +39 -0
  85. data/spec/buildpack_support/constantize_spec.rb +34 -0
  86. data/spec/buildpack_support/dash_case_spec.rb +41 -0
  87. data/spec/buildpack_support/directory_finder_spec.rb +41 -0
  88. data/spec/buildpack_support/filtering_pathname_spec.rb +443 -0
  89. data/spec/buildpack_support/format_duration_spec.rb +60 -0
  90. data/spec/buildpack_support/logging/delegating_logger_spec.rb +62 -0
  91. data/spec/buildpack_support/logging/logger_factory_spec.rb +262 -0
  92. data/spec/buildpack_support/qualify_path_spec.rb +42 -0
  93. data/spec/buildpack_support/rake/buildpack_stage_task_spec.rb +88 -0
  94. data/spec/buildpack_support/rake/cached_artifact_finder_spec.rb +73 -0
  95. data/spec/buildpack_support/rake/check_api_doc_task_spec.rb +69 -0
  96. data/spec/buildpack_support/rake/dependency_cache_task_spec.rb +133 -0
  97. data/spec/buildpack_support/rake/disable_remote_downloads_task_spec.rb +91 -0
  98. data/spec/buildpack_support/rake/package_task_spec.rb +335 -0
  99. data/spec/buildpack_support/rake/package_zip_task_spec.rb +91 -0
  100. data/spec/buildpack_support/rake/repository_configuration_finder_spec.rb +61 -0
  101. data/spec/buildpack_support/rake/write_version_file_task_spec.rb +96 -0
  102. data/spec/buildpack_support/repository/configured_item_spec.rb +78 -0
  103. data/spec/buildpack_support/repository/repository_index_spec.rb +118 -0
  104. data/spec/buildpack_support/repository/wildcard_version_resolver_spec.rb +73 -0
  105. data/spec/buildpack_support/shell_spec.rb +32 -0
  106. data/spec/buildpack_support/snake_case_spec.rb +45 -0
  107. data/spec/buildpack_support/space_case_spec.rb +41 -0
  108. data/spec/buildpack_support/to_b_spec.rb +41 -0
  109. data/spec/buildpack_support/tokenized_version_spec.rb +132 -0
  110. data/spec/fixtures/application/test-file +0 -0
  111. data/spec/fixtures/config/found-config.yml +2 -0
  112. data/spec/fixtures/droplet-resources/droplet-resource +0 -0
  113. data/spec/fixtures/stub-download-with-top-level.zip +0 -0
  114. data/spec/fixtures/stub-download.tar.gz +0 -0
  115. data/spec/fixtures/stub-download.zip +0 -0
  116. data/spec/fixtures/test-cache.yml +18 -0
  117. data/spec/fixtures/test-index.yml +2 -0
  118. data/spec/fixtures/test_component.rb +0 -0
  119. data/spec/fixtures/zip-contents/test-directory/test-deep-file +0 -0
  120. data/spec/fixtures/zip-contents/test-file +0 -0
  121. data/spec/spec_helper.rb +30 -0
  122. metadata +416 -0
@@ -0,0 +1,91 @@
1
+ # Encoding: utf-8
2
+ # Copyright 2013-2014 the original author or authors.
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+
16
+ require 'spec_helper'
17
+ require 'buildpack_support/rake/package_zip_task'
18
+ require 'buildpack_support/test/console_helper'
19
+ require 'buildpack_support/test/scratch_helper'
20
+ require 'rake'
21
+
22
+ describe BuildpackSupport::Rake::PackageZipTask do
23
+ include_context 'console_helper'
24
+ include_context 'scratch_helper'
25
+
26
+ let(:package_name) { (scratch_dir + 'package.zip').to_s }
27
+
28
+ let(:staging_dir) { scratch_dir + 'staging' }
29
+
30
+ let(:task) do
31
+ described_class.new do |t|
32
+ t.package_name = package_name
33
+ t.staging_dir = staging_dir
34
+ end
35
+ end
36
+
37
+ before { Rake::Task.clear }
38
+
39
+ it 'should create a task with the specified name' do
40
+ task
41
+
42
+ expect(Rake::Task.task_defined?(package_name)).to be
43
+ end
44
+
45
+ it 'should raise and error if name is not specified' do
46
+ expect { described_class.new }.to raise_error('package_name must be configured')
47
+ end
48
+
49
+ it 'should call block if provided' do
50
+ called = false
51
+
52
+ described_class.new do |t|
53
+ t.package_name = package_name
54
+ t.staging_dir = staging_dir
55
+ called = true
56
+ end
57
+
58
+ expect(called).to be
59
+ end
60
+
61
+ it 'should not print package name if not verbose' do
62
+ task.run_task(package_name, staging_dir, false)
63
+
64
+ expect(stderr.string).not_to match(/Creating #{package_name}/)
65
+ end
66
+
67
+ it 'should create zip file' do
68
+ name = scratch_dir + 'test.zip'
69
+
70
+ task.run_task(name, staging_dir, false)
71
+
72
+ expect(name).to exist
73
+ end
74
+
75
+ it 'should raise and error if staging_dir is not specified' do
76
+ expect { described_class.new { |t| t.package_name = package_name } }
77
+ .to raise_error('staging_dir must be configured')
78
+ end
79
+
80
+ it 'should add contents of staging directory to zip file' do
81
+ name = scratch_dir + 'test.zip'
82
+
83
+ task.run_task(name, 'spec/fixtures/zip-contents', false)
84
+
85
+ Zip::File.open(name) do |zipfile|
86
+ filenames = zipfile.map { |entry| entry.name }
87
+ expect(filenames).to include('test-file', 'test-directory/', 'test-directory/test-deep-file')
88
+ end
89
+ end
90
+
91
+ end
@@ -0,0 +1,61 @@
1
+ # Encoding: utf-8
2
+ # Copyright 2013-2014 the original author or authors.
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+
16
+ require 'spec_helper'
17
+ require 'buildpack_support/configuration_utils'
18
+ require 'buildpack_support/rake/repository_configuration_finder'
19
+
20
+ describe BuildpackSupport::Rake::RepositoryConfigurationFinder do
21
+
22
+ let(:configuration_utils) { double('ConfigurationUtils') }
23
+
24
+ let(:configurations) { described_class.new.find }
25
+
26
+ before do
27
+ expect(BuildpackSupport::ConfigurationUtils).to receive(:new).and_return(configuration_utils)
28
+ expect(configuration_utils).to receive(:load).with('components').and_return('test-key' => 'TestComponent')
29
+ end
30
+
31
+ it 'should ignore non-repository configurations' do
32
+ expect(configuration_utils).to receive(:load).with('test_component').and_return('version' => 'test-version')
33
+
34
+ expect(configurations).to be_empty
35
+ end
36
+
37
+ it 'should return repository configurations' do
38
+ expect(configuration_utils).to receive(:load).with('test_component')
39
+ .and_return('version' => 'test-version',
40
+ 'repository_root' => 'test-repository-root')
41
+
42
+ expect(configurations).not_to be_empty
43
+ end
44
+
45
+ it 'should ignore non-repository sub-configurations' do
46
+ expect(configuration_utils).to receive(:load).with('test_component')
47
+ .and_return('sub-configuration' => { 'version' => 'test-version' })
48
+
49
+ expect(configurations).to be_empty
50
+ end
51
+
52
+ it 'should return repository sub-configurations' do
53
+ expect(configuration_utils).to receive(:load).with('test_component')
54
+ .and_return('sub-configuration' => { 'version' => 'test-version',
55
+ 'repository_root' => 'test-repository-root' })
56
+
57
+ expect(configurations).not_to be_empty
58
+
59
+ end
60
+
61
+ end
@@ -0,0 +1,96 @@
1
+ # Encoding: utf-8
2
+ # Copyright 2013-2014 the original author or authors.
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+
16
+ require 'spec_helper'
17
+ require 'buildpack_support/rake/write_version_file_task'
18
+ require 'buildpack_support/test/console_helper'
19
+ require 'buildpack_support/test/scratch_helper'
20
+ require 'rake'
21
+
22
+ describe BuildpackSupport::Rake::WriteVersionFileTask do
23
+ include_context 'console_helper'
24
+ include_context 'scratch_helper'
25
+
26
+ let(:package_name) { (scratch_dir + 'package.zip').to_s }
27
+
28
+ let(:staging_dir) { scratch_dir + 'staging' }
29
+
30
+ let(:target) { staging_dir + 'config/version.yml' }
31
+
32
+ let(:buildpack_version) { double('BuildpackVersion') }
33
+
34
+ let(:task) do
35
+ described_class.new do |t|
36
+ t.buildpack_version = buildpack_version
37
+ t.package_name = package_name
38
+ t.staging_dir = staging_dir
39
+ end
40
+ end
41
+
42
+ before do
43
+ Rake::Task.clear
44
+ allow(buildpack_version).to receive(:to_hash).and_return('foo')
45
+ end
46
+
47
+ it 'should create a task with the specified name' do
48
+ task
49
+ expect(Rake::Task.task_defined?(target.to_s)).to be
50
+ end
51
+
52
+ it 'should add a prerequisite to the package' do
53
+ task
54
+ expect(Rake::Task[package_name].prerequisites.first).to eq(target.to_s)
55
+ end
56
+
57
+ it 'should raise and error if buildpack_version is not specified' do
58
+ expect { described_class.new }.to raise_error('buildpack_version must be configured')
59
+ end
60
+
61
+ it 'should raise and error if package_name is not specified' do
62
+ expect do
63
+ described_class.new do |t|
64
+ t.buildpack_version = buildpack_version
65
+ end
66
+ end.to raise_error('package_name must be configured')
67
+ end
68
+
69
+ it 'should raise and error if staging_dir is not specified' do
70
+ expect do
71
+ described_class.new do |t|
72
+ t.buildpack_version = buildpack_version
73
+ t.package_name = package_name
74
+ end
75
+ end.to raise_error('staging_dir must be configured')
76
+ end
77
+
78
+ it 'should create the version file' do
79
+ task.run_task(target, buildpack_version, false)
80
+
81
+ expect(target).to exist
82
+ end
83
+
84
+ it 'should not print the buildpack version if not verbose' do
85
+ task.run_task(target, buildpack_version, false)
86
+
87
+ expect(stderr.string).not_to match("Wrote buildpack version to #{target}")
88
+ end
89
+
90
+ it 'should print the buildpack version if verbose' do
91
+ task.run_task(target, buildpack_version, true)
92
+
93
+ expect(stderr.string).to match("Wrote buildpack version to #{target}")
94
+ end
95
+
96
+ end
@@ -0,0 +1,78 @@
1
+ # Encoding: utf-8
2
+ # Copyright 2013-2014 the original author or authors.
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+
16
+ require 'spec_helper'
17
+ require 'buildpack_support/repository/configured_item'
18
+ require 'buildpack_support/repository/repository_index'
19
+ require 'buildpack_support/tokenized_version'
20
+
21
+ describe BuildpackSupport::Repository::ConfiguredItem do
22
+
23
+ let(:configured_item) { described_class.new }
24
+
25
+ let(:repository_index) { double('RepositoryIndex', find_item: [resolved_version, resolved_uri]) }
26
+
27
+ let(:resolved_uri) { 'resolved-uri' }
28
+
29
+ let(:resolved_version) { 'resolved-version' }
30
+
31
+ before do
32
+ allow(BuildpackSupport::Repository::RepositoryIndex).to receive(:new).and_return(repository_index)
33
+ end
34
+
35
+ it 'raises an error if no repository root is specified' do
36
+ expect { configured_item.find_item('Test', {}) }.to raise_error
37
+ end
38
+
39
+ it 'resolves a system.properties version if specified' do
40
+ details = configured_item.find_item('Test',
41
+ 'repository_root' => 'test-repository-root',
42
+ 'other.key' => 'other-value',
43
+ 'version' => '1.7.0'
44
+ )
45
+
46
+ expect(details[0]).to eq(resolved_version)
47
+ expect(details[1]).to eq(resolved_uri)
48
+ end
49
+
50
+ it 'resolves a configuration version if specified' do
51
+ details = configured_item.find_item('Test',
52
+ 'repository_root' => 'test-repository-root',
53
+ 'version' => '1.7.0'
54
+ )
55
+
56
+ expect(details[0]).to eq(resolved_version)
57
+ expect(details[1]).to eq(resolved_uri)
58
+ end
59
+
60
+ it 'drives the version validator block if supplied' do
61
+ configured_item.find_item('Test',
62
+ 'repository_root' => 'test-repository-root',
63
+ 'version' => '1.7.0'
64
+ ) do |version|
65
+ expect(version).to eq(BuildpackSupport::TokenizedVersion.new('1.7.0'))
66
+ end
67
+ end
68
+
69
+ it 'resolves nil if no version is specified' do
70
+ details = configured_item.find_item('Test',
71
+ 'repository_root' => 'test-repository-root'
72
+ )
73
+
74
+ expect(details[0]).to eq(resolved_version)
75
+ expect(details[1]).to eq(resolved_uri)
76
+ end
77
+
78
+ end
@@ -0,0 +1,118 @@
1
+ # Encoding: utf-8
2
+ # Copyright 2013-2014 the original author or authors.
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific
14
+
15
+ require 'spec_helper'
16
+ require 'buildpack_support/cache/download_cache'
17
+ require 'buildpack_support/configuration_utils'
18
+ require 'buildpack_support/repository/repository_index'
19
+ require 'buildpack_support/test/logging_helper'
20
+ require 'buildpack_support/test/scratch_helper'
21
+ require 'buildpack_support/tokenized_version'
22
+ require 'fileutils'
23
+
24
+ describe BuildpackSupport::Repository::RepositoryIndex do
25
+ include_context 'logging_helper'
26
+ include_context 'scratch_helper'
27
+
28
+ let(:download_cache) { double('DownloadCache') }
29
+
30
+ let(:version_resolver) { double('VersionResolver') }
31
+
32
+ before do
33
+ allow(BuildpackSupport::Cache::DownloadCache).to receive(:new).and_return(download_cache)
34
+ allow_any_instance_of(BuildpackSupport::ConfigurationUtils).to receive(:load).with('repository')
35
+ .and_return('default_repository_root' => 'http://default-repository-root')
36
+ end
37
+
38
+ it 'should load index' do
39
+ allow(download_cache).to receive(:get).with(%r{/test-uri/index\.yml})
40
+ .and_yield(Pathname.new('spec/fixtures/test-index.yml').open)
41
+ allow(version_resolver).to receive(:resolve).with('test-version', %w(resolved-version))
42
+ .and_return('resolved-version')
43
+
44
+ repository_index = described_class.new('{platform}/{architecture}/test-uri', version_resolver)
45
+
46
+ expect(repository_index.find_item('test-version')).to eq(%w(resolved-version resolved-uri))
47
+ end
48
+
49
+ it 'should cope with trailing slash in repository URI' do
50
+ allow(download_cache).to receive(:get).with(%r{/test-uri/index\.yml})
51
+ .and_yield(Pathname.new('spec/fixtures/test-index.yml').open)
52
+ allow(version_resolver).to receive(:resolve).with('test-version', %w(resolved-version))
53
+ .and_return('resolved-version')
54
+
55
+ repository_index = described_class.new('{platform}/{architecture}/test-uri/', version_resolver)
56
+
57
+ expect(repository_index.find_item('test-version')).to eq(%w(resolved-version resolved-uri))
58
+ end
59
+
60
+ it 'should substitute the default repository root' do
61
+ expect(download_cache).to receive(:get).with('http://default-repository-root/test-uri/index.yml')
62
+ .and_yield(Pathname.new('spec/fixtures/test-index.yml').open)
63
+
64
+ described_class.new('{default.repository.root}/test-uri')
65
+ end
66
+
67
+ it 'should handle Centos correctly' do
68
+ allow(Pathname).to receive(:new).and_call_original
69
+ redhat_release = double('redhat-release')
70
+ allow(Pathname).to receive(:new).with('/etc/redhat-release').and_return(redhat_release)
71
+
72
+ allow_any_instance_of(described_class).to receive(:`).with('uname -s').and_return('Linux')
73
+ allow_any_instance_of(described_class).to receive(:`).with('uname -m').and_return('x86_64')
74
+ allow_any_instance_of(described_class).to receive(:`).with('which lsb_release 2> /dev/null').and_return('')
75
+ allow(redhat_release).to receive(:exist?).and_return(true)
76
+ allow(redhat_release).to receive(:read).and_return('CentOS release 6.4 (Final)')
77
+ allow(download_cache).to receive(:get).with('centos6/x86_64/test-uri/index.yml')
78
+ .and_yield(Pathname.new('spec/fixtures/test-index.yml').open)
79
+
80
+ described_class.new('{platform}/{architecture}/test-uri')
81
+
82
+ expect(download_cache).to have_received(:get).with %r{centos6/x86_64/test-uri/index\.yml}
83
+ end
84
+
85
+ it 'should handle Mac OS X correctly' do
86
+ allow_any_instance_of(described_class).to receive(:`).with('uname -s').and_return('Darwin')
87
+ allow_any_instance_of(described_class).to receive(:`).with('uname -m').and_return('x86_64')
88
+ allow(download_cache).to receive(:get).with('mountainlion/x86_64/test-uri/index.yml')
89
+ .and_yield(Pathname.new('spec/fixtures/test-index.yml').open)
90
+
91
+ described_class.new('{platform}/{architecture}/test-uri')
92
+
93
+ expect(download_cache).to have_received(:get).with %r{mountainlion/x86_64/test-uri/index\.yml}
94
+ end
95
+
96
+ it 'should handle Ubuntu correctly' do
97
+ allow_any_instance_of(described_class).to receive(:`).with('uname -s').and_return('Linux')
98
+ allow_any_instance_of(described_class).to receive(:`).with('uname -m').and_return('x86_64')
99
+ allow_any_instance_of(described_class).to receive(:`).with('which lsb_release 2> /dev/null').and_return('/usr/bin/lsb_release')
100
+ allow_any_instance_of(described_class).to receive(:`).with('lsb_release -cs').and_return('precise')
101
+ allow(download_cache).to receive(:get).with('precise/x86_64/test-uri/index.yml')
102
+ .and_yield(Pathname.new('spec/fixtures/test-index.yml').open)
103
+
104
+ described_class.new('{platform}/{architecture}/test-uri')
105
+
106
+ expect(download_cache).to have_received(:get).with %r{precise/x86_64/test-uri/index\.yml}
107
+ end
108
+
109
+ it 'should handle unknown OS correctly' do
110
+ allow_any_instance_of(File).to receive(:exists?).with('/etc/redhat-release').and_return(false)
111
+ allow_any_instance_of(described_class).to receive(:`).with('uname -s').and_return('Linux')
112
+ allow_any_instance_of(described_class).to receive(:`).with('which lsb_release 2> /dev/null').and_return('')
113
+
114
+ expect { described_class.new('{platform}/{architecture}/test-uri') }
115
+ .to raise_error('Unable to determine platform')
116
+ end
117
+
118
+ end