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,73 @@
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/cache/download_cache'
18
+ require 'buildpack_support/configuration_utils'
19
+ require 'buildpack_support/rake/cached_artifact_finder'
20
+ require 'buildpack_support/repository/wildcard_version_resolver'
21
+ require 'buildpack_support/test/logging_helper'
22
+ require 'buildpack_support/tokenized_version'
23
+
24
+ describe BuildpackSupport::Rake::CachedArtifactFinder do
25
+ include_context 'logging_helper'
26
+
27
+ let(:cache) { double('DownloadCache') }
28
+
29
+ let(:configuration_utils) { double('ConfigurationUtils') }
30
+
31
+ let(:finder) { described_class.new }
32
+
33
+ let(:version_resolver) { double('VersionResolver') }
34
+
35
+ before do
36
+ expect(BuildpackSupport::Cache::DownloadCache).to receive(:new).and_return(cache)
37
+ expect(BuildpackSupport::ConfigurationUtils).to receive(:new).and_return(configuration_utils)
38
+ expect(BuildpackSupport::Repository::WildcardVersionResolver).to receive(:new).and_return(version_resolver)
39
+ expect(configuration_utils).to receive(:load).with('repository')
40
+ .and_return('default_repository_root' => 'test-default-repository-root')
41
+ end
42
+
43
+ it 'should augment repository with default repository root' do
44
+ expect(cache).to receive(:get).with('test-default-repository-root/index.yml')
45
+
46
+ finder.find [{ 'repository_root' => '{default.repository.root}' }]
47
+ end
48
+
49
+ it 'should augment repository with platforms' do
50
+ expect(cache).to receive(:get).with('centos6/index.yml')
51
+ expect(cache).to receive(:get).with('lucid/index.yml')
52
+ expect(cache).to receive(:get).with('mountainlion/index.yml')
53
+ expect(cache).to receive(:get).with('precise/index.yml')
54
+ expect(cache).to receive(:get).with('trusty/index.yml')
55
+
56
+ finder.find [{ 'repository_root' => '{platform}' }]
57
+ end
58
+
59
+ it 'should augment repository with architectures' do
60
+ expect(cache).to receive(:get).with('x86_64/index.yml')
61
+
62
+ finder.find [{ 'repository_root' => '{architecture}' }]
63
+ end
64
+
65
+ it 'should resolve a version from the index' do
66
+ expect(cache).to receive(:get).with('test/index.yml').and_yield(File.open('spec/fixtures/test-index.yml'))
67
+ expect(version_resolver).to receive(:resolve).and_return('resolved-version')
68
+
69
+ cached_artifacts = finder.find [{ 'repository_root' => 'test', 'version' => '1.2.3' }]
70
+ expect(cached_artifacts).to include('test/index.yml', 'resolved-uri')
71
+ end
72
+
73
+ end
@@ -0,0 +1,69 @@
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/check_api_doc_task'
18
+ require 'buildpack_support/test/console_helper'
19
+ require 'rake'
20
+
21
+ describe BuildpackSupport::Rake::CheckAPIDocTask do
22
+ include_context 'console_helper'
23
+
24
+ let(:task) { described_class.new }
25
+
26
+ before { Rake::Task.clear }
27
+
28
+ it 'should create a task with the default name' do
29
+ task
30
+
31
+ expect(Rake::Task.task_defined?(:check_api_doc)).to be
32
+ expect(Rake::Task.task_defined?(:test_name)).not_to be
33
+ end
34
+
35
+ it 'should create a task with an alternate name' do
36
+ described_class.new(:test_name)
37
+
38
+ expect(Rake::Task.task_defined?(:check_api_doc)).not_to be
39
+ expect(Rake::Task.task_defined?(:test_name)).to be
40
+ end
41
+
42
+ it 'should call block if provided' do
43
+ expect_any_instance_of(described_class).to receive(:`).with('yard stats --list-undoc').and_return('100.00% documented')
44
+
45
+ expect do |b|
46
+ described_class.new(&b)
47
+ Rake::Task[:check_api_doc].invoke
48
+ end.to yield_control
49
+ end
50
+
51
+ it 'should pass if documentation is 100%' do
52
+ expect(task).to receive(:`).with('yard stats --list-undoc').and_return('100.00% documented')
53
+
54
+ expect(task.run_task(false)).not_to be
55
+ end
56
+
57
+ it 'should raise error if documentation is not 100%' do
58
+ expect(task).to receive(:`).with('yard stats --list-undoc').and_return('99.99% documented')
59
+
60
+ expect { task.run_task(false) }.to raise_error("\nFailed due to undocumented public API")
61
+ end
62
+
63
+ it 'should print verbose output if verbose is true' do
64
+ expect(task).to receive(:`).with('yard stats --list-undoc').and_return('99.99% documented')
65
+
66
+ expect { task.run_task(true) }.to raise_error("\nFailed due to undocumented public API:\n\n99.99% documented")
67
+ end
68
+
69
+ end
@@ -0,0 +1,133 @@
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/cache/download_cache'
18
+ require 'buildpack_support/rake/cached_artifact_finder'
19
+ require 'buildpack_support/rake/dependency_cache_task'
20
+ require 'buildpack_support/rake/repository_configuration_finder'
21
+ require 'buildpack_support/test/console_helper'
22
+ require 'buildpack_support/test/logging_helper'
23
+ require 'buildpack_support/test/scratch_helper'
24
+ require 'rake'
25
+
26
+ describe BuildpackSupport::Rake::DependencyCacheTask do
27
+ include_context 'console_helper'
28
+ include_context 'logging_helper'
29
+ include_context 'scratch_helper'
30
+
31
+ let(:build_dir) { scratch_dir }
32
+
33
+ let(:cached_artifact_finder) { double('CachedArtifactFinder') }
34
+
35
+ let(:download_cache) { double('DownloadCache') }
36
+
37
+ let(:repository_configuration_finder) { double('RepositoryConfigurationFinder') }
38
+
39
+ let(:staging_dir) { scratch_dir }
40
+
41
+ let(:task) do
42
+ described_class.new do |t|
43
+ t.build_dir = build_dir
44
+ t.package_name = 'test-package-name'
45
+ t.staging_dir = staging_dir
46
+ end
47
+ end
48
+
49
+ before do
50
+ Rake::Task.clear
51
+ allow(BuildpackSupport::Rake::CachedArtifactFinder).to receive(:new).and_return(cached_artifact_finder)
52
+ allow(BuildpackSupport::Cache::DownloadCache).to receive(:new).and_return(download_cache)
53
+ allow(BuildpackSupport::Rake::RepositoryConfigurationFinder).to receive(:new).and_return(repository_configuration_finder)
54
+ allow(repository_configuration_finder).to receive(:find).and_return([])
55
+ end
56
+
57
+ it 'should require build_dir to be set' do
58
+ expect { described_class.new }.to raise_error('build_dir must be configured')
59
+ end
60
+
61
+ it 'should require package_name to be set' do
62
+ expect do
63
+ described_class.new do |t|
64
+ t.build_dir = build_dir
65
+ end
66
+ end.to raise_error('package_name must be configured')
67
+ end
68
+
69
+ it 'should require staging_dir to be set' do
70
+ expect do
71
+ described_class.new do |t|
72
+ t.build_dir = build_dir
73
+ t.package_name = 'test-package-name'
74
+ end
75
+ end.to raise_error('staging_dir must be configured')
76
+ end
77
+
78
+ it 'should call block if provided' do
79
+ allow(cached_artifact_finder).to receive(:find).and_return([])
80
+ block_called = false
81
+
82
+ described_class.new do |t|
83
+ t.build_dir = build_dir
84
+ t.package_name = 'test-package-name'
85
+ t.staging_dir = staging_dir
86
+ block_called = true
87
+ end
88
+
89
+ expect(block_called).to be
90
+ end
91
+
92
+ it 'should create tasks for each dependency to be downloaded' do
93
+ expect(cached_artifact_finder).to receive(:find).and_return(['test-target'])
94
+
95
+ task
96
+
97
+ expect(Rake::Task.task_defined?('test-target')).to be
98
+ end
99
+
100
+ it 'should add cache tasks as requirements for package task' do
101
+ expect(cached_artifact_finder).to receive(:find).and_return(['test-target'])
102
+
103
+ task
104
+
105
+ expect(Rake::Task['test-package-name'].prerequisites.first).to eq('test-target')
106
+ end
107
+
108
+ it 'should cache file' do
109
+ expect(cached_artifact_finder).to receive(:find).and_return([])
110
+ expect(download_cache).to receive(:get).with('test-target')
111
+
112
+ task.run_task 'test-target', false
113
+ end
114
+
115
+ it 'should print message if verbose' do
116
+ expect(cached_artifact_finder).to receive(:find).and_return([])
117
+ expect(download_cache).to receive(:get).with('test-target')
118
+
119
+ task.run_task 'test-target', true
120
+
121
+ expect(stderr.string).to match('Caching test-target')
122
+ end
123
+
124
+ it 'should not print message if not verbose' do
125
+ expect(cached_artifact_finder).to receive(:find).and_return([])
126
+ expect(download_cache).to receive(:get).with('test-target')
127
+
128
+ task.run_task 'test-target', false
129
+
130
+ expect(stderr.string).not_to match('Caching test-target')
131
+ end
132
+
133
+ end
@@ -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/disable_remote_downloads_task'
18
+ require 'buildpack_support/test/console_helper'
19
+ require 'buildpack_support/test/scratch_helper'
20
+ require 'rake'
21
+
22
+ describe BuildpackSupport::Rake::DisableRemoteDownloadsTask 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(:source) { 'spec/fixtures/test-cache.yml' }
29
+
30
+ let(:staging_dir) { scratch_dir + 'staging' }
31
+
32
+ let(:target) { staging_dir + 'config/cache.yml' }
33
+
34
+ let(:task) do
35
+ described_class.new do |t|
36
+ t.package_name = package_name
37
+ t.staging_dir = staging_dir
38
+ end
39
+ end
40
+
41
+ before { Rake::Task.clear }
42
+
43
+ it 'should create a task with the specified name' do
44
+ task
45
+
46
+ expect(Rake::Task.task_defined?(target.to_s)).to be
47
+ end
48
+
49
+ it 'should raise and error if package_name is not specified' do
50
+ expect { described_class.new }.to raise_error('package_name must be configured')
51
+ end
52
+
53
+ it 'should raise and error if staging_dir is not specified' do
54
+ expect do
55
+ described_class.new do |t|
56
+ t.package_name = package_name
57
+ end
58
+ end.to raise_error('staging_dir must be configured')
59
+ end
60
+
61
+ it 'should call block if provided' do
62
+ called = false
63
+
64
+ described_class.new do |t|
65
+ t.package_name = package_name
66
+ t.staging_dir = staging_dir
67
+ called = true
68
+ end
69
+
70
+ expect(called).to be
71
+ end
72
+
73
+ it 'should disable remote downloads' do
74
+ task.run_task source, target, true
75
+
76
+ expect(File.read(target)).to match('remote_downloads: disabled')
77
+ end
78
+
79
+ it 'should print message to console if verbose is true' do
80
+ task.run_task source, target, true
81
+
82
+ expect(stderr.string).to match("Disabled remote downloads in #{target}")
83
+ end
84
+
85
+ it 'should not print message to console if verbose is false' do
86
+ task.run_task source, target, false
87
+
88
+ expect(stderr.string).not_to match("Disabled remote downloads in #{target}")
89
+ end
90
+
91
+ end
@@ -0,0 +1,335 @@
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/buildpack_stage_task'
18
+ require 'buildpack_support/rake/dependency_cache_task'
19
+ require 'buildpack_support/rake/disable_remote_downloads_task'
20
+ require 'buildpack_support/rake/package_task'
21
+ require 'buildpack_support/rake/package_zip_task'
22
+ require 'buildpack_support/test/console_helper'
23
+ require 'buildpack_support/test/scratch_helper'
24
+ require 'rake'
25
+
26
+ describe BuildpackSupport::Rake::PackageTask do
27
+ include_context 'console_helper'
28
+ include_context 'scratch_helper'
29
+
30
+ let(:buildpack_version) { double('BuildpackVersion', offline: false, version: 'test-version') }
31
+
32
+ let(:buildpack_stage_task_configuration) { double('BuildpackStageTaskConfiguration') }
33
+
34
+ let(:task_configuration) { double('PackageZipTaskConfiguration') }
35
+
36
+ let(:task) do
37
+ described_class.new do |t|
38
+ t.files = []
39
+ t.prefix = 'test-prefix'
40
+ t.staging_dir = scratch_dir
41
+ end
42
+ end
43
+
44
+ before do
45
+ Rake::Task.clear
46
+ expect(BuildpackSupport::BuildpackVersion).to receive(:new).with(false).and_return(buildpack_version)
47
+ end
48
+
49
+ it 'should create a task with the default name' do
50
+ task
51
+
52
+ expect(Rake::Task.task_defined?(:package)).to be
53
+ expect(Rake::Task.task_defined?(:test_name)).not_to be
54
+ end
55
+
56
+ it 'should create a task with an alternate name' do
57
+ described_class.new(:test_name) do |t|
58
+ t.files = []
59
+ t.prefix = 'test-prefix'
60
+ t.staging_dir = scratch_dir
61
+ end
62
+
63
+ expect(Rake::Task.task_defined?(:package)).not_to be
64
+ expect(Rake::Task.task_defined?(:test_name)).to be
65
+ end
66
+
67
+ it 'should call block if provided' do
68
+ called = false
69
+
70
+ described_class.new do |t|
71
+ t.files = []
72
+ t.prefix = 'test-prefix'
73
+ t.staging_dir = scratch_dir
74
+ called = true
75
+ end
76
+
77
+ expect(called).to be
78
+ end
79
+
80
+ it 'should raise an error if prefix is not configured' do
81
+ expect { described_class.new }.to raise_error('package prefix must be configured')
82
+ end
83
+
84
+ it 'should add a prerequisite on a ZIP package' do
85
+ task
86
+
87
+ expect(Rake::Task[:package].prerequisites.first).to eq('build/test-prefix-test-version.zip')
88
+ end
89
+
90
+ it 'should use unknown in package name if version is nil' do
91
+ expect(buildpack_version).to receive(:version).and_return(nil)
92
+
93
+ task
94
+
95
+ expect(Rake::Task[:package].prerequisites.first).to eq('build/test-prefix-unknown.zip')
96
+ end
97
+
98
+ it 'should add a prerequisite on a ZIP package in a non-default build directory' do
99
+ described_class.new do |t|
100
+ t.build_dir = 'other-build'
101
+ t.files = []
102
+ t.prefix = 'test-prefix'
103
+ t.staging_dir = scratch_dir
104
+ end
105
+
106
+ expect(Rake::Task[:package].prerequisites.first).to eq('other-build/test-prefix-test-version.zip')
107
+ end
108
+
109
+ it 'should create new PackageZip and BuildpackState tasks' do
110
+ expect(BuildpackSupport::Rake::PackageZipTask).to receive(:new)
111
+ expect(BuildpackSupport::Rake::BuildpackStageTask).to receive(:new)
112
+
113
+ task
114
+ end
115
+
116
+ it 'should pass PackageZipTask configuration through when verbose not set' do
117
+ expect(BuildpackSupport::Rake::PackageZipTask).to receive(:new).and_yield(task_configuration)
118
+ expect(task_configuration).to receive(:package_name=).with('build/test-prefix-test-version.zip')
119
+ expect(task_configuration).to receive(:staging_dir=).with(scratch_dir)
120
+
121
+ task
122
+ end
123
+
124
+ it 'should pass PackageZipTask configuration through when verbose set to true' do
125
+ expect(BuildpackSupport::Rake::PackageZipTask).to receive(:new).and_yield(task_configuration)
126
+ expect(task_configuration).to receive(:package_name=).with('build/test-prefix-test-version.zip')
127
+ expect(task_configuration).to receive(:staging_dir=).with(scratch_dir)
128
+ expect(task_configuration).to receive(:verbose=).with(true)
129
+
130
+ described_class.new do |t|
131
+ t.prefix = 'test-prefix'
132
+ t.files = []
133
+ t.staging_dir = scratch_dir
134
+ t.verbose = true
135
+ end
136
+ end
137
+
138
+ it 'should pass PackageZipTask configuration through when verbose set to false' do
139
+ expect(BuildpackSupport::Rake::PackageZipTask).to receive(:new).and_yield(task_configuration)
140
+ expect(task_configuration).to receive(:package_name=).with('build/test-prefix-test-version.zip')
141
+ expect(task_configuration).to receive(:staging_dir=).with(scratch_dir)
142
+ expect(task_configuration).to receive(:verbose=).with(false)
143
+
144
+ described_class.new do |t|
145
+ t.prefix = 'test-prefix'
146
+ t.files = []
147
+ t.staging_dir = scratch_dir
148
+ t.verbose = false
149
+ end
150
+ end
151
+
152
+ it 'should pass BuildpackStageTask configuration through when verbose not set' do
153
+ expect(BuildpackSupport::Rake::BuildpackStageTask).to receive(:new).and_yield(task_configuration)
154
+ expect(task_configuration).to receive(:files=).with([])
155
+ expect(task_configuration).to receive(:package_name=).with('build/test-prefix-test-version.zip')
156
+ expect(task_configuration).to receive(:staging_dir=).with(scratch_dir)
157
+
158
+ task
159
+ end
160
+
161
+ it 'should pass BuildpackStageTask configuration through when verbose set to true' do
162
+ expect(BuildpackSupport::Rake::BuildpackStageTask).to receive(:new).and_yield(task_configuration)
163
+ expect(task_configuration).to receive(:files=).with([])
164
+ expect(task_configuration).to receive(:package_name=).with('build/test-prefix-test-version.zip')
165
+ expect(task_configuration).to receive(:staging_dir=).with(scratch_dir)
166
+ expect(task_configuration).to receive(:verbose=).with(true)
167
+
168
+ described_class.new do |t|
169
+ t.prefix = 'test-prefix'
170
+ t.files = []
171
+ t.staging_dir = scratch_dir
172
+ t.verbose = true
173
+ end
174
+ end
175
+
176
+ it 'should pass BuildpackStageTask configuration through when verbose set to false' do
177
+ expect(BuildpackSupport::Rake::BuildpackStageTask).to receive(:new).and_yield(task_configuration)
178
+ expect(task_configuration).to receive(:files=).with([])
179
+ expect(task_configuration).to receive(:package_name=).with('build/test-prefix-test-version.zip')
180
+ expect(task_configuration).to receive(:staging_dir=).with(scratch_dir)
181
+ expect(task_configuration).to receive(:verbose=).with(false)
182
+
183
+ described_class.new do |t|
184
+ t.prefix = 'test-prefix'
185
+ t.files = []
186
+ t.staging_dir = scratch_dir
187
+ t.verbose = false
188
+ end
189
+ end
190
+
191
+ it 'should pass WriteVersionFileTask configuration through when verbose not set' do
192
+ expect(BuildpackSupport::Rake::WriteVersionFileTask).to receive(:new).and_yield(task_configuration)
193
+ expect(task_configuration).to receive(:buildpack_version=).with(buildpack_version)
194
+ expect(task_configuration).to receive(:package_name=).with('build/test-prefix-test-version.zip')
195
+ expect(task_configuration).to receive(:staging_dir=).with(scratch_dir)
196
+
197
+ task
198
+ end
199
+
200
+ it 'should pass WriteVersionFileTask configuration through when verbose set to true' do
201
+ expect(BuildpackSupport::Rake::WriteVersionFileTask).to receive(:new).and_yield(task_configuration)
202
+ expect(task_configuration).to receive(:buildpack_version=).with(buildpack_version)
203
+ expect(task_configuration).to receive(:package_name=).with('build/test-prefix-test-version.zip')
204
+ expect(task_configuration).to receive(:staging_dir=).with(scratch_dir)
205
+ expect(task_configuration).to receive(:verbose=).with(true)
206
+
207
+ described_class.new do |t|
208
+ t.prefix = 'test-prefix'
209
+ t.files = []
210
+ t.staging_dir = scratch_dir
211
+ t.verbose = true
212
+ end
213
+ end
214
+
215
+ it 'should pass WriteVersionFileTask configuration through when verbose set to false' do
216
+ expect(BuildpackSupport::Rake::WriteVersionFileTask).to receive(:new).and_yield(task_configuration)
217
+ expect(task_configuration).to receive(:buildpack_version=).with(buildpack_version)
218
+ expect(task_configuration).to receive(:package_name=).with('build/test-prefix-test-version.zip')
219
+ expect(task_configuration).to receive(:staging_dir=).with(scratch_dir)
220
+ expect(task_configuration).to receive(:verbose=).with(false)
221
+
222
+ described_class.new do |t|
223
+ t.prefix = 'test-prefix'
224
+ t.files = []
225
+ t.staging_dir = scratch_dir
226
+ t.verbose = false
227
+ end
228
+ end
229
+
230
+ context do
231
+
232
+ before do
233
+ allow(buildpack_version).to receive(:offline).and_return(true)
234
+ end
235
+
236
+ it 'should add offline to package name if build is offline' do
237
+ allow(BuildpackSupport::Rake::DisableRemoteDownloadsTask).to receive(:new)
238
+ allow(BuildpackSupport::Rake::DependencyCacheTask).to receive(:new)
239
+
240
+ task
241
+
242
+ expect(Rake::Task[:package].prerequisites.first).to eq('build/test-prefix-offline-test-version.zip')
243
+ end
244
+
245
+ it 'should create new DependencyCache and DisableRemoteDownloads tasks' do
246
+ expect(BuildpackSupport::Rake::DependencyCacheTask).to receive(:new)
247
+ expect(BuildpackSupport::Rake::DisableRemoteDownloadsTask).to receive(:new)
248
+
249
+ task
250
+ end
251
+
252
+ it 'should pass DisableRemoteDownloads configuration through when verbose not set' do
253
+ allow(BuildpackSupport::Rake::DependencyCacheTask).to receive(:new)
254
+ expect(BuildpackSupport::Rake::DisableRemoteDownloadsTask).to receive(:new).and_yield(task_configuration)
255
+ expect(task_configuration).to receive(:package_name=).with('build/test-prefix-offline-test-version.zip')
256
+ expect(task_configuration).to receive(:staging_dir=).with(scratch_dir)
257
+
258
+ task
259
+ end
260
+
261
+ it 'should pass DisableRemoteDownloads configuration through when verbose set to true' do
262
+ allow(BuildpackSupport::Rake::DependencyCacheTask).to receive(:new)
263
+ expect(BuildpackSupport::Rake::DisableRemoteDownloadsTask).to receive(:new).and_yield(task_configuration)
264
+ expect(task_configuration).to receive(:package_name=).with('build/test-prefix-offline-test-version.zip')
265
+ expect(task_configuration).to receive(:staging_dir=).with(scratch_dir)
266
+ expect(task_configuration).to receive(:verbose=).with(true)
267
+
268
+ described_class.new do |t|
269
+ t.prefix = 'test-prefix'
270
+ t.files = []
271
+ t.staging_dir = scratch_dir
272
+ t.verbose = true
273
+ end
274
+ end
275
+
276
+ it 'should pass DisableRemoteDownloads configuration through when verbose set to false' do
277
+ allow(BuildpackSupport::Rake::DependencyCacheTask).to receive(:new)
278
+ expect(BuildpackSupport::Rake::DisableRemoteDownloadsTask).to receive(:new).and_yield(task_configuration)
279
+ expect(task_configuration).to receive(:package_name=).with('build/test-prefix-offline-test-version.zip')
280
+ expect(task_configuration).to receive(:staging_dir=).with(scratch_dir)
281
+ expect(task_configuration).to receive(:verbose=).with(false)
282
+
283
+ described_class.new do |t|
284
+ t.prefix = 'test-prefix'
285
+ t.files = []
286
+ t.staging_dir = scratch_dir
287
+ t.verbose = false
288
+ end
289
+ end
290
+
291
+ it 'should pass DependencyCacheTask configuration through when verbose not set' do
292
+ allow(BuildpackSupport::Rake::DisableRemoteDownloadsTask).to receive(:new)
293
+ expect(BuildpackSupport::Rake::DependencyCacheTask).to receive(:new).and_yield(task_configuration)
294
+ expect(task_configuration).to receive(:build_dir=).with('build')
295
+ expect(task_configuration).to receive(:package_name=).with('build/test-prefix-offline-test-version.zip')
296
+ expect(task_configuration).to receive(:staging_dir=).with(scratch_dir)
297
+
298
+ task
299
+ end
300
+
301
+ it 'should pass DependencyCacheTask configuration through when verbose set to true' do
302
+ allow(BuildpackSupport::Rake::DisableRemoteDownloadsTask).to receive(:new)
303
+ expect(BuildpackSupport::Rake::DependencyCacheTask).to receive(:new).and_yield(task_configuration)
304
+ expect(task_configuration).to receive(:build_dir=).with('build')
305
+ expect(task_configuration).to receive(:package_name=).with('build/test-prefix-offline-test-version.zip')
306
+ expect(task_configuration).to receive(:staging_dir=).with(scratch_dir)
307
+ expect(task_configuration).to receive(:verbose=).with(true)
308
+
309
+ described_class.new do |t|
310
+ t.prefix = 'test-prefix'
311
+ t.files = []
312
+ t.staging_dir = scratch_dir
313
+ t.verbose = true
314
+ end
315
+ end
316
+
317
+ it 'should pass DependencyCacheTask configuration through when verbose set to false' do
318
+ allow(BuildpackSupport::Rake::DisableRemoteDownloadsTask).to receive(:new)
319
+ expect(BuildpackSupport::Rake::DependencyCacheTask).to receive(:new).and_yield(task_configuration)
320
+ expect(task_configuration).to receive(:build_dir=).with('build')
321
+ expect(task_configuration).to receive(:package_name=).with('build/test-prefix-offline-test-version.zip')
322
+ expect(task_configuration).to receive(:staging_dir=).with(scratch_dir)
323
+ expect(task_configuration).to receive(:verbose=).with(false)
324
+
325
+ described_class.new do |t|
326
+ t.prefix = 'test-prefix'
327
+ t.files = []
328
+ t.staging_dir = scratch_dir
329
+ t.verbose = false
330
+ end
331
+ end
332
+
333
+ end
334
+
335
+ end