-
Notifications
You must be signed in to change notification settings - Fork 369
Expand file tree
/
Copy pathbuildpack_upload_spec.rb
More file actions
54 lines (46 loc) · 2.1 KB
/
buildpack_upload_spec.rb
File metadata and controls
54 lines (46 loc) · 2.1 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
require 'spec_helper'
require 'actions/buildpack_upload'
module VCAP::CloudController
RSpec.describe BuildpackUpload do
let(:user) { User.make }
let(:user_email) { 'user@example.com' }
let(:user_name) { 'user-name' }
let(:user_audit_info) { UserAuditInfo.new(user_guid: user.guid, user_email: user_email, user_name: user_name) }
subject(:buildpack_upload) { BuildpackUpload.new(user_audit_info) }
describe '#upload_async' do
let!(:buildpack) { VCAP::CloudController::Buildpack.create_from_hash({ name: 'upload_binary_buildpack', stack: nil, position: 0 }) }
let(:message) { BuildpackUploadMessage.new({ 'bits_path' => '/tmp/path', 'bits_name' => 'buildpack.zip' }, VCAP::CloudController::Lifecycles::BUILDPACK) }
let(:config) { Config.new({ name: 'local', index: '1' }) }
before do
allow(Buildpacks::StackNameExtractor).to receive(:extract_from_file).and_return('the-stack')
end
context 'when the buildpack and message are valid' do
it 'enqueues and returns an upload job' do
returned_job = nil
expect do
returned_job = buildpack_upload.upload_async(message:, buildpack:, config:)
end.to change(Delayed::Job, :count).by(1)
job = Delayed::Job.last
expect(returned_job.delayed_job_guid).to eq(job.guid)
expect(job.queue).to eq('cc-local-1')
expect(job.handler).to include(buildpack.guid)
expect(job.handler).to include('BuildpackBits')
end
it 'leaves the state as AWAITING_UPLOAD' do
buildpack_upload.upload_async(message:, buildpack:, config:)
expect(Buildpack.find(guid: buildpack.guid).state).to eq(Buildpack::CREATED_STATE)
end
it 'uses the right path and filename' do
expect(Jobs::V3::BuildpackBits).to receive(:new).with(
buildpack.guid,
'/tmp/path',
'buildpack.zip',
user_audit_info,
message.audit_hash
).and_call_original
buildpack_upload.upload_async(message:, buildpack:, config:)
end
end
end
end
end