Skip to content

Commit

Permalink
space manifests will error when setting both docker and buildpacks
Browse files Browse the repository at this point in the history
[Finishes #163660668]
  • Loading branch information
XenoPhex committed Feb 6, 2019
1 parent 70ecdb6 commit 298dee8
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 0 deletions.
7 changes: 7 additions & 0 deletions app/messages/app_manifest_message.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ def self.underscore_keys(hash)
validate :validate_app_update_message!
validate :validate_buildpack_and_buildpacks_combination!
validate :validate_docker_enabled!
validate :validate_docker_buildpacks_combination!
validate :validate_service_bindings_message!, if: proc { |record| record.requested?(:services) }
validate :validate_env_update_message!, if: proc { |record| record.requested?(:env) }
validate :validate_manifest_singular_buildpack_message!, if: proc { |record| record.requested?(:buildpack) }
Expand Down Expand Up @@ -369,6 +370,12 @@ def validate_docker_enabled!
errors.add(:base, e.message)
end

def validate_docker_buildpacks_combination!
if requested?(:docker) && (requested?(:buildpack) || requested?(:buildpacks))
errors.add(:base, 'Cannot specify both buildpack(s) and docker keys')
end
end

def add_process_error!(error_message, type)
errors.add(:base, %(Process "#{type}": #{error_message}))
end
Expand Down
37 changes: 37 additions & 0 deletions spec/unit/messages/app_manifest_message_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -577,6 +577,43 @@ module VCAP::CloudController
end
end

describe 'combination errors' do
context 'when docker and buildpack is provided' do
before do
FeatureFlag.make(name: 'diego_docker', enabled: true, error_message: nil)
end

let(:buildpack) { Buildpack.make }
let(:params) { { buildpack: buildpack.name, docker: { image: 'my/image' } } }

it 'is not valid' do
message = AppManifestMessage.create_from_yml(params)

expect(message).not_to be_valid
expect(message.errors.count).to eq(1)
expect(message.errors.full_messages).to include('Cannot specify both buildpack(s) and docker keys')
end
end

context 'when docker and buildpacks is provided' do
before do
FeatureFlag.make(name: 'diego_docker', enabled: true, error_message: nil)
end

let(:buildpack) { Buildpack.make }
let(:buildpack2) { Buildpack.make }
let(:params) { { buildpacks: [buildpack.name, buildpack2.name], docker: { image: 'my/image' } } }

it 'is not valid' do
message = AppManifestMessage.create_from_yml(params)

expect(message).not_to be_valid
expect(message.errors.count).to eq(1)
expect(message.errors.full_messages).to include('Cannot specify both buildpack(s) and docker keys')
end
end
end

context 'when there are multiple errors' do
let(:params) do
{
Expand Down

0 comments on commit 298dee8

Please sign in to comment.