Skip to content

Commit 36bb71b

Browse files
committed
enhanced error handling and test cases
* raising RuntimeError if `APPD_CONF_DIR` is provided but directory does not exist * added version directory `stub-app-dynamics-agent.zip` * test if config file gets succesfully copied * test if error is raised when provided directory does not exist
1 parent d170a63 commit 36bb71b

File tree

4 files changed

+19
-2
lines changed

4 files changed

+19
-2
lines changed

lib/java_buildpack/framework/app_dynamics_agent.rb

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -201,10 +201,13 @@ def override_default_config_remote
201201
def override_default_config_local
202202
return unless @application.environment['APPD_CONF_DIR']
203203

204-
app_conf_dir = @application.environment['APPD_CONF_DIR']
204+
app_conf_dir = @application.root + @application.environment['APPD_CONF_DIR']
205+
206+
raise "AppDynamics configuration source dir #{app_conf_dir} does not exist" unless Dir.exist?(app_conf_dir)
207+
205208
@logger.info { "Copy override configuration files from #{app_conf_dir}" }
206209
CONFIG_FILES.each do |conf_file|
207-
conf_file_path = @application.root + app_conf_dir + conf_file
210+
conf_file_path = app_conf_dir + conf_file
208211

209212
next unless File.file?(conf_file_path)
210213

spec/fixtures/framework_app_dynamics_agent/BOOT-INF/classes/appdynamics/conf/app-agent-config.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
<!-- sourced by APPD_CONF_DIR -->
12
<app-agent-configuration>
23
<configuration-properties>
34
<property name="agent-overwrite" value="false"/>
330 Bytes
Binary file not shown.

spec/java_buildpack/framework/app_dynamics_agent_spec.rb

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,19 @@
199199
cache_fixture: 'stub-app-dynamics-agent.zip' do
200200

201201
component.compile
202+
expect(File.read(sandbox + "ver21.1.0.31582/conf/app-agent-config.xml")).to include "sourced by APPD_CONF_DIR"
203+
end
204+
end
205+
206+
context do
207+
208+
let(:environment) { { 'APPD_CONF_DIR' => 'BOOT-INF/classes/appdynamics/conf-false' } }
209+
210+
it 'sets APPD_CONF_DIR env var to copy config files from incorrect app dir',
211+
app_fixture: 'framework_app_dynamics_agent',
212+
cache_fixture: 'stub-app-dynamics-agent.zip' do
213+
214+
expect{component.compile}.to raise_error(RuntimeError, /AppDynamics configuration source dir/)
202215
end
203216
end
204217
end

0 commit comments

Comments
 (0)