Skip to content

Commit f478d6b

Browse files
committed
fix: Validate presence package configuration
1 parent f6b94cb commit f478d6b

File tree

3 files changed

+25
-2
lines changed

3 files changed

+25
-2
lines changed

lib/appmap/config.rb

+3-2
Original file line numberDiff line numberDiff line change
@@ -176,8 +176,8 @@ def method_hook(cls, method_names, labels)
176176
package_hooks('actionpack',
177177
[
178178
method_hook('ActionDispatch::Request::Session', %i[[] dig values fetch], %w[http.session.read]),
179-
method_hook('ActionDispatch::Request::Session', %i[destroy[]= clear update delete merge], %w[http.session.write]),
180-
method_hook('ActionDispatch::Cookies::CookieJar', %i[[]= clear update delete recycle], %w[http.session.read]),
179+
method_hook('ActionDispatch::Request::Session', %i[destroy []= clear update delete merge], %w[http.session.write]),
180+
method_hook('ActionDispatch::Cookies::CookieJar', %i[[] fetch], %w[http.session.read]),
181181
method_hook('ActionDispatch::Cookies::CookieJar', %i[[]= clear update delete recycle], %w[http.session.write]),
182182
method_hook('ActionDispatch::Cookies::EncryptedCookieJar', %i[[]= clear update delete recycle], %w[http.cookie crypto.encrypt])
183183
],
@@ -360,6 +360,7 @@ def load(config_data)
360360
gem = package['gem']
361361
path = package['path']
362362
raise %q(AppMap config 'package' element should specify 'gem' or 'path', not both) if gem && path
363+
raise %q(AppMap config 'package' element should specify 'gem' or 'path') unless gem || path
363364

364365
if gem
365366
shallow = package['shallow']
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
name: name
2+
packages:
3+
- dogs: are friendly

test/agent_setup_validate_test.rb

+19
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ class AgentSetupValidateTest < Minitest::Test
66
NON_EXISTING_CONFIG_FILENAME = '123.yml'
77
INVALID_YAML_CONFIG_FILENAME = 'spec/fixtures/config/invalid_yaml_config.yml'
88
INVALID_CONFIG_FILENAME = 'spec/fixtures/config/invalid_config.yml'
9+
MISSING_PATH_OR_GEM_CONFIG_FILENAME = 'spec/fixtures/config/missing_path_or_gem.yml'
910

1011
def test_init_when_config_exists
1112
output = `./exe/appmap-agent-validate`
@@ -72,4 +73,22 @@ def test_init_with_invalid_data_config
7273
])
7374
assert_equal expected, output.strip
7475
end
76+
77+
def test_init_with_missing_package_key
78+
output = `./exe/appmap-agent-validate -c #{MISSING_PATH_OR_GEM_CONFIG_FILENAME}`
79+
assert_equal 0, $CHILD_STATUS.exitstatus
80+
expected = JSON.pretty_generate([
81+
{
82+
level: :error,
83+
message: 'AppMap auto-configuration is currently not available for non Rails projects'
84+
},
85+
{
86+
level: :error,
87+
filename: MISSING_PATH_OR_GEM_CONFIG_FILENAME,
88+
message: "AppMap configuration #{MISSING_PATH_OR_GEM_CONFIG_FILENAME} could not be loaded",
89+
detailed_message: "AppMap config 'package' element should specify 'gem' or 'path'"
90+
}
91+
])
92+
assert_equal expected, output.strip
93+
end
7594
end

0 commit comments

Comments
 (0)