buildpack-support 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE +202 -0
- data/NOTICE +2 -0
- data/docs/cache.md +77 -0
- data/docs/component.md +1 -0
- data/docs/configuration.md +27 -0
- data/docs/logging.md +54 -0
- data/docs/other.md +1 -0
- data/docs/rake.md +1 -0
- data/docs/repository.md +116 -0
- data/docs/test.md +1 -0
- data/lib/buildpack_support.rb +18 -0
- data/lib/buildpack_support/base_buildpack.rb +166 -0
- data/lib/buildpack_support/buildpack_version.rb +124 -0
- data/lib/buildpack_support/cache.rb +24 -0
- data/lib/buildpack_support/cache/application_cache.rb +41 -0
- data/lib/buildpack_support/cache/cached_file.rb +103 -0
- data/lib/buildpack_support/cache/download_cache.rb +280 -0
- data/lib/buildpack_support/cache/inferred_network_failure.rb +26 -0
- data/lib/buildpack_support/cache/internet_availability.rb +64 -0
- data/lib/buildpack_support/component.rb +24 -0
- data/lib/buildpack_support/component/application.rb +76 -0
- data/lib/buildpack_support/component/base_component.rb +78 -0
- data/lib/buildpack_support/component/base_droplet.rb +96 -0
- data/lib/buildpack_support/component/downloads.rb +88 -0
- data/lib/buildpack_support/component/services.rb +84 -0
- data/lib/buildpack_support/component/versioned_dependency_component.rb +71 -0
- data/lib/buildpack_support/component/versioned_downloads.rb +57 -0
- data/lib/buildpack_support/component/with_timing.rb +40 -0
- data/lib/buildpack_support/configuration_utils.rb +58 -0
- data/lib/buildpack_support/constantize.rb +46 -0
- data/lib/buildpack_support/dash_case.rb +29 -0
- data/lib/buildpack_support/directory_finder.rb +45 -0
- data/lib/buildpack_support/filtering_pathname.rb +227 -0
- data/lib/buildpack_support/format_duration.rb +57 -0
- data/lib/buildpack_support/logging.rb +22 -0
- data/lib/buildpack_support/logging/delegating_logger.rb +48 -0
- data/lib/buildpack_support/logging/logger_factory.rb +148 -0
- data/lib/buildpack_support/qualify_path.rb +36 -0
- data/lib/buildpack_support/rake.rb +22 -0
- data/lib/buildpack_support/rake/buildpack_stage_task.rb +86 -0
- data/lib/buildpack_support/rake/cached_artifact_finder.rb +99 -0
- data/lib/buildpack_support/rake/check_api_doc_task.rb +70 -0
- data/lib/buildpack_support/rake/dependency_cache_task.rb +87 -0
- data/lib/buildpack_support/rake/disable_remote_downloads_task.rb +80 -0
- data/lib/buildpack_support/rake/package_task.rb +133 -0
- data/lib/buildpack_support/rake/package_zip_task.rb +80 -0
- data/lib/buildpack_support/rake/repository_configuration_finder.rb +66 -0
- data/lib/buildpack_support/rake/write_version_file_task.rb +82 -0
- data/lib/buildpack_support/repository.rb +24 -0
- data/lib/buildpack_support/repository/configured_item.rb +81 -0
- data/lib/buildpack_support/repository/repository_index.rb +98 -0
- data/lib/buildpack_support/repository/wildcard_version_resolver.rb +75 -0
- data/lib/buildpack_support/shell.rb +41 -0
- data/lib/buildpack_support/snake_case.rb +30 -0
- data/lib/buildpack_support/space_case.rb +29 -0
- data/lib/buildpack_support/test/application_helper.rb +41 -0
- data/lib/buildpack_support/test/base_component_helper.rb +59 -0
- data/lib/buildpack_support/test/base_droplet_helper.rb +36 -0
- data/lib/buildpack_support/test/console_helper.rb +57 -0
- data/lib/buildpack_support/test/environment_helper.rb +32 -0
- data/lib/buildpack_support/test/internet_availability_helper.rb +29 -0
- data/lib/buildpack_support/test/logging_helper.rb +50 -0
- data/lib/buildpack_support/test/scratch_helper.rb +32 -0
- data/lib/buildpack_support/test/versioned_dependency_component_helper.rb +32 -0
- data/lib/buildpack_support/test/with_load_path_helper.rb +27 -0
- data/lib/buildpack_support/to_b.rb +38 -0
- data/lib/buildpack_support/tokenized_version.rb +157 -0
- data/lib/buildpack_support/version.rb +23 -0
- data/spec/buildpack_support/base_buildpack_spec.rb +112 -0
- data/spec/buildpack_support/buildpack_version_spec.rb +122 -0
- data/spec/buildpack_support/cache/application_cache_spec.rb +56 -0
- data/spec/buildpack_support/cache/cached_file_spec.rb +94 -0
- data/spec/buildpack_support/cache/download_cache_spec.rb +293 -0
- data/spec/buildpack_support/cache/internet_availability_spec.rb +57 -0
- data/spec/buildpack_support/cache/yield_file_with_content.rb +30 -0
- data/spec/buildpack_support/component/application_spec.rb +81 -0
- data/spec/buildpack_support/component/base_component_spec.rb +81 -0
- data/spec/buildpack_support/component/base_droplet_spec.rb +72 -0
- data/spec/buildpack_support/component/downloads_spec.rb +63 -0
- data/spec/buildpack_support/component/services_spec.rb +80 -0
- data/spec/buildpack_support/component/versioned_dependency_component_spec.rb +58 -0
- data/spec/buildpack_support/component/versioned_downloads_spec.rb +58 -0
- data/spec/buildpack_support/component/with_timing_spec.rb +30 -0
- data/spec/buildpack_support/configuration_utils_spec.rb +39 -0
- data/spec/buildpack_support/constantize_spec.rb +34 -0
- data/spec/buildpack_support/dash_case_spec.rb +41 -0
- data/spec/buildpack_support/directory_finder_spec.rb +41 -0
- data/spec/buildpack_support/filtering_pathname_spec.rb +443 -0
- data/spec/buildpack_support/format_duration_spec.rb +60 -0
- data/spec/buildpack_support/logging/delegating_logger_spec.rb +62 -0
- data/spec/buildpack_support/logging/logger_factory_spec.rb +262 -0
- data/spec/buildpack_support/qualify_path_spec.rb +42 -0
- data/spec/buildpack_support/rake/buildpack_stage_task_spec.rb +88 -0
- data/spec/buildpack_support/rake/cached_artifact_finder_spec.rb +73 -0
- data/spec/buildpack_support/rake/check_api_doc_task_spec.rb +69 -0
- data/spec/buildpack_support/rake/dependency_cache_task_spec.rb +133 -0
- data/spec/buildpack_support/rake/disable_remote_downloads_task_spec.rb +91 -0
- data/spec/buildpack_support/rake/package_task_spec.rb +335 -0
- data/spec/buildpack_support/rake/package_zip_task_spec.rb +91 -0
- data/spec/buildpack_support/rake/repository_configuration_finder_spec.rb +61 -0
- data/spec/buildpack_support/rake/write_version_file_task_spec.rb +96 -0
- data/spec/buildpack_support/repository/configured_item_spec.rb +78 -0
- data/spec/buildpack_support/repository/repository_index_spec.rb +118 -0
- data/spec/buildpack_support/repository/wildcard_version_resolver_spec.rb +73 -0
- data/spec/buildpack_support/shell_spec.rb +32 -0
- data/spec/buildpack_support/snake_case_spec.rb +45 -0
- data/spec/buildpack_support/space_case_spec.rb +41 -0
- data/spec/buildpack_support/to_b_spec.rb +41 -0
- data/spec/buildpack_support/tokenized_version_spec.rb +132 -0
- data/spec/fixtures/application/test-file +0 -0
- data/spec/fixtures/config/found-config.yml +2 -0
- data/spec/fixtures/droplet-resources/droplet-resource +0 -0
- data/spec/fixtures/stub-download-with-top-level.zip +0 -0
- data/spec/fixtures/stub-download.tar.gz +0 -0
- data/spec/fixtures/stub-download.zip +0 -0
- data/spec/fixtures/test-cache.yml +18 -0
- data/spec/fixtures/test-index.yml +2 -0
- data/spec/fixtures/test_component.rb +0 -0
- data/spec/fixtures/zip-contents/test-directory/test-deep-file +0 -0
- data/spec/fixtures/zip-contents/test-file +0 -0
- data/spec/spec_helper.rb +30 -0
- metadata +416 -0
@@ -0,0 +1,60 @@
|
|
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/format_duration'
|
18
|
+
|
19
|
+
describe 'format duration' do
|
20
|
+
|
21
|
+
it 'should display seconds' do
|
22
|
+
expect_time_string '0.0s', MILLISECOND
|
23
|
+
expect_time_string '0.1s', TENTH
|
24
|
+
expect_time_string '1.0s', SECOND
|
25
|
+
expect_time_string '1.1s', SECOND + TENTH
|
26
|
+
expect_time_string '1.1s', SECOND + TENTH + MILLISECOND
|
27
|
+
end
|
28
|
+
|
29
|
+
it 'should display minutes' do
|
30
|
+
expect_time_string '1m 0s', MINUTE
|
31
|
+
expect_time_string '1m 1s', MINUTE + SECOND
|
32
|
+
expect_time_string '1m 1s', MINUTE + SECOND + TENTH
|
33
|
+
expect_time_string '1m 1s', MINUTE + SECOND + TENTH + MILLISECOND
|
34
|
+
end
|
35
|
+
|
36
|
+
it 'should display hours' do
|
37
|
+
expect_time_string '1h 0m', HOUR
|
38
|
+
expect_time_string '1h 1m', HOUR + MINUTE
|
39
|
+
expect_time_string '1h 1m', HOUR + MINUTE + SECOND
|
40
|
+
expect_time_string '1h 1m', HOUR + MINUTE + SECOND + TENTH
|
41
|
+
expect_time_string '1h 1m', HOUR + MINUTE + SECOND + TENTH + MILLISECOND
|
42
|
+
end
|
43
|
+
|
44
|
+
private
|
45
|
+
|
46
|
+
MILLISECOND = 0.001.freeze
|
47
|
+
|
48
|
+
TENTH = (100 * MILLISECOND).freeze
|
49
|
+
|
50
|
+
SECOND = (10 * TENTH).freeze
|
51
|
+
|
52
|
+
MINUTE = (60 * SECOND).freeze
|
53
|
+
|
54
|
+
HOUR = (60 * MINUTE).freeze
|
55
|
+
|
56
|
+
def expect_time_string(expected, time)
|
57
|
+
expect(time.duration).to eq(expected)
|
58
|
+
end
|
59
|
+
|
60
|
+
end
|
@@ -0,0 +1,62 @@
|
|
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/logging/delegating_logger'
|
18
|
+
require 'logger'
|
19
|
+
|
20
|
+
describe BuildpackSupport::Logging::DelegatingLogger do
|
21
|
+
|
22
|
+
let(:block) { ->() { 'test-message' } }
|
23
|
+
let(:delegate1) { double('delegate1') }
|
24
|
+
let(:delegate2) { double('delegate2') }
|
25
|
+
let(:delegating_logger) { described_class.new('test-klass', [delegate1, delegate2]) }
|
26
|
+
|
27
|
+
it 'should delegate FATAL calls' do
|
28
|
+
expect(delegate1).to receive(:add).with(Logger::FATAL, nil, 'test-klass')
|
29
|
+
expect(delegate2).to receive(:add).with(Logger::FATAL, nil, 'test-klass')
|
30
|
+
|
31
|
+
delegating_logger.fatal
|
32
|
+
end
|
33
|
+
|
34
|
+
it 'should delegate ERROR calls' do
|
35
|
+
expect(delegate1).to receive(:add).with(Logger::ERROR, nil, 'test-klass')
|
36
|
+
expect(delegate2).to receive(:add).with(Logger::ERROR, nil, 'test-klass')
|
37
|
+
|
38
|
+
delegating_logger.error
|
39
|
+
end
|
40
|
+
|
41
|
+
it 'should delegate WARN calls' do
|
42
|
+
expect(delegate1).to receive(:add).with(Logger::WARN, nil, 'test-klass')
|
43
|
+
expect(delegate2).to receive(:add).with(Logger::WARN, nil, 'test-klass')
|
44
|
+
|
45
|
+
delegating_logger.warn
|
46
|
+
end
|
47
|
+
|
48
|
+
it 'should delegate INFO calls' do
|
49
|
+
expect(delegate1).to receive(:add).with(Logger::INFO, nil, 'test-klass')
|
50
|
+
expect(delegate2).to receive(:add).with(Logger::INFO, nil, 'test-klass')
|
51
|
+
|
52
|
+
delegating_logger.info
|
53
|
+
end
|
54
|
+
|
55
|
+
it 'should delegate DEBUG calls' do
|
56
|
+
expect(delegate1).to receive(:add).with(Logger::DEBUG, nil, 'test-klass')
|
57
|
+
expect(delegate2).to receive(:add).with(Logger::DEBUG, nil, 'test-klass')
|
58
|
+
|
59
|
+
delegating_logger.debug
|
60
|
+
end
|
61
|
+
|
62
|
+
end
|
@@ -0,0 +1,262 @@
|
|
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/logging/logger_factory'
|
19
|
+
require 'buildpack_support/test/console_helper'
|
20
|
+
require 'buildpack_support/test/logging_helper'
|
21
|
+
|
22
|
+
describe BuildpackSupport::Logging::LoggerFactory do
|
23
|
+
include_context 'console_helper'
|
24
|
+
include_context 'logging_helper'
|
25
|
+
|
26
|
+
let(:logger) { described_class.instance.get_logger String }
|
27
|
+
|
28
|
+
it 'should maintain backwards compatibility' do
|
29
|
+
expect(described_class.get_logger String).to be
|
30
|
+
end
|
31
|
+
|
32
|
+
it 'should log all levels to file',
|
33
|
+
log_level: 'FATAL' do
|
34
|
+
|
35
|
+
trigger
|
36
|
+
|
37
|
+
expect(log_contents).to match(/DEBUG block-debug-message/)
|
38
|
+
expect(log_contents).to match(/INFO block-info-message/)
|
39
|
+
expect(log_contents).to match(/WARN block-warn-message/)
|
40
|
+
expect(log_contents).to match(/ERROR block-error-message/)
|
41
|
+
expect(log_contents).to match(/FATAL block-fatal-message/)
|
42
|
+
|
43
|
+
expect(log_contents).to match(/DEBUG param-debug-message/)
|
44
|
+
expect(log_contents).to match(/INFO param-info-message/)
|
45
|
+
expect(log_contents).to match(/WARN param-warn-message/)
|
46
|
+
expect(log_contents).to match(/ERROR param-error-message/)
|
47
|
+
expect(log_contents).to match(/FATAL param-fatal-message/)
|
48
|
+
end
|
49
|
+
|
50
|
+
it 'should log all levels to console when BP_LOG_LEVEL set to DEBUG',
|
51
|
+
log_level: 'DEBUG' do
|
52
|
+
|
53
|
+
trigger
|
54
|
+
|
55
|
+
expect(stderr.string).to match(/DEBUG block-debug-message/)
|
56
|
+
expect(stderr.string).to match(/INFO block-info-message/)
|
57
|
+
expect(stderr.string).to match(/WARN block-warn-message/)
|
58
|
+
expect(stderr.string).to match(/ERROR block-error-message/)
|
59
|
+
expect(stderr.string).to match(/FATAL block-fatal-message/)
|
60
|
+
|
61
|
+
expect(stderr.string).to match(/DEBUG param-debug-message/)
|
62
|
+
expect(stderr.string).to match(/INFO param-info-message/)
|
63
|
+
expect(stderr.string).to match(/WARN param-warn-message/)
|
64
|
+
expect(stderr.string).to match(/ERROR param-error-message/)
|
65
|
+
expect(stderr.string).to match(/FATAL param-fatal-message/)
|
66
|
+
end
|
67
|
+
|
68
|
+
it 'should log all levels above INFO to console when BP_LOG_LEVEL set to INFO',
|
69
|
+
log_level: 'INFO' do
|
70
|
+
|
71
|
+
trigger
|
72
|
+
|
73
|
+
expect(stderr.string).not_to match(/DEBUG block-debug-message/)
|
74
|
+
expect(stderr.string).to match(/INFO block-info-message/)
|
75
|
+
expect(stderr.string).to match(/WARN block-warn-message/)
|
76
|
+
expect(stderr.string).to match(/ERROR block-error-message/)
|
77
|
+
expect(stderr.string).to match(/FATAL block-fatal-message/)
|
78
|
+
|
79
|
+
expect(stderr.string).not_to match(/DEBUG param-debug-message/)
|
80
|
+
expect(stderr.string).to match(/INFO param-info-message/)
|
81
|
+
expect(stderr.string).to match(/WARN param-warn-message/)
|
82
|
+
expect(stderr.string).to match(/ERROR param-error-message/)
|
83
|
+
expect(stderr.string).to match(/FATAL param-fatal-message/)
|
84
|
+
end
|
85
|
+
|
86
|
+
it 'should log all levels above WARN to console when BP_LOG_LEVEL set to WARN',
|
87
|
+
log_level: 'WARN' do
|
88
|
+
|
89
|
+
trigger
|
90
|
+
|
91
|
+
expect(stderr.string).not_to match(/DEBUG block-debug-message/)
|
92
|
+
expect(stderr.string).not_to match(/INFO block-info-message/)
|
93
|
+
expect(stderr.string).to match(/WARN block-warn-message/)
|
94
|
+
expect(stderr.string).to match(/ERROR block-error-message/)
|
95
|
+
expect(stderr.string).to match(/FATAL block-fatal-message/)
|
96
|
+
|
97
|
+
expect(stderr.string).not_to match(/DEBUG param-debug-message/)
|
98
|
+
expect(stderr.string).not_to match(/INFO param-info-message/)
|
99
|
+
expect(stderr.string).to match(/WARN param-warn-message/)
|
100
|
+
expect(stderr.string).to match(/ERROR param-error-message/)
|
101
|
+
expect(stderr.string).to match(/FATAL param-fatal-message/)
|
102
|
+
end
|
103
|
+
|
104
|
+
it 'should log all levels above ERROR to console when BP_LOG_LEVEL set to ERROR',
|
105
|
+
log_level: 'ERROR' do
|
106
|
+
|
107
|
+
trigger
|
108
|
+
|
109
|
+
expect(stderr.string).not_to match(/DEBUG block-debug-message/)
|
110
|
+
expect(stderr.string).not_to match(/INFO block-info-message/)
|
111
|
+
expect(stderr.string).not_to match(/WARN block-warn-message/)
|
112
|
+
expect(stderr.string).to match(/ERROR block-error-message/)
|
113
|
+
expect(stderr.string).to match(/FATAL block-fatal-message/)
|
114
|
+
|
115
|
+
expect(stderr.string).not_to match(/DEBUG param-debug-message/)
|
116
|
+
expect(stderr.string).not_to match(/INFO param-info-message/)
|
117
|
+
expect(stderr.string).not_to match(/WARN param-warn-message/)
|
118
|
+
expect(stderr.string).to match(/ERROR param-error-message/)
|
119
|
+
expect(stderr.string).to match(/FATAL param-fatal-message/)
|
120
|
+
end
|
121
|
+
|
122
|
+
it 'should log FATAL to console when BP_LOG_LEVEL set to FATAL',
|
123
|
+
log_level: 'FATAL' do
|
124
|
+
|
125
|
+
trigger
|
126
|
+
|
127
|
+
expect(stderr.string).not_to match(/DEBUG block-debug-message/)
|
128
|
+
expect(stderr.string).not_to match(/INFO block-info-message/)
|
129
|
+
expect(stderr.string).not_to match(/WARN block-warn-message/)
|
130
|
+
expect(stderr.string).not_to match(/ERROR block-error-message/)
|
131
|
+
expect(stderr.string).to match(/FATAL block-fatal-message/)
|
132
|
+
|
133
|
+
expect(stderr.string).not_to match(/DEBUG param-debug-message/)
|
134
|
+
expect(stderr.string).not_to match(/INFO param-info-message/)
|
135
|
+
expect(stderr.string).not_to match(/WARN param-warn-message/)
|
136
|
+
expect(stderr.string).not_to match(/ERROR param-error-message/)
|
137
|
+
expect(stderr.string).to match(/FATAL param-fatal-message/)
|
138
|
+
end
|
139
|
+
|
140
|
+
it 'should log all levels to console when $DEBUG set',
|
141
|
+
:debug do
|
142
|
+
|
143
|
+
trigger
|
144
|
+
|
145
|
+
expect(stderr.string).to match(/DEBUG block-debug-message/)
|
146
|
+
expect(stderr.string).to match(/INFO block-info-message/)
|
147
|
+
expect(stderr.string).to match(/WARN block-warn-message/)
|
148
|
+
expect(stderr.string).to match(/ERROR block-error-message/)
|
149
|
+
expect(stderr.string).to match(/FATAL block-fatal-message/)
|
150
|
+
|
151
|
+
expect(stderr.string).to match(/DEBUG param-debug-message/)
|
152
|
+
expect(stderr.string).to match(/INFO param-info-message/)
|
153
|
+
expect(stderr.string).to match(/WARN param-warn-message/)
|
154
|
+
expect(stderr.string).to match(/ERROR param-error-message/)
|
155
|
+
expect(stderr.string).to match(/FATAL param-fatal-message/)
|
156
|
+
|
157
|
+
end
|
158
|
+
|
159
|
+
it 'should log all levels to console when $VERBOSE set',
|
160
|
+
:verbose do
|
161
|
+
|
162
|
+
trigger
|
163
|
+
|
164
|
+
expect(stderr.string).to match(/DEBUG block-debug-message/)
|
165
|
+
expect(stderr.string).to match(/INFO block-info-message/)
|
166
|
+
expect(stderr.string).to match(/WARN block-warn-message/)
|
167
|
+
expect(stderr.string).to match(/ERROR block-error-message/)
|
168
|
+
expect(stderr.string).to match(/FATAL block-fatal-message/)
|
169
|
+
|
170
|
+
expect(stderr.string).to match(/DEBUG param-debug-message/)
|
171
|
+
expect(stderr.string).to match(/INFO param-info-message/)
|
172
|
+
expect(stderr.string).to match(/WARN param-warn-message/)
|
173
|
+
expect(stderr.string).to match(/ERROR param-error-message/)
|
174
|
+
expect(stderr.string).to match(/FATAL param-fatal-message/)
|
175
|
+
|
176
|
+
end
|
177
|
+
|
178
|
+
it 'should return the log file' do
|
179
|
+
expect(described_class.instance.log_file).to eq(scratch_dir + '.buildpack.log')
|
180
|
+
end
|
181
|
+
|
182
|
+
context do
|
183
|
+
|
184
|
+
before do
|
185
|
+
allow_any_instance_of(BuildpackSupport::ConfigurationUtils).to receive(:load).with('logging')
|
186
|
+
.and_return('default_log_level' => 'DEBUG')
|
187
|
+
described_class.instance.setup scratch_dir
|
188
|
+
end
|
189
|
+
|
190
|
+
it 'should log all levels to console when default_log_level set to DEBUG in configuration file' do
|
191
|
+
trigger
|
192
|
+
|
193
|
+
expect(stderr.string).to match(/DEBUG block-debug-message/)
|
194
|
+
expect(stderr.string).to match(/INFO block-info-message/)
|
195
|
+
expect(stderr.string).to match(/WARN block-warn-message/)
|
196
|
+
expect(stderr.string).to match(/ERROR block-error-message/)
|
197
|
+
expect(stderr.string).to match(/FATAL block-fatal-message/)
|
198
|
+
|
199
|
+
expect(stderr.string).to match(/DEBUG param-debug-message/)
|
200
|
+
expect(stderr.string).to match(/INFO param-info-message/)
|
201
|
+
expect(stderr.string).to match(/WARN param-warn-message/)
|
202
|
+
expect(stderr.string).to match(/ERROR param-error-message/)
|
203
|
+
expect(stderr.string).to match(/FATAL param-fatal-message/)
|
204
|
+
end
|
205
|
+
end
|
206
|
+
|
207
|
+
context do
|
208
|
+
|
209
|
+
before do
|
210
|
+
allow_any_instance_of(BuildpackSupport::ConfigurationUtils).to receive(:load).with('logging').and_return({})
|
211
|
+
described_class.instance.setup scratch_dir
|
212
|
+
end
|
213
|
+
|
214
|
+
it 'should log all levels above INFO to console when no configuration has been set' do
|
215
|
+
trigger
|
216
|
+
|
217
|
+
expect(stderr.string).not_to match(/DEBUG block-debug-message/)
|
218
|
+
expect(stderr.string).to match(/INFO block-info-message/)
|
219
|
+
expect(stderr.string).to match(/WARN block-warn-message/)
|
220
|
+
expect(stderr.string).to match(/ERROR block-error-message/)
|
221
|
+
expect(stderr.string).to match(/FATAL block-fatal-message/)
|
222
|
+
|
223
|
+
expect(stderr.string).not_to match(/DEBUG param-debug-message/)
|
224
|
+
expect(stderr.string).to match(/INFO param-info-message/)
|
225
|
+
expect(stderr.string).to match(/WARN param-warn-message/)
|
226
|
+
expect(stderr.string).to match(/ERROR param-error-message/)
|
227
|
+
expect(stderr.string).to match(/FATAL param-fatal-message/)
|
228
|
+
end
|
229
|
+
end
|
230
|
+
|
231
|
+
context do
|
232
|
+
|
233
|
+
before do
|
234
|
+
described_class.instance.reset
|
235
|
+
end
|
236
|
+
|
237
|
+
it 'should raise an error if get_logger called and not yet initialized' do
|
238
|
+
expect { described_class.instance.get_logger String }
|
239
|
+
.to raise_error 'Attempted to get Logger for String before initialization'
|
240
|
+
end
|
241
|
+
|
242
|
+
it 'should raise an error if log_file called and not yet initialized' do
|
243
|
+
expect { described_class.instance.log_file }
|
244
|
+
.to raise_error 'Attempted to get log file before initialization'
|
245
|
+
end
|
246
|
+
end
|
247
|
+
|
248
|
+
def trigger
|
249
|
+
logger.debug { 'block-debug-message' }
|
250
|
+
logger.info { 'block-info-message' }
|
251
|
+
logger.warn { 'block-warn-message' }
|
252
|
+
logger.error { 'block-error-message' }
|
253
|
+
logger.fatal { 'block-fatal-message' }
|
254
|
+
|
255
|
+
logger.debug 'param-debug-message'
|
256
|
+
logger.info 'param-info-message'
|
257
|
+
logger.warn 'param-warn-message'
|
258
|
+
logger.error 'param-error-message'
|
259
|
+
logger.fatal 'param-fatal-message'
|
260
|
+
end
|
261
|
+
|
262
|
+
end
|
@@ -0,0 +1,42 @@
|
|
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/qualify_path'
|
18
|
+
|
19
|
+
describe 'qualify_path' do
|
20
|
+
|
21
|
+
let(:pathQualifier) { StubPathQualifierClass.new }
|
22
|
+
|
23
|
+
it 'should return a path relative to the provided path' do
|
24
|
+
foo = Pathname.new('/foo')
|
25
|
+
bar = Pathname.new('/bar/bam')
|
26
|
+
expect(pathQualifier.qualify_path(foo, bar)).to eq('$PWD/../../foo')
|
27
|
+
end
|
28
|
+
|
29
|
+
it 'should return a path relative to the droplet root' do
|
30
|
+
foo = Pathname.new('/droplet/foo')
|
31
|
+
expect(pathQualifier.qualify_path(foo)).to eq('$PWD/foo')
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
35
|
+
|
36
|
+
class StubPathQualifierClass
|
37
|
+
include BuildpackSupport::QualifyPath
|
38
|
+
|
39
|
+
def initialize
|
40
|
+
@droplet_root = Pathname.new('/droplet')
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,88 @@
|
|
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/test/console_helper'
|
19
|
+
require 'buildpack_support/test/scratch_helper'
|
20
|
+
require 'rake'
|
21
|
+
require 'rake/clean'
|
22
|
+
|
23
|
+
describe BuildpackSupport::Rake::BuildpackStageTask do
|
24
|
+
include_context 'console_helper'
|
25
|
+
include_context 'scratch_helper'
|
26
|
+
|
27
|
+
before { Rake::Task.clear }
|
28
|
+
|
29
|
+
let(:task) do
|
30
|
+
described_class.new do |t|
|
31
|
+
t.files = Dir['spec/fixtures/zip-contents/**/*']
|
32
|
+
t.package_name = 'test-package-name'
|
33
|
+
t.staging_dir = scratch_dir
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
it 'should raise an error if files is not specified' do
|
38
|
+
expect { described_class.new }.to raise_error('files must be configured')
|
39
|
+
end
|
40
|
+
|
41
|
+
it 'should raise an error if package_name is not specified' do
|
42
|
+
expect do
|
43
|
+
described_class.new do |t|
|
44
|
+
t.files = []
|
45
|
+
end
|
46
|
+
end.to raise_error('package_name must be configured')
|
47
|
+
end
|
48
|
+
|
49
|
+
it 'should raise an error if staging_dir is not specified' do
|
50
|
+
expect do
|
51
|
+
described_class.new do |t|
|
52
|
+
t.files = []
|
53
|
+
t.package_name = 'test-package-name'
|
54
|
+
end
|
55
|
+
end.to raise_error('staging_dir must be configured')
|
56
|
+
end
|
57
|
+
|
58
|
+
it 'should call block if provided' do
|
59
|
+
called = false
|
60
|
+
|
61
|
+
described_class.new do |t|
|
62
|
+
t.files = []
|
63
|
+
t.package_name = 'test-package-name'
|
64
|
+
t.staging_dir = ''
|
65
|
+
called = true
|
66
|
+
end
|
67
|
+
|
68
|
+
expect(called).to be
|
69
|
+
end
|
70
|
+
|
71
|
+
it 'should create staging_dir tasks for all files and no directories' do
|
72
|
+
task
|
73
|
+
|
74
|
+
expect(Rake::Task.task_defined?(scratch_dir + 'spec/fixtures/zip-contents/test-file')).to be
|
75
|
+
expect(Rake::Task.task_defined?(scratch_dir + 'spec/fixtures/zip-contents/test-directory')).not_to be
|
76
|
+
expect(Rake::Task.task_defined?(scratch_dir + 'spec/fixtures/zip-contents/test-directory/test-deep-file')).to be
|
77
|
+
end
|
78
|
+
|
79
|
+
it 'should copy files' do
|
80
|
+
task
|
81
|
+
|
82
|
+
target = scratch_dir + 'spec/fixtures/zip-contents/test-directory/test-deep-file'
|
83
|
+
Rake::Task[target].invoke
|
84
|
+
|
85
|
+
expect(target).to exist
|
86
|
+
end
|
87
|
+
|
88
|
+
end
|