Repository navigation
Expand file tree
/
Copy pathbuildpack_version_spec.rb
More file actions
123 lines (92 loc) · 4.81 KB
/
Copy pathbuildpack_version_spec.rb
File metadata and controls
123 lines (92 loc) · 4.81 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
# Encoding: utf-8
# Cloud Foundry Java Buildpack
# Copyright 2013 the original author or authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
require 'spec_helper'
require 'application_helper'
require 'logging_helper'
require 'java_buildpack/buildpack_version'
require 'pathname'
describe JavaBuildpack::BuildpackVersion do
include_context 'application_helper'
include_context 'logging_helper'
let(:buildpack_version) { described_class.new }
before do |example|
configuration = example.metadata[:configuration] || {}
allow(JavaBuildpack::Util::ConfigurationUtils).to receive(:load).with('version', true).and_return(configuration)
end
it 'should create offline version string from config/version.yml',
log_level: 'DEBUG',
configuration: { 'hash' => 'test-hash', 'offline' => true,
'remote' => 'test-remote', 'version' => 'test-version' } do
expect(buildpack_version.to_s).to match(/test-version (offline) | test-remote#test-hash/)
expect(buildpack_version.to_s(false)).to match(/test-version-offline-test-remote#test-hash/)
expect(stderr.string).to match(/test-version (offline) | test-remote#test-hash/)
end
it 'should create online version string from config/version.yml',
log_level: 'DEBUG',
configuration: { 'hash' => 'test-hash', 'offline' => false,
'remote' => 'test-remote', 'version' => 'test-version' } do
expect(buildpack_version.to_s).to match(/test-version | test-remote#test-hash/)
expect(buildpack_version.to_s(false)).to match(/test-version-test-remote#test-hash/)
expect(stderr.string).to match(/test-version | test-remote#test-hash/)
end
it 'should create version string from git repository if no config/version.yml exists',
log_level: 'DEBUG' do
git_dir = Pathname.new('.git').expand_path
allow_any_instance_of(described_class).to receive(:system)
.with('which git > /dev/null')
.and_return(true)
allow_any_instance_of(described_class).to receive(:`)
.with("git --git-dir=#{git_dir} rev-parse --short HEAD")
.and_return('test-hash')
allow_any_instance_of(described_class).to receive(:`)
.with("git --git-dir=#{git_dir} config --get remote.origin.url")
.and_return('test-remote')
expect(buildpack_version.to_s).to match(/test-remote#test-hash/)
expect(buildpack_version.to_s(false)).to match(/test-remote#test-hash/)
expect(stderr.string).to match(/test-remote#test-hash/)
end
it 'should create unknown version string if no config/version.yml exists and it is not in a git repository',
log_level: 'DEBUG' do
allow_any_instance_of(described_class).to receive(:system).with('which git > /dev/null').and_return(false)
expect(buildpack_version.to_s).to match(/unknown/)
expect(buildpack_version.to_s(false)).to match(/unknown/)
expect(stderr.string).to match(/unknown/)
end
it 'should create a has from the values',
configuration: { 'hash' => 'test-hash', 'offline' => true,
'remote' => 'test-remote', 'version' => 'test-version' } do |example|
allow_any_instance_of(described_class).to receive(:system).with('which git > /dev/null').and_return(false)
expect(buildpack_version.to_hash).to eq(example.metadata[:configuration])
end
it 'should exclude non-populated values from the hash' do
allow_any_instance_of(described_class).to receive(:system).with('which git > /dev/null').and_return(false)
expect(buildpack_version.to_hash).to eq({})
end
context do
let(:environment) { { 'OFFLINE' => 'true' } }
it 'should pick up offline from the environment' do
allow_any_instance_of(described_class).to receive(:system).with('which git > /dev/null').and_return(false)
expect(buildpack_version.offline).to be
end
end
context do
let(:environment) { { 'VERSION' => 'test-version' } }
it 'should pick up version from the environment' do
allow_any_instance_of(described_class).to receive(:system).with('which git > /dev/null').and_return(false)
expect(buildpack_version.version).to match(/test-version/)
end
end
end