Skip to content

Commit b7f8344

Browse files
committed
Add test for cc uploader drain script rendering
1 parent 3c4e87b commit b7f8344

File tree

1 file changed

+54
-0
lines changed

1 file changed

+54
-0
lines changed
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
# frozen_string_literal: true
2+
3+
require 'rspec'
4+
require 'bosh/template/test'
5+
require 'yaml'
6+
require 'json'
7+
8+
describe 'cc_uploader drain script rendering' do
9+
let(:release_path) { File.join(File.dirname(__FILE__), '../..') }
10+
let(:release) { Bosh::Template::Test::ReleaseDir.new(release_path) }
11+
let(:job) { release.job('cc_uploader') }
12+
let(:template) { job.template('bin/drain') }
13+
14+
context 'when capi.cc_uploader.cc_uploader_drain_timeout_in_minutes is provided' do
15+
let(:properties) do
16+
{
17+
'capi' => {
18+
'cc_uploader' => {
19+
'cc_uploader_drain_timeout_in_minutes' => '10m'
20+
}
21+
}
22+
}
23+
end
24+
25+
it 'renders the drain script with correct timeout' do
26+
rendered = template.render(properties)
27+
expect(rendered).to include('TIMEOUT_MINUTES="10m"')
28+
expect(rendered).to include('DRAIN_TIMEOUT=$(( TIMEOUT_MINUTES * 60 ))')
29+
end
30+
end
31+
32+
context 'when capi.cc_uploader.cc_uploader_drain_timeout_in_minutes is not provided' do
33+
it 'defaults to 15 minutes' do
34+
rendered = template.render({})
35+
expect(rendered).to include('TIMEOUT_MINUTES="15m"')
36+
end
37+
end
38+
39+
it 'writes logs to the expected log file' do
40+
rendered = template.render({})
41+
expect(rendered).to include('LOG_FILE="/var/vcap/sys/log/cc_uploader/drain.log"')
42+
end
43+
44+
it 'uses the correct PID file location' do
45+
rendered = template.render({})
46+
expect(rendered).to include('PID_FILE="/var/vcap/sys/run/bpm/cc_uploader/cc_uploader.pid"')
47+
end
48+
49+
it 'safely attempts to terminate the cc_uploader process' do
50+
rendered = template.render({})
51+
expect(rendered).to include('kill -TERM "$(cat "$PID_FILE")"')
52+
expect(rendered).to include('kill -0 "$(cat "$PID_FILE")"')
53+
end
54+
end

0 commit comments

Comments
 (0)