From d5d0ee54bd19b926d36b20bc94c1a2a749f47dff Mon Sep 17 00:00:00 2001 From: David Alvarado Date: Mon, 10 Apr 2023 23:37:09 +0000 Subject: [PATCH] Add stack name to unknown buildpack error message * Helps in cases where the buildpack exists for one stack but not another --- .../buildpack_lifecycle_data_validator.rb | 6 +++++- .../buildpack_lifecycle_data_validator_spec.rb | 15 ++++++++++++++- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/lib/cloud_controller/diego/lifecycles/buildpack_lifecycle_data_validator.rb b/lib/cloud_controller/diego/lifecycles/buildpack_lifecycle_data_validator.rb index c679a5b96c9..08bed855085 100644 --- a/lib/cloud_controller/diego/lifecycles/buildpack_lifecycle_data_validator.rb +++ b/lib/cloud_controller/diego/lifecycles/buildpack_lifecycle_data_validator.rb @@ -15,7 +15,11 @@ def buildpacks_are_uri_or_nil next if buildpack_info.buildpack.nil? next if buildpack_info.buildpack_url - errors.add(:buildpack, %("#{buildpack_info.buildpack}" must be an existing admin buildpack or a valid git URI)) + if stack + errors.add(:buildpack, %("#{buildpack_info.buildpack}" for stack "#{stack.name}" must be an existing admin buildpack or a valid git URI)) + else + errors.add(:buildpack, %("#{buildpack_info.buildpack}" must be an existing admin buildpack or a valid git URI)) + end end end diff --git a/spec/unit/lib/cloud_controller/diego/lifecycles/buildpack_lifecycle_data_validator_spec.rb b/spec/unit/lib/cloud_controller/diego/lifecycles/buildpack_lifecycle_data_validator_spec.rb index 932c30344c9..c53312b1995 100644 --- a/spec/unit/lib/cloud_controller/diego/lifecycles/buildpack_lifecycle_data_validator_spec.rb +++ b/spec/unit/lib/cloud_controller/diego/lifecycles/buildpack_lifecycle_data_validator_spec.rb @@ -19,6 +19,18 @@ module VCAP::CloudController end end + context 'when stack is nil and buildpack is nonexistant' do + let(:stack) { nil } + let(:buildpack_name_or_url) { 'nonexistant_buildpack' } + let(:buildpack) { nil } + + it 'is not valid' do + expect(validator).not_to be_valid + expect(validator.errors_on(:stack)).to include('must be an existing stack') + expect(validator.errors_on(:buildpack)).to include('"nonexistant_buildpack" must be an existing admin buildpack or a valid git URI') + end + end + context 'when given a buildpack url' do let(:buildpack_name_or_url) { 'http://yeah.com' } let(:buildpack) { nil } @@ -63,10 +75,11 @@ module VCAP::CloudController context 'when given an invalid BuildpackInfo' do let(:buildpack_infos) { [buildpack_info, BuildpackInfo.new('invalid-bp', nil)] } + let(:stack) { Stack.make(name: 'existing_stack') } it 'includes an error for the invalid buildpack' do expect(validator).not_to be_valid - expect(validator.errors[:buildpack]).to include('"invalid-bp" must be an existing admin buildpack or a valid git URI') + expect(validator.errors[:buildpack]).to include('"invalid-bp" for stack "existing_stack" must be an existing admin buildpack or a valid git URI') end end end