/
configuration_spec.rb
259 lines (224 loc) · 10.1 KB
/
configuration_spec.rb
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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
require 'spec_helper'
describe Coveralls::Configuration do
before do
ENV.stub(:[]).and_return(nil)
end
describe '.configuration' do
it "returns a hash with the default keys" do
config = Coveralls::Configuration.configuration
config.should be_a(Hash)
config.keys.should include(:environment)
config.keys.should include(:git)
end
context 'yaml_config' do
let(:repo_token) { SecureRandom.hex(4) }
let(:repo_secret_token) { SecureRandom.hex(4) }
let(:yaml_config) {
{
'repo_token' => repo_token,
'repo_secret_token' => repo_secret_token
}
}
before do
Coveralls::Configuration.stub(:yaml_config).and_return(yaml_config)
end
it 'sets the Yaml config and associated variables if present' do
config = Coveralls::Configuration.configuration
config[:configuration].should eq(yaml_config)
config[:repo_token].should eq(repo_token)
end
it 'uses the repo_secret_token if the repo_token is not set' do
yaml_config.delete('repo_token')
config = Coveralls::Configuration.configuration
config[:configuration].should eq(yaml_config)
config[:repo_token].should eq(repo_secret_token)
end
end
context 'repo_token in environment' do
let(:repo_token) { SecureRandom.hex(4) }
before do
ENV.stub(:[]).with('COVERALLS_REPO_TOKEN').and_return(repo_token)
end
it 'pulls the repo token from the environment if set' do
config = Coveralls::Configuration.configuration
config[:repo_token].should eq(repo_token)
end
end
context 'Services' do
context 'on Travis' do
before do
ENV.stub(:[]).with('TRAVIS').and_return('1')
end
it 'should set service parameters for this service and no other' do
Coveralls::Configuration.should_receive(:set_service_params_for_travis).with(anything, anything)
Coveralls::Configuration.should_not_receive(:set_service_params_for_circleci)
Coveralls::Configuration.should_not_receive(:set_service_params_for_semaphore)
Coveralls::Configuration.should_not_receive(:set_service_params_for_jenkins)
Coveralls::Configuration.should_not_receive(:set_service_params_for_coveralls_local)
Coveralls::Configuration.should_not_receive(:set_service_params_for_generic_ci)
Coveralls::Configuration.configuration
end
end
context 'on CircleCI' do
before do
ENV.stub(:[]).with('CIRCLECI').and_return('1')
end
it 'should set service parameters for this service and no other' do
Coveralls::Configuration.should_not_receive(:set_service_params_for_travis)
Coveralls::Configuration.should_receive(:set_service_params_for_circleci)
Coveralls::Configuration.should_not_receive(:set_service_params_for_semaphore)
Coveralls::Configuration.should_not_receive(:set_service_params_for_jenkins)
Coveralls::Configuration.should_not_receive(:set_service_params_for_coveralls_local)
Coveralls::Configuration.should_not_receive(:set_service_params_for_generic_ci)
Coveralls::Configuration.configuration
end
end
context 'on Semaphore' do
before do
ENV.stub(:[]).with('SEMAPHORE').and_return('1')
end
it 'should set service parameters for this service and no other' do
Coveralls::Configuration.should_not_receive(:set_service_params_for_travis)
Coveralls::Configuration.should_not_receive(:set_service_params_for_circleci)
Coveralls::Configuration.should_receive(:set_service_params_for_semaphore)
Coveralls::Configuration.should_not_receive(:set_service_params_for_jenkins)
Coveralls::Configuration.should_not_receive(:set_service_params_for_coveralls_local)
Coveralls::Configuration.should_not_receive(:set_service_params_for_generic_ci)
Coveralls::Configuration.configuration
end
end
context 'when using Jenkins' do
before do
ENV.stub(:[]).with('JENKINS_URL').and_return('1')
end
it 'should set service parameters for this service and no other' do
Coveralls::Configuration.should_not_receive(:set_service_params_for_travis)
Coveralls::Configuration.should_not_receive(:set_service_params_for_circleci)
Coveralls::Configuration.should_not_receive(:set_service_params_for_semaphore)
Coveralls::Configuration.should_receive(:set_service_params_for_jenkins)
Coveralls::Configuration.should_not_receive(:set_service_params_for_coveralls_local)
Coveralls::Configuration.should_not_receive(:set_service_params_for_generic_ci)
Coveralls::Configuration.configuration
end
end
context 'when running Coveralls locally' do
before do
ENV.stub(:[]).with('COVERALLS_RUN_LOCALLY').and_return('1')
end
it 'should set service parameters for this service and no other' do
Coveralls::Configuration.should_not_receive(:set_service_params_for_travis)
Coveralls::Configuration.should_not_receive(:set_service_params_for_circleci)
Coveralls::Configuration.should_not_receive(:set_service_params_for_semaphore)
Coveralls::Configuration.should_not_receive(:set_service_params_for_jenkins)
Coveralls::Configuration.should_receive(:set_service_params_for_coveralls_local)
Coveralls::Configuration.should_not_receive(:set_service_params_for_generic_ci)
Coveralls::Configuration.configuration
end
end
context 'for generic CI' do
before do
ENV.stub(:[]).with('CI_NAME').and_return('1')
end
it 'should set service parameters for this service and no other' do
Coveralls::Configuration.should_not_receive(:set_service_params_for_travis)
Coveralls::Configuration.should_not_receive(:set_service_params_for_circleci)
Coveralls::Configuration.should_not_receive(:set_service_params_for_semaphore)
Coveralls::Configuration.should_not_receive(:set_service_params_for_jenkins)
Coveralls::Configuration.should_not_receive(:set_service_params_for_coveralls_local)
Coveralls::Configuration.should_receive(:set_service_params_for_generic_ci)
Coveralls::Configuration.configuration
end
end
end
end
describe '.set_service_params_for_travis' do
let(:travis_job_id) { SecureRandom.hex(4) }
before do
ENV.stub(:[]).with('TRAVIS_JOB_ID').and_return(travis_job_id)
end
it 'should set the service_job_id' do
config = {}
Coveralls::Configuration.set_service_params_for_travis(config, nil)
config[:service_job_id].should eq(travis_job_id)
end
it 'should set the service_name to travis-ci by default' do
config = {}
Coveralls::Configuration.set_service_params_for_travis(config, nil)
config[:service_name].should eq('travis-ci')
end
it 'should set the service_name to a value if one is passed in' do
config = {}
service_name = SecureRandom.hex(4)
Coveralls::Configuration.set_service_params_for_travis(config, service_name)
config[:service_name].should eq(service_name)
end
end
describe '.set_service_params_for_circleci' do
let(:circle_build_num) { SecureRandom.hex(4) }
before do
ENV.stub(:[]).with('CIRCLE_BUILD_NUM').and_return(circle_build_num)
end
it 'should set the expected parameters' do
config = {}
Coveralls::Configuration.set_service_params_for_circleci(config)
config[:service_name].should eq('circleci')
config[:service_number].should eq(circle_build_num)
end
end
describe '.set_service_params_for_semaphore' do
let(:semaphore_build_num) { SecureRandom.hex(4) }
before do
ENV.stub(:[]).with('SEMAPHORE_BUILD_NUMBER').and_return(semaphore_build_num)
end
it 'should set the expected parameters' do
config = {}
Coveralls::Configuration.set_service_params_for_semaphore(config)
config[:service_name].should eq('semaphore')
config[:service_number].should eq(semaphore_build_num)
end
end
describe '.set_service_params_for_jenkins' do
let(:build_num) { SecureRandom.hex(4) }
before do
ENV.stub(:[]).with('BUILD_NUMBER').and_return(build_num)
end
it 'should set the expected parameters' do
config = {}
Coveralls::Configuration.set_service_params_for_jenkins(config)
config[:service_name].should eq('jenkins')
config[:service_number].should eq(build_num)
end
end
describe '.set_service_params_for_coveralls_local' do
it 'should set the expected parameters' do
config = {}
Coveralls::Configuration.set_service_params_for_coveralls_local(config)
config[:service_name].should eq('coveralls-ruby')
config[:service_job_id].should be_nil
config[:service_event_type].should eq('manual')
end
end
describe '.set_service_params_for_generic_ci' do
let(:service_name) { SecureRandom.hex(4) }
let(:service_number) { SecureRandom.hex(4) }
let(:service_build_url) { SecureRandom.hex(4) }
let(:service_branch) { SecureRandom.hex(4) }
let(:service_pull_request) { SecureRandom.hex(4) }
before do
ENV.stub(:[]).with('CI_NAME').and_return(service_name)
ENV.stub(:[]).with('CI_BUILD_NUMBER').and_return(service_number)
ENV.stub(:[]).with('CI_BUILD_URL').and_return(service_build_url)
ENV.stub(:[]).with('CI_BRANCH').and_return(service_branch)
ENV.stub(:[]).with('CI_PULL_REQUEST').and_return(service_pull_request)
end
it 'should set the expected parameters' do
config = {}
Coveralls::Configuration.set_service_params_for_generic_ci(config)
config[:service_name].should eq(service_name)
config[:service_number].should eq(service_number)
config[:service_build_url].should eq(service_build_url)
config[:service_branch].should eq(service_branch)
config[:service_pull_request].should eq(service_pull_request)
end
end
end