appmap 0.35.0 → 0.37.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.dockerignore +1 -1
- data/.gitignore +2 -1
- data/.rubocop.yml +10 -0
- data/CHANGELOG.md +22 -0
- data/README.md +11 -8
- data/Rakefile +3 -2
- data/appmap.gemspec +2 -1
- data/appmap.yml +1 -7
- data/lib/appmap.rb +2 -2
- data/lib/appmap/class_map.rb +20 -6
- data/lib/appmap/config.rb +53 -23
- data/lib/appmap/event.rb +21 -6
- data/lib/appmap/hook.rb +1 -1
- data/lib/appmap/rails/request_handler.rb +8 -1
- data/lib/appmap/railtie.rb +1 -1
- data/lib/appmap/rspec.rb +1 -1
- data/lib/appmap/version.rb +2 -2
- data/spec/abstract_controller4_base_spec.rb +27 -28
- data/spec/abstract_controller_base_spec.rb +43 -39
- data/spec/class_map_spec.rb +36 -0
- data/spec/fixtures/hook/exception_method.rb +44 -0
- data/spec/fixtures/hook/instance_method.rb +4 -0
- data/spec/fixtures/{rails_users_app → rails5_users_app}/.dockerignore +0 -0
- data/spec/fixtures/{rails_users_app → rails5_users_app}/.gitignore +0 -0
- data/spec/fixtures/{rails_users_app → rails5_users_app}/.rspec +0 -0
- data/{.ruby-version → spec/fixtures/rails5_users_app/.ruby-version} +0 -0
- data/spec/fixtures/{rails_users_app → rails5_users_app}/Dockerfile +0 -0
- data/spec/fixtures/{rails_users_app → rails5_users_app}/Dockerfile.pg +0 -0
- data/spec/fixtures/rails5_users_app/Gemfile +51 -0
- data/spec/fixtures/{rails_users_app → rails5_users_app}/Rakefile +0 -0
- data/spec/fixtures/{rails_users_app → rails5_users_app}/app/controllers/api/users_controller.rb +0 -0
- data/spec/fixtures/{rails_users_app → rails5_users_app}/app/controllers/application_controller.rb +0 -0
- data/spec/fixtures/{rails_users_app → rails5_users_app}/app/controllers/concerns/.keep +0 -0
- data/spec/fixtures/{rails_users_app → rails5_users_app}/app/controllers/health_controller.rb +0 -0
- data/spec/fixtures/{rails_users_app → rails5_users_app}/app/controllers/users_controller.rb +0 -0
- data/spec/fixtures/{rails_users_app → rails5_users_app}/app/models/activerecord/user.rb +0 -0
- data/spec/fixtures/{rails_users_app → rails5_users_app}/app/models/concerns/.keep +0 -0
- data/spec/fixtures/{rails_users_app → rails5_users_app}/app/models/sequel/user.rb +0 -0
- data/spec/fixtures/{rails_users_app → rails5_users_app}/app/views/layouts/application.html.haml +0 -0
- data/spec/fixtures/{rails_users_app → rails5_users_app}/app/views/users/index.html.haml +0 -0
- data/spec/fixtures/{rails_users_app → rails5_users_app}/appmap.yml +1 -1
- data/spec/fixtures/{rails_users_app → rails5_users_app}/bin/appmap +0 -0
- data/spec/fixtures/{rails_users_app → rails5_users_app}/bin/byebug +0 -0
- data/spec/fixtures/{rails_users_app → rails5_users_app}/bin/gli +0 -0
- data/spec/fixtures/{rails_users_app → rails5_users_app}/bin/htmldiff +0 -0
- data/spec/fixtures/{rails_users_app → rails5_users_app}/bin/ldiff +0 -0
- data/spec/fixtures/{rails_users_app → rails5_users_app}/bin/nokogiri +0 -0
- data/spec/fixtures/{rails_users_app → rails5_users_app}/bin/rackup +0 -0
- data/spec/fixtures/{rails_users_app → rails5_users_app}/bin/rails +0 -0
- data/spec/fixtures/{rails_users_app → rails5_users_app}/bin/rake +0 -0
- data/spec/fixtures/{rails_users_app → rails5_users_app}/bin/rspec +0 -0
- data/spec/fixtures/{rails_users_app → rails5_users_app}/bin/ruby-parse +0 -0
- data/spec/fixtures/{rails_users_app → rails5_users_app}/bin/ruby-rewrite +0 -0
- data/spec/fixtures/{rails_users_app → rails5_users_app}/bin/sequel +0 -0
- data/spec/fixtures/{rails_users_app → rails5_users_app}/bin/setup +0 -0
- data/spec/fixtures/{rails_users_app → rails5_users_app}/bin/sprockets +0 -0
- data/spec/fixtures/{rails_users_app → rails5_users_app}/bin/thor +0 -0
- data/spec/fixtures/{rails_users_app → rails5_users_app}/bin/update +0 -0
- data/spec/fixtures/{rails_users_app → rails5_users_app}/config.ru +0 -0
- data/spec/fixtures/{rails_users_app → rails5_users_app}/config/application.rb +0 -0
- data/spec/fixtures/{rails_users_app → rails5_users_app}/config/boot.rb +0 -0
- data/spec/fixtures/{rails_users_app → rails5_users_app}/config/credentials.yml.enc +0 -0
- data/spec/fixtures/{rails_users_app → rails5_users_app}/config/database.yml +0 -0
- data/spec/fixtures/{rails_users_app → rails5_users_app}/config/environment.rb +0 -0
- data/spec/fixtures/{rails_users_app → rails5_users_app}/config/environments/development.rb +0 -0
- data/spec/fixtures/{rails_users_app → rails5_users_app}/config/environments/production.rb +0 -0
- data/spec/fixtures/{rails_users_app → rails5_users_app}/config/environments/test.rb +0 -0
- data/spec/fixtures/{rails_users_app → rails5_users_app}/config/initializers/application_controller_renderer.rb +0 -0
- data/spec/fixtures/{rails_users_app → rails5_users_app}/config/initializers/backtrace_silencers.rb +0 -0
- data/spec/fixtures/{rails_users_app → rails5_users_app}/config/initializers/cors.rb +0 -0
- data/spec/fixtures/{rails_users_app → rails5_users_app}/config/initializers/filter_parameter_logging.rb +0 -0
- data/spec/fixtures/{rails_users_app → rails5_users_app}/config/initializers/inflections.rb +0 -0
- data/spec/fixtures/{rails_users_app → rails5_users_app}/config/initializers/mime_types.rb +0 -0
- data/spec/fixtures/{rails_users_app → rails5_users_app}/config/initializers/record_button.rb +0 -0
- data/spec/fixtures/{rails_users_app → rails5_users_app}/config/initializers/wrap_parameters.rb +0 -0
- data/spec/fixtures/{rails_users_app → rails5_users_app}/config/locales/en.yml +0 -0
- data/spec/fixtures/{rails_users_app → rails5_users_app}/config/routes.rb +0 -0
- data/spec/fixtures/{rails_users_app → rails5_users_app}/create_app +0 -0
- data/spec/fixtures/{rails_users_app → rails5_users_app}/db/migrate/20190728211408_create_users.rb +0 -0
- data/spec/fixtures/{rails_users_app → rails5_users_app}/db/schema.rb +0 -0
- data/spec/fixtures/{rails_users_app → rails5_users_app}/docker-compose.yml +0 -0
- data/spec/fixtures/{rails_users_app → rails5_users_app}/features/api_users.feature +0 -0
- data/spec/fixtures/{rails_users_app → rails5_users_app}/features/support/env.rb +0 -0
- data/spec/fixtures/{rails_users_app → rails5_users_app}/features/support/hooks.rb +0 -0
- data/spec/fixtures/{rails_users_app → rails5_users_app}/features/support/steps.rb +0 -0
- data/spec/fixtures/{rails_users_app → rails5_users_app}/lib/tasks/.keep +0 -0
- data/spec/fixtures/{rails_users_app → rails5_users_app}/log/.keep +0 -0
- data/spec/fixtures/{rails_users_app → rails5_users_app}/public/robots.txt +0 -0
- data/spec/fixtures/{rails_users_app → rails5_users_app}/spec/controllers/users_controller_api_spec.rb +0 -0
- data/spec/fixtures/{rails_users_app → rails5_users_app}/spec/models/user_spec.rb +0 -0
- data/spec/fixtures/{rails_users_app → rails5_users_app}/spec/rails_helper.rb +0 -0
- data/spec/fixtures/{rails_users_app → rails5_users_app}/spec/spec_helper.rb +0 -0
- data/spec/fixtures/{rails_users_app → rails5_users_app}/users_app/.gitignore +0 -0
- data/spec/fixtures/rails6_users_app/.dockerignore +1 -0
- data/spec/fixtures/rails6_users_app/.gitignore +39 -0
- data/spec/fixtures/rails6_users_app/.rspec +1 -0
- data/spec/fixtures/{rails_users_app → rails6_users_app}/.ruby-version +0 -0
- data/spec/fixtures/rails6_users_app/Dockerfile +29 -0
- data/spec/fixtures/rails6_users_app/Dockerfile.pg +3 -0
- data/spec/fixtures/{rails_users_app → rails6_users_app}/Gemfile +0 -0
- data/spec/fixtures/rails6_users_app/Rakefile +6 -0
- data/spec/fixtures/rails6_users_app/app/controllers/api/users_controller.rb +27 -0
- data/spec/fixtures/rails6_users_app/app/controllers/application_controller.rb +2 -0
- data/spec/fixtures/rails6_users_app/app/controllers/concerns/.keep +0 -0
- data/spec/fixtures/rails6_users_app/app/controllers/health_controller.rb +5 -0
- data/spec/fixtures/rails6_users_app/app/controllers/users_controller.rb +5 -0
- data/spec/fixtures/rails6_users_app/app/models/activerecord/user.rb +18 -0
- data/spec/fixtures/rails6_users_app/app/models/concerns/.keep +0 -0
- data/spec/fixtures/rails6_users_app/app/models/sequel/user.rb +25 -0
- data/spec/fixtures/rails6_users_app/app/views/layouts/application.html.haml +7 -0
- data/spec/fixtures/rails6_users_app/app/views/users/index.html.haml +7 -0
- data/spec/fixtures/rails6_users_app/appmap.yml +3 -0
- data/spec/fixtures/rails6_users_app/bin/appmap +29 -0
- data/spec/fixtures/rails6_users_app/bin/byebug +29 -0
- data/spec/fixtures/rails6_users_app/bin/gli +29 -0
- data/spec/fixtures/rails6_users_app/bin/htmldiff +29 -0
- data/spec/fixtures/rails6_users_app/bin/ldiff +29 -0
- data/spec/fixtures/rails6_users_app/bin/nokogiri +29 -0
- data/spec/fixtures/rails6_users_app/bin/rackup +29 -0
- data/spec/fixtures/rails6_users_app/bin/rails +4 -0
- data/spec/fixtures/rails6_users_app/bin/rake +29 -0
- data/spec/fixtures/rails6_users_app/bin/rspec +29 -0
- data/spec/fixtures/rails6_users_app/bin/ruby-parse +29 -0
- data/spec/fixtures/rails6_users_app/bin/ruby-rewrite +29 -0
- data/spec/fixtures/rails6_users_app/bin/sequel +29 -0
- data/spec/fixtures/rails6_users_app/bin/setup +25 -0
- data/spec/fixtures/rails6_users_app/bin/sprockets +29 -0
- data/spec/fixtures/rails6_users_app/bin/thor +29 -0
- data/spec/fixtures/rails6_users_app/bin/update +25 -0
- data/spec/fixtures/rails6_users_app/config.ru +5 -0
- data/spec/fixtures/rails6_users_app/config/application.rb +51 -0
- data/spec/fixtures/rails6_users_app/config/boot.rb +3 -0
- data/spec/fixtures/rails6_users_app/config/credentials.yml.enc +1 -0
- data/spec/fixtures/rails6_users_app/config/database.yml +18 -0
- data/spec/fixtures/rails6_users_app/config/environment.rb +5 -0
- data/spec/fixtures/rails6_users_app/config/environments/development.rb +40 -0
- data/spec/fixtures/rails6_users_app/config/environments/production.rb +68 -0
- data/spec/fixtures/rails6_users_app/config/environments/test.rb +36 -0
- data/spec/fixtures/rails6_users_app/config/initializers/application_controller_renderer.rb +8 -0
- data/spec/fixtures/rails6_users_app/config/initializers/backtrace_silencers.rb +7 -0
- data/spec/fixtures/rails6_users_app/config/initializers/cors.rb +16 -0
- data/spec/fixtures/rails6_users_app/config/initializers/filter_parameter_logging.rb +4 -0
- data/spec/fixtures/rails6_users_app/config/initializers/inflections.rb +16 -0
- data/spec/fixtures/rails6_users_app/config/initializers/mime_types.rb +4 -0
- data/spec/fixtures/rails6_users_app/config/initializers/record_button.rb +3 -0
- data/spec/fixtures/rails6_users_app/config/initializers/wrap_parameters.rb +9 -0
- data/spec/fixtures/rails6_users_app/config/locales/en.yml +33 -0
- data/spec/fixtures/rails6_users_app/config/routes.rb +11 -0
- data/spec/fixtures/rails6_users_app/create_app +27 -0
- data/spec/fixtures/rails6_users_app/db/migrate/20190728211408_create_users.rb +9 -0
- data/spec/fixtures/rails6_users_app/db/schema.rb +23 -0
- data/spec/fixtures/rails6_users_app/docker-compose.yml +28 -0
- data/spec/fixtures/rails6_users_app/features/api_users.feature +13 -0
- data/spec/fixtures/rails6_users_app/features/support/env.rb +4 -0
- data/spec/fixtures/rails6_users_app/features/support/hooks.rb +11 -0
- data/spec/fixtures/rails6_users_app/features/support/steps.rb +18 -0
- data/spec/fixtures/rails6_users_app/lib/tasks/.keep +0 -0
- data/spec/fixtures/rails6_users_app/log/.keep +0 -0
- data/spec/fixtures/rails6_users_app/public/robots.txt +1 -0
- data/spec/fixtures/rails6_users_app/spec/controllers/users_controller_api_spec.rb +29 -0
- data/spec/fixtures/rails6_users_app/spec/models/user_spec.rb +39 -0
- data/spec/fixtures/rails6_users_app/spec/rails_helper.rb +66 -0
- data/spec/fixtures/rails6_users_app/spec/spec_helper.rb +96 -0
- data/spec/fixtures/rails6_users_app/users_app/.gitignore +20 -0
- data/spec/hook_spec.rb +196 -11
- data/spec/rails_spec_helper.rb +5 -5
- data/spec/railtie_spec.rb +31 -32
- data/spec/record_sql_rails4_pg_spec.rb +47 -48
- data/spec/record_sql_rails_pg_spec.rb +62 -63
- data/spec/remote_recording_spec.rb +90 -89
- data/spec/rspec_feature_metadata_spec.rb +17 -18
- data/test/cli_test.rb +0 -10
- data/test/expectations/openssl_test_key_sign1.json +55 -0
- data/test/expectations/openssl_test_key_sign2.json +58 -0
- data/test/fixtures/gem_test/Gemfile +6 -0
- data/test/fixtures/gem_test/appmap.yml +3 -0
- data/test/fixtures/gem_test/test/to_param_test.rb +14 -0
- data/test/gem_test.rb +34 -0
- data/test/minitest_test.rb +2 -2
- data/test/openssl_test.rb +10 -165
- metadata +171 -80
data/spec/rails_spec_helper.rb
CHANGED
@@ -29,10 +29,10 @@ def run_cmd(*cmd, &failed)
|
|
29
29
|
raise 'Command failed'
|
30
30
|
end
|
31
31
|
|
32
|
-
shared_context 'Rails app pg database' do
|
33
|
-
|
34
|
-
raise 'you must set @fixure_dir' unless @fixture_dir
|
32
|
+
shared_context 'Rails app pg database' do |fixture_dir|
|
33
|
+
let(:fixture_dir) { fixture_dir }
|
35
34
|
|
35
|
+
before(:all) do
|
36
36
|
print_pg_logs = lambda do
|
37
37
|
logs, = run_cmd 'docker-compose logs pg'
|
38
38
|
puts "docker-compose logs for pg:"
|
@@ -40,7 +40,7 @@ shared_context 'Rails app pg database' do
|
|
40
40
|
puts logs
|
41
41
|
end
|
42
42
|
|
43
|
-
Dir.chdir
|
43
|
+
Dir.chdir fixture_dir do
|
44
44
|
run_cmd 'docker-compose down -v'
|
45
45
|
cmd = 'docker-compose up -d pg'
|
46
46
|
run_cmd cmd
|
@@ -54,7 +54,7 @@ shared_context 'Rails app pg database' do
|
|
54
54
|
after(:all) do
|
55
55
|
if ENV['NOKILL'] != 'true'
|
56
56
|
cmd = 'docker-compose down -v'
|
57
|
-
run_cmd cmd, chdir:
|
57
|
+
run_cmd cmd, chdir: fixture_dir
|
58
58
|
end
|
59
59
|
end
|
60
60
|
end
|
data/spec/railtie_spec.rb
CHANGED
@@ -1,43 +1,42 @@
|
|
1
1
|
require 'rails_spec_helper'
|
2
2
|
|
3
3
|
describe 'AppMap tracer via Railtie' do
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
let(:env) { {} }
|
4
|
+
include_context 'Rails app pg database', 'spec/fixtures/rails5_users_app' do
|
5
|
+
let(:env) { {} }
|
8
6
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
7
|
+
let(:cmd) { %(docker-compose run --rm -e RAILS_ENV -e APPMAP app ./bin/rails r "puts Rails.configuration.appmap.enabled.inspect") }
|
8
|
+
let(:command_capture2) do
|
9
|
+
require 'open3'
|
10
|
+
Open3.capture3(env, cmd, chdir: fixture_dir).tap do |result|
|
11
|
+
unless result[2] == 0
|
12
|
+
warn <<~STDERR
|
13
|
+
Failed to run rails5_users_app container
|
14
|
+
<<< Output:
|
15
|
+
#{result[0]}
|
16
|
+
#{result[1]}
|
17
|
+
>>> End of output
|
18
|
+
STDERR
|
19
|
+
raise 'Failed to run rails5_users_app container'
|
20
|
+
end
|
22
21
|
end
|
23
22
|
end
|
24
|
-
|
25
|
-
|
26
|
-
let(:command_result) { command_capture2[2] }
|
27
|
-
|
28
|
-
it 'is disabled by default' do
|
29
|
-
expect(command_output).to eq('nil')
|
30
|
-
end
|
23
|
+
let(:command_output) { command_capture2[0].strip }
|
24
|
+
let(:command_result) { command_capture2[2] }
|
31
25
|
|
32
|
-
|
33
|
-
|
34
|
-
it 'is enabled' do
|
35
|
-
expect(command_output.split("\n")).to include('true')
|
26
|
+
it 'is disabled by default' do
|
27
|
+
expect(command_output).to eq('nil')
|
36
28
|
end
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
29
|
+
|
30
|
+
describe 'with APPMAP=true' do
|
31
|
+
let(:env) { { 'APPMAP' => 'true' } }
|
32
|
+
it 'is enabled' do
|
33
|
+
expect(command_output.split("\n")).to include('true')
|
34
|
+
end
|
35
|
+
context 'and RAILS_ENV=test' do
|
36
|
+
let(:env) { { 'APPMAP' => 'true', 'RAILS_ENV' => 'test' } }
|
37
|
+
it 'is disabled' do
|
38
|
+
expect(command_output).to eq('nil')
|
39
|
+
end
|
41
40
|
end
|
42
41
|
end
|
43
42
|
end
|
@@ -1,75 +1,74 @@
|
|
1
1
|
require 'rails_spec_helper'
|
2
2
|
|
3
3
|
describe 'Record SQL queries in a Rails4 app' do
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
cmd = "docker-compose run --rm -e ORM_MODULE=#{orm_module} -e APPMAP=true -v #{File.absolute_path tmpdir}:/app/tmp app ./bin/rspec spec/controllers/users_controller_api_spec.rb:#{test_line_number}"
|
11
|
-
run_cmd cmd, chdir: @fixture_dir
|
4
|
+
include_context 'Rails app pg database', 'spec/fixtures/rails4_users_app' do
|
5
|
+
around(:each) do |example|
|
6
|
+
FileUtils.rm_rf tmpdir
|
7
|
+
FileUtils.mkdir_p tmpdir
|
8
|
+
cmd = "docker-compose run --rm -e ORM_MODULE=#{orm_module} -e APPMAP=true -v #{File.absolute_path tmpdir}:/app/tmp app ./bin/rspec spec/controllers/users_controller_api_spec.rb:#{test_line_number}"
|
9
|
+
run_cmd cmd, chdir: fixture_dir
|
12
10
|
|
13
|
-
|
14
|
-
|
11
|
+
example.run
|
12
|
+
end
|
13
|
+
|
14
|
+
let(:tmpdir) { "tmp/spec/record_sql_rails_pg_spec" }
|
15
|
+
let(:appmap) { JSON.parse(File.read(appmap_json)).to_yaml }
|
15
16
|
|
16
|
-
|
17
|
-
|
17
|
+
context 'when running specs' do
|
18
|
+
let(:test_line_number) { 31 }
|
19
|
+
let(:orm_module) { 'activerecord' }
|
18
20
|
|
19
|
-
|
20
|
-
|
21
|
-
let(:orm_module) { 'activerecord' }
|
21
|
+
it { is_expected.to be }
|
22
|
+
end
|
22
23
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
context 'while creating a new record' do
|
27
|
-
let(:test_line_number) { 8 }
|
28
|
-
let(:appmap_json) { File.join(tmpdir, 'appmap/rspec/Api_UsersController_POST_api_users_with_required_parameters_creates_a_user.appmap.json') }
|
24
|
+
context 'while creating a new record' do
|
25
|
+
let(:test_line_number) { 8 }
|
26
|
+
let(:appmap_json) { File.join(tmpdir, 'appmap/rspec/Api_UsersController_POST_api_users_with_required_parameters_creates_a_user.appmap.json') }
|
29
27
|
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
28
|
+
xcontext 'using Sequel ORM' do
|
29
|
+
let(:orm_module) { 'sequel' }
|
30
|
+
it 'detects the sql INSERT' do
|
31
|
+
expect(appmap).to include(<<-SQL_QUERY.strip)
|
34
32
|
sql_query:
|
35
33
|
sql: INSERT INTO "users" ("login") VALUES ('alice') RETURNING *
|
36
|
-
|
34
|
+
SQL_QUERY
|
35
|
+
end
|
37
36
|
end
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
expect(appmap).to include(<<-SQL_QUERY.strip)
|
37
|
+
context 'using ActiveRecord ORM' do
|
38
|
+
let(:orm_module) { 'activerecord' }
|
39
|
+
it 'detects the sql INSERT' do
|
40
|
+
expect(appmap).to include(<<-SQL_QUERY.strip)
|
43
41
|
sql_query:
|
44
42
|
sql: INSERT INTO "users" ("login", "created_at", "updated_at") VALUES ($1, $2,
|
45
43
|
$3) RETURNING "id"
|
46
|
-
|
44
|
+
SQL_QUERY
|
45
|
+
end
|
47
46
|
end
|
48
47
|
end
|
49
|
-
end
|
50
48
|
|
51
|
-
|
52
|
-
|
53
|
-
|
49
|
+
context 'while listing records' do
|
50
|
+
let(:test_line_number) { 23 }
|
51
|
+
let(:appmap_json) { File.join(tmpdir, 'appmap/rspec/Api_UsersController_GET_api_users_lists_the_users.appmap.json') }
|
54
52
|
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
53
|
+
xcontext 'using Sequel ORM' do
|
54
|
+
let(:orm_module) { 'sequel' }
|
55
|
+
it 'detects the sql SELECT' do
|
56
|
+
expect(appmap).to include(<<-SQL_QUERY.strip)
|
59
57
|
sql_query:
|
60
58
|
sql: SELECT * FROM "users"
|
61
|
-
|
59
|
+
SQL_QUERY
|
62
60
|
|
63
|
-
|
61
|
+
expect(appmap).to include('sql:')
|
62
|
+
end
|
64
63
|
end
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
expect(appmap).to include(<<-SQL_QUERY.strip)
|
64
|
+
context 'using ActiveRecord ORM' do
|
65
|
+
let(:orm_module) { 'activerecord' }
|
66
|
+
it 'detects the sql SELECT' do
|
67
|
+
expect(appmap).to include(<<-SQL_QUERY.strip)
|
70
68
|
sql_query:
|
71
69
|
sql: SELECT "users".* FROM "users"
|
72
|
-
|
70
|
+
SQL_QUERY
|
71
|
+
end
|
73
72
|
end
|
74
73
|
end
|
75
74
|
end
|
@@ -1,89 +1,88 @@
|
|
1
1
|
require 'rails_spec_helper'
|
2
2
|
|
3
3
|
describe 'SQL events' do
|
4
|
-
|
5
|
-
|
4
|
+
include_context 'Rails app pg database', 'spec/fixtures/rails5_users_app' do
|
5
|
+
around(:each) do |example|
|
6
|
+
FileUtils.rm_rf tmpdir
|
7
|
+
FileUtils.mkdir_p tmpdir
|
8
|
+
cmd = "docker-compose run --rm -e ORM_MODULE=#{orm_module} -e APPMAP=true -v #{File.absolute_path tmpdir}:/app/tmp app ./bin/rspec spec/controllers/users_controller_api_spec.rb:#{test_line_number}"
|
9
|
+
run_cmd cmd, chdir: fixture_dir
|
6
10
|
|
7
|
-
|
8
|
-
|
9
|
-
FileUtils.mkdir_p tmpdir
|
10
|
-
cmd = "docker-compose run --rm -e ORM_MODULE=#{orm_module} -e APPMAP=true -v #{File.absolute_path tmpdir}:/app/tmp app ./bin/rspec spec/controllers/users_controller_api_spec.rb:#{test_line_number}"
|
11
|
-
run_cmd cmd, chdir: @fixture_dir
|
12
|
-
|
13
|
-
example.run
|
14
|
-
end
|
11
|
+
example.run
|
12
|
+
end
|
15
13
|
|
16
|
-
|
14
|
+
let(:tmpdir) { "tmp/spec/record_sql_rails_pg_spec" }
|
17
15
|
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
16
|
+
describe 'fields' do
|
17
|
+
let(:test_line_number) { 8 }
|
18
|
+
let(:appmap_json) { File.join(tmpdir, 'appmap/rspec/Api_UsersController_POST_api_users_with_required_parameters_creates_a_user.appmap.json') }
|
19
|
+
let(:orm_module) { 'sequel' }
|
20
|
+
let(:appmap) { JSON.parse(File.read(appmap_json)) }
|
21
|
+
describe 'on a call event' do
|
22
|
+
let(:event) do
|
23
|
+
appmap['events'].find do |event|
|
24
|
+
event['event'] == 'call' &&
|
25
|
+
event.keys.include?('sql_query')
|
26
|
+
end
|
27
|
+
end
|
28
|
+
it 'do not include function-only fields' do
|
29
|
+
expect(event.keys).to_not include('defined_class')
|
30
|
+
expect(event.keys).to_not include('method_id')
|
31
|
+
expect(event.keys).to_not include('path')
|
32
|
+
expect(event.keys).to_not include('lineno')
|
28
33
|
end
|
29
|
-
end
|
30
|
-
it 'do not include function-only fields' do
|
31
|
-
expect(event.keys).to_not include('defined_class')
|
32
|
-
expect(event.keys).to_not include('method_id')
|
33
|
-
expect(event.keys).to_not include('path')
|
34
|
-
expect(event.keys).to_not include('lineno')
|
35
34
|
end
|
36
35
|
end
|
37
|
-
end
|
38
36
|
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
37
|
+
describe 'in a Rails app' do
|
38
|
+
let(:appmap) { JSON.parse(File.read(appmap_json)).to_yaml }
|
39
|
+
context 'while creating a new record' do
|
40
|
+
let(:test_line_number) { 8 }
|
41
|
+
let(:appmap_json) { File.join(tmpdir, 'appmap/rspec/Api_UsersController_POST_api_users_with_required_parameters_creates_a_user.appmap.json') }
|
44
42
|
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
43
|
+
context 'using Sequel ORM' do
|
44
|
+
let(:orm_module) { 'sequel' }
|
45
|
+
it 'detects the sql INSERT' do
|
46
|
+
expect(appmap).to include(<<-SQL_QUERY.strip)
|
49
47
|
sql_query:
|
50
48
|
sql: INSERT INTO "users" ("login") VALUES ('alice') RETURNING *
|
51
|
-
|
49
|
+
SQL_QUERY
|
50
|
+
end
|
52
51
|
end
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
expect(appmap).to include(<<-SQL_QUERY.strip)
|
52
|
+
context 'using ActiveRecord ORM' do
|
53
|
+
let(:orm_module) { 'activerecord' }
|
54
|
+
it 'detects the sql INSERT' do
|
55
|
+
expect(appmap).to include(<<-SQL_QUERY.strip)
|
58
56
|
sql_query:
|
59
57
|
sql: INSERT INTO "users" ("login") VALUES ($1) RETURNING "id"
|
60
|
-
|
58
|
+
SQL_QUERY
|
59
|
+
end
|
61
60
|
end
|
62
61
|
end
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
expect(appmap).to include(<<-SQL_QUERY.strip)
|
62
|
+
|
63
|
+
context 'while listing records' do
|
64
|
+
let(:test_line_number) { 23 }
|
65
|
+
let(:appmap_json) { File.join(tmpdir, 'appmap/rspec/Api_UsersController_GET_api_users_lists_the_users.appmap.json') }
|
66
|
+
|
67
|
+
context 'using Sequel ORM' do
|
68
|
+
let(:orm_module) { 'sequel' }
|
69
|
+
it 'detects the sql SELECT' do
|
70
|
+
expect(appmap).to include(<<-SQL_QUERY.strip)
|
73
71
|
sql_query:
|
74
72
|
sql: SELECT * FROM "users"
|
75
|
-
|
76
|
-
|
77
|
-
|
73
|
+
SQL_QUERY
|
74
|
+
|
75
|
+
expect(appmap).to include('sql:')
|
76
|
+
end
|
78
77
|
end
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
expect(appmap).to include(<<-SQL_QUERY.strip)
|
78
|
+
context 'using ActiveRecord ORM' do
|
79
|
+
let(:orm_module) { 'activerecord' }
|
80
|
+
it 'detects the sql SELECT' do
|
81
|
+
expect(appmap).to include(<<-SQL_QUERY.strip)
|
84
82
|
sql_query:
|
85
83
|
sql: SELECT "users".* FROM "users"
|
86
|
-
|
84
|
+
SQL_QUERY
|
85
|
+
end
|
87
86
|
end
|
88
87
|
end
|
89
88
|
end
|
@@ -3,115 +3,116 @@ require 'net/http'
|
|
3
3
|
require 'socket'
|
4
4
|
|
5
5
|
describe 'remote recording', :order => :defined do
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
end
|
15
|
-
|
16
|
-
port_cmd = 'docker-compose port app 3000'
|
17
|
-
port_out, = run_cmd port_cmd, chdir: @fixture_dir
|
18
|
-
@service_port = port_out.strip.split(':')[1]
|
19
|
-
|
20
|
-
service_running = false
|
21
|
-
retry_count = 0
|
22
|
-
uri = URI("http://localhost:#{@service_port}/health")
|
6
|
+
include_context 'Rails app pg database', 'spec/fixtures/rails5_users_app' do
|
7
|
+
before(:all) do
|
8
|
+
fixture_dir = 'spec/fixtures/rails5_users_app'
|
9
|
+
start_cmd = 'docker-compose up -d app'
|
10
|
+
run_cmd({ 'ORM_MODULE' => 'sequel', 'APPMAP' => 'true' }, start_cmd, chdir: fixture_dir)
|
11
|
+
Dir.chdir fixture_dir do
|
12
|
+
wait_for_container 'app'
|
13
|
+
end
|
23
14
|
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
15
|
+
port_cmd = 'docker-compose port app 3000'
|
16
|
+
port_out, = run_cmd port_cmd, chdir: fixture_dir
|
17
|
+
@service_port = port_out.strip.split(':')[1]
|
18
|
+
|
19
|
+
service_running = false
|
20
|
+
retry_count = 0
|
21
|
+
uri = URI("http://localhost:#{@service_port}/health")
|
22
|
+
|
23
|
+
until service_running
|
24
|
+
sleep(0.25)
|
25
|
+
begin
|
26
|
+
res = Net::HTTP.start(uri.hostname, uri.port) do |http|
|
27
|
+
http.request(Net::HTTP::Get.new(uri))
|
28
|
+
end
|
29
|
+
|
30
|
+
status = res.response.code.to_i
|
31
|
+
service_running = true if status >= 200 && status < 300
|
32
|
+
|
33
|
+
# give up after a certain error threshold is met
|
34
|
+
# we don't want to wait forever if there's an unrecoverable issue
|
35
|
+
raise 'gave up waiting on fixture service' if (retry_count += 1) == 10
|
36
|
+
rescue Errno::ETIMEDOUT, Errno::ECONNRESET, EOFError
|
37
|
+
$stderr.print('.')
|
29
38
|
end
|
30
|
-
|
31
|
-
status = res.response.code.to_i
|
32
|
-
service_running = true if status >= 200 && status < 300
|
33
|
-
|
34
|
-
# give up after a certain error threshold is met
|
35
|
-
# we don't want to wait forever if there's an unrecoverable issue
|
36
|
-
raise 'gave up waiting on fixture service' if (retry_count += 1) == 10
|
37
|
-
rescue Errno::ETIMEDOUT, Errno::ECONNRESET, EOFError
|
38
|
-
$stderr.print('.')
|
39
39
|
end
|
40
40
|
end
|
41
|
-
end
|
42
41
|
|
43
|
-
|
44
|
-
|
45
|
-
|
42
|
+
def json_body(res)
|
43
|
+
JSON.parse(res.body).deep_symbolize_keys
|
44
|
+
end
|
46
45
|
|
47
|
-
|
48
|
-
|
49
|
-
|
46
|
+
after(:all) do
|
47
|
+
fixture_dir = 'spec/fixtures/rails5_users_app'
|
48
|
+
run_cmd 'docker-compose rm -fs app', chdir: fixture_dir
|
49
|
+
end
|
50
50
|
|
51
|
-
|
52
|
-
|
53
|
-
|
51
|
+
let(:service_address) { URI("http://localhost:#{@service_port}") }
|
52
|
+
let(:users_path) { '/users' }
|
53
|
+
let(:record_path) { '/_appmap/record' }
|
54
54
|
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
55
|
+
it 'returns the recording status' do
|
56
|
+
res = Net::HTTP.start(service_address.hostname, service_address.port) { |http|
|
57
|
+
http.request(Net::HTTP::Get.new(record_path))
|
58
|
+
}
|
59
59
|
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
60
|
+
expect(res).to be_a(Net::HTTPOK)
|
61
|
+
expect(res['Content-Type']).to eq('application/json')
|
62
|
+
expect(json_body(res)).to eq(enabled: false)
|
63
|
+
end
|
64
64
|
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
65
|
+
it 'starts a new recording session' do
|
66
|
+
res = Net::HTTP.start(service_address.hostname, service_address.port) { |http|
|
67
|
+
http.request(Net::HTTP::Post.new(record_path))
|
68
|
+
}
|
69
69
|
|
70
|
-
|
71
|
-
|
70
|
+
expect(res).to be_a(Net::HTTPOK)
|
71
|
+
end
|
72
72
|
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
73
|
+
it 'reflects the recording status' do
|
74
|
+
res = Net::HTTP.start(service_address.hostname, service_address.port) { |http|
|
75
|
+
http.request(Net::HTTP::Get.new(record_path))
|
76
|
+
}
|
77
77
|
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
78
|
+
expect(res).to be_a(Net::HTTPOK)
|
79
|
+
expect(res['Content-Type']).to eq('application/json')
|
80
|
+
expect(json_body(res)).to eq(enabled: true)
|
81
|
+
end
|
82
82
|
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
83
|
+
it 'fails to start a new recording session while recording is already active' do
|
84
|
+
res = Net::HTTP.start(service_address.hostname, service_address.port) { |http|
|
85
|
+
http.request(Net::HTTP::Post.new(record_path))
|
86
|
+
}
|
87
87
|
|
88
|
-
|
89
|
-
|
88
|
+
expect(res).to be_a(Net::HTTPConflict)
|
89
|
+
end
|
90
90
|
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
91
|
+
it 'stops recording' do
|
92
|
+
# Generate some events
|
93
|
+
Net::HTTP.start(service_address.hostname, service_address.port) { |http|
|
94
|
+
http.request(Net::HTTP::Get.new(users_path) )
|
95
|
+
}
|
96
96
|
|
97
|
-
|
98
|
-
|
99
|
-
|
97
|
+
res = Net::HTTP.start(service_address.hostname, service_address.port) { |http|
|
98
|
+
http.request(Net::HTTP::Delete.new(record_path))
|
99
|
+
}
|
100
100
|
|
101
|
-
|
102
|
-
|
101
|
+
expect(res).to be_a(Net::HTTPOK)
|
102
|
+
expect(res['Content-Type']).to eq('application/json')
|
103
103
|
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
104
|
+
data = json_body(res)
|
105
|
+
expect(data[:metadata]).to be_truthy
|
106
|
+
expect(data[:classMap].length).to be > 0
|
107
|
+
expect(data[:events].length).to be > 0
|
108
|
+
end
|
109
109
|
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
110
|
+
it 'fails to stop recording if there is no active recording session' do
|
111
|
+
res = Net::HTTP.start(service_address.hostname, service_address.port) { |http|
|
112
|
+
http.request(Net::HTTP::Delete.new(record_path))
|
113
|
+
}
|
114
114
|
|
115
|
-
|
115
|
+
expect(res).to be_a(Net::HTTPNotFound)
|
116
|
+
end
|
116
117
|
end
|
117
118
|
end
|