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,30 @@
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 'rspec/expectations'
17
+ require 'rspec/matchers/built_in/yield'
18
+
19
+ RSpec::Matchers.define :yield_file_with_content do |expected|
20
+ match do |block|
21
+ probe = RSpec::Matchers::BuiltIn::YieldProbe.probe(block)
22
+ probe.yielded_once?(:yield_with_args) && content(probe.single_yield_args.first) =~ expected
23
+ end
24
+
25
+ supports_block_expectations
26
+
27
+ def content(file)
28
+ File.read(file)
29
+ end
30
+ end
@@ -0,0 +1,81 @@
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/component/application'
18
+ require 'buildpack_support/test/application_helper'
19
+ require 'buildpack_support/test/environment_helper'
20
+ require 'fileutils'
21
+
22
+ describe BuildpackSupport::Component::Application do
23
+ include_context 'application_helper'
24
+ include_context 'environment_helper'
25
+
26
+ let(:environment) do
27
+ { 'test-key' => 'test-value', 'VCAP_APPLICATION' => vcap_application.to_yaml,
28
+ 'VCAP_SERVICES' => vcap_services.to_yaml }
29
+ end
30
+
31
+ it 'should return a parsed version of VCAP_APPLICATION as details' do
32
+ expect(application.details).to eq(vcap_application)
33
+ end
34
+
35
+ it 'should remove VCAP_APPLICATION and VCAP_SERVICES from environment' do
36
+ expect(application.environment).to include('test-key')
37
+ expect(application.environment).not_to include('VCAP_APPLICATION')
38
+ expect(application.environment).not_to include('VCAP_SERVICES')
39
+ end
40
+
41
+ it 'should return a child path if it does not exist' do
42
+ expect(application.root + 'test-file').not_to be_nil
43
+ end
44
+
45
+ it 'should not return a child path that does not exist if it exists but is not in the initial contents' do
46
+ FileUtils.touch(scratch_dir + 'test-file')
47
+
48
+ expect(application.root + 'test-file').not_to exist
49
+ end
50
+
51
+ it 'should return a child path if it exists and is in the initial contents',
52
+ app_fixture: 'application' do
53
+
54
+ expect(application.root + 'test-file').not_to be_nil
55
+ end
56
+
57
+ it 'should only list children that exist initially',
58
+ app_fixture: 'application' do
59
+
60
+ FileUtils.mkdir_p(scratch_dir + '.ignore-directory')
61
+ FileUtils.mkdir_p(scratch_dir + 'ignore-directory')
62
+ FileUtils.touch(scratch_dir + '.ignore-file')
63
+ FileUtils.touch(scratch_dir + 'ignore-file')
64
+
65
+ children = application.root.children
66
+ expect(children.size).to eq(4)
67
+ expect(children).to include(scratch_dir + '.test-directory')
68
+ expect(children).to include(scratch_dir + 'test-directory')
69
+ expect(children).to include(scratch_dir + '.test-file')
70
+ expect(children).to include(scratch_dir + 'test-file')
71
+ expect(children).not_to include(scratch_dir + '.ignore-directory')
72
+ expect(children).not_to include(scratch_dir + 'ignore-directory')
73
+ expect(children).not_to include(scratch_dir + '.ignore-file')
74
+ expect(children).not_to include(scratch_dir + 'ignore-file')
75
+ end
76
+
77
+ it 'should return a parsed version of VCAP_SERVICES as services' do
78
+ expect(application.services.find_service(/test-service/)).to be
79
+ end
80
+
81
+ end
@@ -0,0 +1,81 @@
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/component/base_component'
18
+ require 'buildpack_support/test/base_component_helper'
19
+
20
+ describe BuildpackSupport::Component::BaseComponent do
21
+ include_context 'base_component_helper'
22
+
23
+ let(:component) { StubBaseComponent.new context }
24
+
25
+ it 'should assign application to an instance variable' do
26
+ expect(component.application).to equal(application)
27
+ end
28
+
29
+ it 'should assign component name to an instance variable' do
30
+ expect(component.component_name).to eq('Stub Base Component')
31
+ end
32
+
33
+ it 'should assign configuration to an instance variable' do
34
+ expect(component.configuration).to equal(configuration)
35
+ end
36
+
37
+ it 'should assign droplet to an instance variable' do
38
+ expect(component.droplet).to equal(droplet)
39
+ end
40
+
41
+ it 'should fail if methods are unimplemented' do
42
+ expect { component.detect }.to raise_error
43
+ expect { component.compile }.to raise_error
44
+ expect { component.release }.to raise_error
45
+ end
46
+
47
+ it 'should download file and yield it',
48
+ cache_fixture: 'stub-download.tar.gz' do
49
+
50
+ component.download(version, uri) { |file| expect(file.path).to eq('spec/fixtures/stub-download.tar.gz') }
51
+ expect(stdout.string).to match(/Downloading Stub Base Component #{version} from #{uri}/)
52
+ end
53
+
54
+ it 'should download and expand TAR file in the sandbox',
55
+ cache_fixture: 'stub-download.tar.gz' do
56
+
57
+ component.download_tar(version, uri)
58
+ expect(droplet.sandbox + 'test-file').to exist
59
+ end
60
+
61
+ it 'should download and expand ZIP file in the sandbox',
62
+ cache_fixture: 'stub-download.zip' do
63
+
64
+ component.download_zip(version, uri, false)
65
+ expect(droplet.sandbox + 'test-file').to exist
66
+ end
67
+
68
+ it 'should download and expand ZIP file, stripping the top level directory in the sandbox',
69
+ cache_fixture: 'stub-download-with-top-level.zip' do
70
+
71
+ component.download_zip(version, uri)
72
+ expect(droplet.sandbox + 'test-file').to exist
73
+ end
74
+
75
+ end
76
+
77
+ class StubBaseComponent < BuildpackSupport::Component::BaseComponent
78
+
79
+ attr_reader :application, :component_name, :configuration, :droplet
80
+
81
+ end
@@ -0,0 +1,72 @@
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/component/base_droplet'
18
+ require 'buildpack_support/test/base_droplet_helper'
19
+ require 'buildpack_support/test/scratch_helper'
20
+ require 'fileutils'
21
+ require 'pathname'
22
+
23
+ describe BuildpackSupport::Component::BaseDroplet do
24
+ include_context 'base_droplet_helper'
25
+ include_context 'scratch_helper'
26
+
27
+ it 'should return component_id' do
28
+ expect(droplet.component_id).to eq(component_id)
29
+ end
30
+
31
+ it 'should return an existent child if in application' do
32
+ FileUtils.touch(scratch_dir + 'test-file')
33
+
34
+ expect(droplet.root + 'test-file').to exist
35
+ end
36
+
37
+ it 'should return an existent child if in sandbox' do
38
+ FileUtils.mkdir_p(scratch_dir + '.buildpack/base_droplet')
39
+ FileUtils.touch(scratch_dir + '.buildpack/base_droplet/test-file')
40
+
41
+ expect(droplet.sandbox + 'test-file').to exist
42
+ end
43
+
44
+ it 'should return a non-existent child if in buildpack but not sandbox' do
45
+ FileUtils.mkdir_p(scratch_dir + '.buildpack')
46
+ FileUtils.touch(scratch_dir + '.buildpack/test-file')
47
+
48
+ expect(droplet.root + '.buildpack/test-file').not_to exist
49
+ end
50
+
51
+ it 'should expose a sandbox for the component based on its component_id' do
52
+ expect(droplet.sandbox).to eq(scratch_dir + '.buildpack/base_droplet')
53
+ end
54
+
55
+ context do
56
+ let(:fixtures_directory) { Pathname.new('spec/fixtures') }
57
+
58
+ it 'should copy resources if resources directory exists' do
59
+ stub_const(described_class.to_s + '::RESOURCES_DIRECTORY', fixtures_directory)
60
+ allow(fixtures_directory).to receive(:+).with('base_droplet').and_return(fixtures_directory + 'droplet-resources')
61
+
62
+ droplet.copy_resources
63
+
64
+ expect(droplet.sandbox + 'droplet-resource').to exist
65
+ end
66
+ end
67
+
68
+ it 'should not copy resources if resource directory does not exist' do
69
+ droplet.copy_resources
70
+ end
71
+
72
+ end
@@ -0,0 +1,63 @@
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/component/downloads'
18
+ require 'buildpack_support/test/base_component_helper'
19
+
20
+ describe BuildpackSupport::Component::Downloads do
21
+ include_context 'base_component_helper'
22
+
23
+ let(:component) { StubDownloadsClass.new droplet }
24
+
25
+ it 'should download file and yield it',
26
+ cache_fixture: 'stub-download.tar.gz' do
27
+
28
+ component.download(version, uri) { |file| expect(file.path).to eq('spec/fixtures/stub-download.tar.gz') }
29
+ expect(stdout.string).to match(/Downloading Stub Component #{version} from #{uri}/)
30
+ end
31
+
32
+ it 'should download and expand TAR file in the sandbox',
33
+ cache_fixture: 'stub-download.tar.gz' do
34
+
35
+ component.download_tar(version, uri)
36
+ expect(droplet.sandbox + 'test-file').to exist
37
+ end
38
+
39
+ it 'should download and expand ZIP file in the sandbox',
40
+ cache_fixture: 'stub-download.zip' do
41
+
42
+ component.download_zip(version, uri, false)
43
+ expect(droplet.sandbox + 'test-file').to exist
44
+ end
45
+
46
+ it 'should download and expand ZIP file, stripping the top level directory in the sandbox',
47
+ cache_fixture: 'stub-download-with-top-level.zip' do
48
+
49
+ component.download_zip(version, uri)
50
+ expect(droplet.sandbox + 'test-file').to exist
51
+ end
52
+
53
+ end
54
+
55
+ class StubDownloadsClass
56
+ include BuildpackSupport::Component::Downloads
57
+
58
+ def initialize(droplet)
59
+ @component_name = 'Stub Component'
60
+ @droplet = droplet
61
+ end
62
+
63
+ end
@@ -0,0 +1,80 @@
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/component/services'
18
+ require 'buildpack_support/test/logging_helper'
19
+
20
+ describe BuildpackSupport::Component::Services do
21
+ include_context 'logging_helper'
22
+
23
+ let(:service) do
24
+ { 'name' => 'test-name', 'label' => 'test-label', 'tags' => ['test-tag'], 'plan' => 'test-plan',
25
+ 'credentials' => { 'uri' => 'test-uri' } }
26
+ end
27
+
28
+ let(:services) { described_class.new('test' => [service]) }
29
+
30
+ it 'should return false from one_service? if there is no service that matches' do
31
+ expect(services.one_service? 'bad-test').not_to be
32
+ expect(services.one_service?(/bad-test/)).not_to be
33
+ end
34
+
35
+ it 'should return true from one_service? if there is a matching name' do
36
+ expect(services.one_service? 'test-name').to be
37
+ expect(services.one_service?(/test-name/)).to be
38
+ end
39
+
40
+ it 'should return true from one_service? if there is a matching label' do
41
+ expect(services.one_service? 'test-label').to be
42
+ expect(services.one_service?(/test-label/)).to be
43
+ end
44
+
45
+ it 'should return true from one_service? if there is a matching tag' do
46
+ expect(services.one_service? 'test-tag').to be
47
+ expect(services.one_service?(/test-tag/)).to be
48
+ end
49
+
50
+ it 'should return false from one_service? if there is a matching service without required credentials' do
51
+ expect(services.one_service? 'test-tag', 'bad-credential').not_to be
52
+ expect(services.one_service?(/test-tag/, 'bad-credential')).not_to be
53
+ end
54
+
55
+ it 'should return true from one_service? if there is a matching service with required credentials' do
56
+ expect(services.one_service? 'test-tag', 'uri').to be
57
+ expect(services.one_service?(/test-tag/, 'uri')).to be
58
+ end
59
+
60
+ it 'should return nil from find_service? if there is no service that matches' do
61
+ expect(services.find_service 'bad-test').to be_nil
62
+ expect(services.find_service(/bad-test/)).to be_nil
63
+ end
64
+
65
+ it 'should return service from find_service? if there is a matching name' do
66
+ expect(services.find_service 'test-name').to be(service)
67
+ expect(services.find_service(/test-name/)).to be(service)
68
+ end
69
+
70
+ it 'should return service from find_service? if there is a matching label' do
71
+ expect(services.find_service 'test-label').to be(service)
72
+ expect(services.find_service(/test-label/)).to be(service)
73
+ end
74
+
75
+ it 'should return service from find_service? if there is a matching tag' do
76
+ expect(services.find_service 'test-tag').to be(service)
77
+ expect(services.find_service(/test-tag/)).to be(service)
78
+ end
79
+
80
+ end
@@ -0,0 +1,58 @@
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/component/versioned_dependency_component'
18
+ require 'buildpack_support/test/versioned_dependency_component_helper'
19
+
20
+ describe BuildpackSupport::Component::VersionedDependencyComponent do
21
+ include_context 'versioned_dependency_component_helper'
22
+
23
+ let(:component) { StubVersionedDependencyComponent.new context }
24
+
25
+ it 'should fail if methods are unimplemented' do
26
+ expect { component.compile }.to raise_error
27
+ expect { component.release }.to raise_error
28
+ expect { component.supports? }.to raise_error
29
+ end
30
+
31
+ context do
32
+ before do
33
+ allow_any_instance_of(StubVersionedDependencyComponent).to receive(:supports?).and_return(false)
34
+ end
35
+
36
+ it 'should return nil from detect if not supported' do
37
+ expect(component.detect).to be_nil
38
+ end
39
+ end
40
+
41
+ context do
42
+
43
+ before do
44
+ allow_any_instance_of(StubVersionedDependencyComponent).to receive(:supports?).and_return(true)
45
+ end
46
+
47
+ it 'should return name and version string from detect if supported' do
48
+ expect(component.detect).to eq("stub-versioned-dependency-component=#{version}")
49
+ end
50
+ end
51
+
52
+ end
53
+
54
+ class StubVersionedDependencyComponent < BuildpackSupport::Component::VersionedDependencyComponent
55
+
56
+ public :supports?
57
+
58
+ end