health_check 3.0.0 → 3.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,30 @@
1
+ # Gemfile for health_test testing
2
+
3
+ source 'https://rubygems.org'
4
+
5
+ ruby RUBY_VERSION < '2.5' ? '2.5.0' : RUBY_VERSION
6
+
7
+ gem 'rails', '~> 6.2.0'
8
+ gem 'rake', '>= 0.8.7'
9
+
10
+ group :development, :test do
11
+ if defined?(JRUBY_VERSION)
12
+ gem 'jruby-openssl'
13
+ gem 'activerecord-jdbcsqlite3-adapter'
14
+ else
15
+ gem 'sqlite3', "~> 1.3.7"
16
+ end
17
+ gem 'shoulda'
18
+ end
19
+
20
+ # redis based checks
21
+ gem 'sidekiq', '~> 5.2.9', require: !ENV['SIDEKIQ'].nil? # REQUIRED
22
+ gem 'redis', '~> 4.0.3', require: !ENV['REDIS_URL'].nil? # REQUIRED
23
+ gem 'resque', '~> 1.27.4', require: !ENV['RESQUE'].nil? # REQUIRED
24
+ gem 'elasticsearch', '~> 6.3.1', require: !ENV['ELASTICSEARCH_URL'].nil? # REQUIRED
25
+ # s3 check
26
+ gem 'aws-sdk-s3', require: !ENV['AWS_ACCESS_KEY_ID'].nil? # REQUIRED
27
+
28
+ gem 'webpacker', '~> 4.0.7' # REQUIRED
29
+ gem 'rexml', '~> 3.2.4' # REQUIRED for ruby 3.0
30
+ gem 'webrick' # REQUIRED for ruby 3.0
@@ -0,0 +1,37 @@
1
+ # Gemfile for health_test testing
2
+
3
+ source 'https://rubygems.org'
4
+
5
+ # Bundle edge Rails instead:
6
+
7
+ ruby RUBY_VERSION < '2.2.2' ? '2.2.2' : RUBY_VERSION
8
+
9
+ gem 'rails'
10
+ gem 'rake'
11
+ gem 'rack'
12
+
13
+ group :development, :test do
14
+ if defined?(JRUBY_VERSION)
15
+ gem 'jruby-openssl'
16
+ gem 'activerecord-jdbcsqlite3-adapter'
17
+ else
18
+ gem 'sqlite3'
19
+ end
20
+ gem 'shoulda'
21
+ end
22
+
23
+ # redis based checks
24
+ gem 'sidekiq', '~> 5.2.9', require: !ENV['SIDEKIQ'].nil? # REQUIRED
25
+ gem 'redis', '~> 4.0.3', require: !ENV['REDIS_URL'].nil? # REQUIRED
26
+ gem 'resque', '~> 1.27.4', require: !ENV['RESQUE'].nil? # REQUIRED
27
+ gem 'elasticsearch', '~> 6.3.1', require: !ENV['ELASTICSEARCH_URL'].nil? # REQUIRED
28
+ # s3 check
29
+ gem 'aws-sdk-s3', require: !ENV['AWS_ACCESS_KEY_ID'].nil? # REQUIRED
30
+
31
+ # Initial Gemfile has therubyracer commented out
32
+ gem 'therubyrhino', platform: :jruby # REQUIRED
33
+ gem 'therubyracer', platform: :ruby # REQUIRED
34
+
35
+ gem 'webpacker', '~> 4.0.7' # REQUIRED
36
+ gem 'rexml', '~> 3.2.4' # REQUIRED for ruby 3.0
37
+ gem 'webrick' # REQUIRED for ruby 3.0
data/test/setup_railsapp CHANGED
@@ -2,15 +2,27 @@
2
2
 
3
3
  route_prefix=medical_check
4
4
 
5
- err_report() {
6
- echo "$0: Error on line $1 - aborted"
7
- exit 1
5
+ # Any failure causes exit
6
+ set -eE -o functrace
7
+
8
+ report_failure() {
9
+ local lineno=$2
10
+ local fn=$3
11
+ local exitstatus=$4
12
+ local msg=$5
13
+ local lineno_fns=${1% 0}
14
+ if [[ $lineno_fns != "0" ]] ; then
15
+ lineno="${lineno} ${lineno_fns}"
16
+ fi
17
+ if [[ $exitstatus == 0 ]] ; then
18
+ echo "${BASH_SOURCE[1]}: Finished!"
19
+ else
20
+ echo "${BASH_SOURCE[1]}:${fn}[${lineno}] Failed with status ${exitstatus}: $msg"
21
+ fi
8
22
  }
9
23
 
10
- trap 'err_report $LINENO' ERR
24
+ trap 'report_failure "${BASH_LINENO[*]}" "$LINENO" "${FUNCNAME[*]:-script}" "$?" "$BASH_COMMAND"' ERR
11
25
 
12
- # Any failure causes exit
13
- set -e
14
26
 
15
27
  case "$1" in
16
28
  [0-9]*)
@@ -54,7 +66,7 @@ mkdir -p tmp/gems
54
66
  if $rbenv_which bundle ; then
55
67
  echo Bundler is installed
56
68
  else
57
- gem install bundler
69
+ gem install bundler ${BUNDLER_VERSION:+-v ${BUNDLER_VERSION}}
58
70
  $rehash
59
71
  fi
60
72
 
@@ -62,6 +74,13 @@ echo "Running bundle with BUNDLE_GEMFILE=$BUNDLE_GEMFILE ..."
62
74
  if ! smarter_bundle ; then
63
75
  echo "Test aborted (missing required gems)"
64
76
  exit 2
77
+ elif [ ! -s $BUNDLE_GEMFILE.lock ] ; then
78
+ echo "Error: smarter_bundler return OK status BUT lock file ($BUNDLE_GEMFILE.lock) is missing!"
79
+ exit 3
80
+ else
81
+ echo bundle passed - lock file contains:
82
+ cat $BUNDLE_GEMFILE.lock
83
+ echo
65
84
  fi
66
85
  $rehash
67
86
 
@@ -69,9 +88,9 @@ rails="$base_dir/test/bin/rails"
69
88
  rake="$base_dir/test/bin/rake"
70
89
 
71
90
  echo Checking $rails is present ...
72
- [ -f $rails -a -f $rake ] || bundle exec rake rails:update:bin || echo '(ignored rake rails:update:bin exit status)'
73
- [ -f $rails ] || bundle binstubs railties || echo '(ignored bundle exit status)'
74
- [ -f $rails ] || bundle binstubs rails || echo '(ignored bundle exit status)'
91
+ [ -f $rails -a -f $rake ] || bundle ${BUNDLER_VERSION:+_${BUNDLER_VERSION}_} exec rake rails:update:bin || echo '(ignored rake rails:update:bin exit status)'
92
+ [ -f $rails ] || bundle ${BUNDLER_VERSION:+_${BUNDLER_VERSION}_} binstubs railties || echo '(ignored bundle exit status)'
93
+ [ -f $rails ] || bundle ${BUNDLER_VERSION:+_${BUNDLER_VERSION}_} binstubs rails || echo '(ignored bundle exit status)'
75
94
  if [ ! -f $rails ]; then
76
95
  echo "Test aborted (unable to create $rails)"
77
96
  exit 2
@@ -79,7 +98,7 @@ fi
79
98
 
80
99
  if [ ! -f $rake ]; then
81
100
  echo "Running bundle binstubs rake ..."
82
- if ! bundle binstubs rake || [ ! -f $rake ]; then
101
+ if ! bundle ${BUNDLER_VERSION:+_${BUNDLER_VERSION}_} binstubs rake || [ ! -f $rake ]; then
83
102
  echo "Test aborted (unable to create $rake)"
84
103
  exit 2
85
104
  fi
@@ -124,16 +143,25 @@ esac
124
143
 
125
144
  echo "Creating $actual_rails_version app in $tmp_dir/railsapp using adapter $db"
126
145
  case "$actual_rails_version" in
127
- *' '[12].*)
128
- $rails railsapp -d $db
129
- ;;
130
146
  *' '[345].*)
147
+ args="--skip-bundle -d $db"
131
148
  case "$BUNDLE_GEMFILE" in
132
149
  *rails_edge.gemfile)
133
- $rails new railsapp --skip-bundle -d $db --edge
150
+ $rails new railsapp $args --edge
134
151
  ;;
135
152
  *)
136
- $rails new railsapp --skip-bundle -d $db
153
+ $rails new railsapp $args
154
+ ;;
155
+ esac
156
+ ;;
157
+ *' '[6].*)
158
+ args="--skip-bundle -d $db --skip-git --skip-bootsnap"
159
+ case "$BUNDLE_GEMFILE" in
160
+ *rails_edge.gemfile)
161
+ $rails new railsapp $args --edge
162
+ ;;
163
+ *)
164
+ $rails new railsapp $args
137
165
  ;;
138
166
  esac
139
167
  ;;
@@ -155,31 +183,48 @@ echo "Configuring mailer to point to fake_smtp_server port 3555"
155
183
  cat >> config/environment.rb <<'!EOF!'
156
184
 
157
185
  ActionMailer::Base.delivery_method = :smtp
158
- ActionMailer::Base.smtp_settings = { :address => "localhost", :port => 3555 }
186
+ ActionMailer::Base.smtp_settings = { address: "localhost", port: 3555 }
159
187
 
160
188
  !EOF!
161
189
 
162
190
  echo Adding an initializer for health_check gem ...
163
191
  mkdir -p config/initializers
164
192
  tee config/initializers/health_check.rb <<!
165
- HealthCheck.setup do |config|
166
- config.success = "$success"
167
- config.smtp_timeout = 60.0
168
- config.http_status_for_error_text = 550
169
- config.http_status_for_error_object = 555
170
- config.uri = '$route_prefix'
171
- config.origin_ip_whitelist = ENV['IP_WHITELIST'].split(',') unless ENV['IP_WHITELIST'].blank?
172
- config.basic_auth_username = ENV['AUTH_USER'] unless ENV['AUTH_USER'].blank?
173
- config.basic_auth_password = ENV['AUTH_PASSWORD'] unless ENV['AUTH_PASSWORD'].blank?
174
-
175
- config.add_custom_check do
176
- File.exists?("$custom_file") ? '' : '$custom_file is missing!'
177
- end
178
-
179
- config.add_custom_check('pass') do
180
- ''
193
+ require 'fileutils'
194
+
195
+ if defined? HealthCheck
196
+ HealthCheck.setup do |config|
197
+ config.success = "$success"
198
+ config.smtp_timeout = 60.0
199
+ config.http_status_for_error_text = 550
200
+ config.http_status_for_error_object = 555
201
+ config.uri = '$route_prefix'
202
+ config.origin_ip_whitelist = ENV['IP_WHITELIST'].split(',') unless ENV['IP_WHITELIST'].blank?
203
+ config.basic_auth_username = ENV['AUTH_USER'] unless ENV['AUTH_USER'].blank?
204
+ config.basic_auth_password = ENV['AUTH_PASSWORD'] unless ENV['AUTH_PASSWORD'].blank?
205
+
206
+ config.add_custom_check do
207
+ File.exists?("$custom_file") ? '' : '$custom_file is missing!'
208
+ end
209
+
210
+ config.add_custom_check('pass') do
211
+ ''
212
+ end
213
+
214
+ config.on_failure do |checks, msg|
215
+ File.open('tmp/health_check_failure.txt', 'w') do |f|
216
+ f.puts "FAILED: #{checks}, MESSAGE: #{msg}"
217
+ end
218
+ end
219
+
220
+ config.on_success do |checks|
221
+ File.open('tmp/health_check_success.txt', 'w') do |f|
222
+ f.puts "PASSED: #{checks}"
223
+ end
224
+ end
225
+
226
+ config.include_error_in_response_body = ENV['HIDE_ERROR_RESPONSE'].to_s !~ /^[1tTyY]/
181
227
  end
182
-
183
228
  end
184
229
  !
185
230
 
@@ -194,7 +239,7 @@ then
194
239
  exit 2
195
240
  fi
196
241
  echo Adding health_check as gem to Gemfile...
197
- echo "gem 'health_check', :path => '$base_dir'" >> Gemfile
242
+ echo "gem 'health_check', path: '$base_dir'" >> Gemfile
198
243
 
199
244
  case "$RAILS_SERVER" in
200
245
  webrick|'')
@@ -205,33 +250,59 @@ webrick|'')
205
250
  echo "gem '$RAILS_SERVER'" >> Gemfile
206
251
  ;;
207
252
  esac
208
-
209
- sed -i.bak -e '/listen/s/^/#Earlier version required # /' Gemfile
210
-
211
- egrep REQUIRED < ${INITIAL_BUNDLE_GEMFILE} >> Gemfile || echo No required gems found...
253
+ TAB=$'\t'
254
+ QUOTES='"'"'"
255
+ case "$actual_rails_version" in
256
+ *' '5.0*)
257
+ if egrep -i 'gem.*sqlite3' Gemfile ; then
258
+ # Can't do this as a require as we may go back to testing JRuby
259
+ echo Force sqlite to 1.3.13+ version for Rails 5.0 ...
260
+ gem=sqlite3
261
+ sed -i.bak -e "s/^\([ ${TAB}]*gem[ ${TAB}]*[${QUOTES}]${gem}[${QUOTES}]\)\(.*\)$/\1, '~> 1.3.13' # overriden: \2/" Gemfile
262
+ fi
263
+ ;;
264
+ esac
265
+ if egrep -q REQUIRED ${INITIAL_BUNDLE_GEMFILE} ; then
266
+ sed -n "s/^[ ${TAB}]*gem[ ${TAB}]*[${QUOTES}]\([^${QUOTES}]*\)[${QUOTES}].*REQUIRED.*/\1/p" ${INITIAL_BUNDLE_GEMFILE} | while read gem
267
+ do
268
+ echo "Commenting out gem '$gem' line in Gemfile"
269
+ sed -i.bak -e "s/^\([ ${TAB}]*gem[ ${TAB}]*[${QUOTES}]${gem}[${QUOTES}].*\)$/# overriden by REQUIRED below: \1/" Gemfile
270
+ done
271
+ echo Adding Required gems
272
+ egrep REQUIRED ${INITIAL_BUNDLE_GEMFILE} | tee -a Gemfile
273
+ else
274
+ echo No required gems to be added to Gemfile
275
+ fi
212
276
 
213
277
  echo
214
- echo ================= Gemfile ===================
278
+ echo ================= $PWD/Gemfile ===================
215
279
  cat Gemfile
216
280
  echo
217
- echo running bundle install
218
- smarter_bundle ${BUNDLER_VERSION:+_${BUNDLER_VERSION}_} install
281
+ echo ==================================================
282
+ echo running smarter_bundle install
283
+ smarter_bundle install
219
284
  $rehash
285
+
286
+ if egrep webpacker Gemfile && [ ! -f config/webpacker.yml ] ; then
287
+ echo completing setup by running rails webpacker:install ...
288
+ $rails webpacker:install
289
+ fi
290
+
220
291
  echo "Using binstubs in $railsapp/bin for rails and rake commands"
221
292
  rails="$railsapp/bin/rails"
222
293
  rake="$railsapp/bin/rake"
223
294
 
224
295
  echo Checking $rails is present ...
225
- [ -f $rails -a -f $rake ] || bundle exec rake rails:update:bin || echo '(ignored rake rails:update:bin exit status)'
226
- [ -f $rails ] || bundle binstubs railties || echo '(ignored bundle exit status)'
227
- [ -f $rails ] || bundle binstubs rails || echo '(ignored bundle exit status)'
296
+ [ -f $rails -a -f $rake ] || bundle ${BUNDLER_VERSION:+_${BUNDLER_VERSION}_} exec rake rails:update:bin || echo '(ignored rake rails:update:bin exit status)'
297
+ [ -f $rails ] || bundle ${BUNDLER_VERSION:+_${BUNDLER_VERSION}_} binstubs railties || echo '(ignored bundle exit status)'
298
+ [ -f $rails ] || bundle ${BUNDLER_VERSION:+_${BUNDLER_VERSION}_} binstubs rails || echo '(ignored bundle exit status)'
228
299
  if [ ! -f $rails ]; then
229
300
  echo "Test aborted (unable to create $rails)"
230
301
  exit 2
231
302
  fi
232
303
 
233
304
  echo Checking $rake is present ...
234
- [ -f $rake ] || bundle binstubs rake || echo '(ignored bundle exit status)'
305
+ [ -f $rake ] || bundle ${BUNDLER_VERSION:+_${BUNDLER_VERSION}_} binstubs rake || echo '(ignored bundle exit status)'
235
306
  if [ ! -f $rake ]; then
236
307
  echo "Test aborted (unable to create $rake)"
237
308
  exit 2
@@ -240,8 +311,9 @@ fi
240
311
  $rehash
241
312
  # Fix for rvm, otherwise bundle run from rails create fails
242
313
  export PATH="`pwd`/bin:$PATH"
243
- echo ================= Gemfile.lock ===================
314
+ echo ================= $PWD/Gemfile.lock ===================
244
315
  cat Gemfile.lock
316
+ echo ==================================================
245
317
  echo
246
318
 
247
319
  for e in test ${RAILS_ENV2:-production}
@@ -255,11 +327,22 @@ do
255
327
  echo
256
328
  fi
257
329
  done
258
- echo "============== config/environment.rb ============="
330
+
331
+ if egrep -q 'bootsnap.setup' config/boot.rb ; then
332
+ echo Commenting out bootsnap from config/boot.rb
333
+ sed -i.bak -e 's/^\(.*bootsnap.setup\)/# \1/' config/boot.rb
334
+ echo "============== $PWD/config/boot.rb ============="
335
+ cat config/boot.rb
336
+ echo ==================================================
337
+ fi
338
+ rm -rf tmp/cache/bootsnap*
339
+ echo
340
+
341
+ echo "============== $PWD/config/environment.rb ============="
259
342
  cat config/environment.rb
260
343
  echo
261
344
 
262
- echo ========================
345
+ echo =========================================================
263
346
  case $db in
264
347
  jdbcsqlite3)
265
348
  for e in test ${RAILS_ENV2:-production}
@@ -350,11 +433,11 @@ cat > app/controllers/example_controller.rb <<'EOF'
350
433
  class ExampleController < ApplicationController
351
434
 
352
435
  def index
353
- render :plain => 'example page'
436
+ render plain: 'example page'
354
437
  end
355
438
 
356
439
  def catchall
357
- render :plain => 'catch all route'
440
+ render plain: 'catch all route'
358
441
  end
359
442
 
360
443
  end
@@ -388,7 +471,7 @@ case "$MIDDLEWARE" in
388
471
 
389
472
  #echo =============== config/application.rb-old ========================
390
473
  #cat config/application.rb-old
391
- echo =============== config/application.rb ========================
474
+ echo =============== $PWD/config/application.rb ========================
392
475
  cat config/application.rb
393
476
  else
394
477
  echo FAILED: NO config/application.rb file!!
@@ -412,11 +495,12 @@ if [ -s config/routes.rb ]; then
412
495
  # rails 3.0+
413
496
  echo " # -----------------------------------------"
414
497
  echo " # START OF SECTION FOR TESTING HEALTH_CHECK"
415
- echo " get 'example(/:action(/:id))(.:format)' => 'example'"
498
+ echo " get 'example/catchall(.:format)', controller: :example, action: :catchall"
499
+ echo " get 'example(.:format)', controller: :example, action: :index"
416
500
  echo " if File.exists?('$catchall_file')"
417
501
  echo " health_check_routes"
418
502
  echo " # CATCH ALL ROUTE"
419
- echo " get '*path', :to => 'example#catchall'"
503
+ echo " get '*path', controller: :example, action: :catchall"
420
504
  echo " end"
421
505
  echo " # END OF SECTION FOR TESTING HEALTH_CHECK"
422
506
  echo " # ---------------------------------------"
@@ -2,15 +2,49 @@
2
2
 
3
3
  route_prefix=medical_check
4
4
 
5
- err_report() {
6
- echo "$0: Error on line $1 - aborted"
7
- exit 1
5
+ # Any failure causes exit
6
+ set -eE -o functrace
7
+
8
+ report_failure() {
9
+ local lineno=$2
10
+ local fn=$3
11
+ local exitstatus=$4
12
+ local msg=$5
13
+ local lineno_fns=${1% 0}
14
+ if [[ $lineno_fns != "0" ]] ; then
15
+ lineno="${lineno} ${lineno_fns}"
16
+ fi
17
+ if [[ $exitstatus == 0 ]] ; then
18
+ echo "${BASH_SOURCE[1]}: Finished!"
19
+ else
20
+ echo "${BASH_SOURCE[1]}:${fn}[${lineno}] Failed with status ${exitstatus}: $msg"
21
+ fi
8
22
  }
9
23
 
10
- trap 'err_report $LINENO' ERR
24
+ trap 'report_failure "${BASH_LINENO[*]}" "$LINENO" "${FUNCNAME[*]:-script}" "$?" "$BASH_COMMAND"' ERR
25
+
11
26
 
12
27
  # Any failure causes exit
13
- set -e
28
+ set -eE -o functrace
29
+
30
+ report_failure() {
31
+ local lineno=$2
32
+ local fn=$3
33
+ local exitstatus=$4
34
+ local msg=$5
35
+ local lineno_fns=${1% 0}
36
+ if [[ $lineno_fns != "0" ]] ; then
37
+ lineno="${lineno} ${lineno_fns}"
38
+ fi
39
+ if [[ $exitstatus == 0 ]] ; then
40
+ echo "${BASH_SOURCE[1]}: Finished!"
41
+ else
42
+ echo "${BASH_SOURCE[1]}:${fn}[${lineno}] Failed with status ${exitstatus}: $msg"
43
+ fi
44
+ }
45
+
46
+ trap 'report_failure "${BASH_LINENO[*]}" "$LINENO" "${FUNCNAME[*]:-script}" "$?" "$BASH_COMMAND"' ERR
47
+
14
48
  export DISABLE_SPRING=1
15
49
 
16
50
  cleanup_db()
@@ -91,18 +125,25 @@ start_server()
91
125
  bundle_prefix='bundle exec'
92
126
  fi
93
127
  server_arg=${RAILS_SERVER:-webrick}
128
+ case "$actual_rails_version" in
129
+ *' '[12345].*)
130
+ ;;
131
+ *)
132
+ server_arg="-u $server_arg"
133
+ ;;
134
+ esac
94
135
  echo "start_server called using: `env | egrep '^RAILS|^RACK|^PATH='` $bundle_prefix $server_arg"
95
136
  case "$server_arg" in
96
- puma)
137
+ *puma)
97
138
  $bundle_prefix puma -b tcp://127.0.0.1:$port &
98
139
  ;;
99
- passenger)
140
+ *passenger)
100
141
  $bundle_prefix passenger start -p $port &
101
142
  ;;
102
- thin)
143
+ *thin)
103
144
  $bundle_prefix thin start -p $port &
104
145
  ;;
105
- unicorn)
146
+ *unicorn)
106
147
  $bundle_prefix unicorn_rails -l 127.0.0.1:$port &
107
148
  ;;
108
149
  *)
@@ -212,7 +253,7 @@ common_tests()
212
253
  test_no=$1
213
254
 
214
255
  if [ -z "$run_test" ] || [ $test_no == "$run_test" ]; then
215
- echo "${test_no}: CHECKING routes exist..."
256
+ echo "${test_no}[line $LINENO]: CHECKING routes exist..."
216
257
  $rake routes | tee /tmp/t$$
217
258
  echo
218
259
  case `egrep ${route_prefix} /tmp/t$$ || true` in
@@ -225,7 +266,7 @@ common_tests()
225
266
 
226
267
  test_no=`expr 1 + $test_no`
227
268
  if [ -z "$run_test" ] || [ $test_no == "$run_test" ]; then
228
- echo "${test_no}: TESTING can get a static file ..."
269
+ echo "${test_no}[line $LINENO]: TESTING can get a static file ..."
229
270
  case "$RAILS_ENV=`egrep '^\s*config.serve_static_[asetfil]* *= *false' config/environments/${RAILS_ENV}.rb`" in
230
271
  production*static*false*)
231
272
  echo " SKIPPED (disabled in production)"
@@ -238,40 +279,77 @@ common_tests()
238
279
  echo
239
280
  fi
240
281
 
282
+ rm -f tmp/health_check_success.txt tmp/health_check_failure.txt
283
+
241
284
  test_no=`expr 1 + $test_no`
242
285
  if [ -z "$run_test" ] || [ $test_no == "$run_test" ]; then
243
- echo "${test_no}: TESTING can get an example controller ..."
286
+ echo "${test_no}[line $LINENO]: TESTING can get an example controller ..."
244
287
  $testurl ${host}/example 200 text/plain 'example page'
245
288
  echo
246
289
  fi
247
290
 
248
291
  test_no=`expr 1 + $test_no`
249
292
  if [ -z "$run_test" ] || [ $test_no == "$run_test" ]; then
250
- echo "${test_no}: TESTING direct call to catchall method on example controller ..."
293
+ echo "${test_no}[line $LINENO]: TESTING direct call to catchall method on example controller ..."
251
294
  $testurl ${host}/example/catchall 200 text/plain 'catch all route'
252
295
  echo
253
296
  fi
254
297
 
298
+ if [ -f tmp/health_check_success.txt ] ; then
299
+ echo "FAIL tmp/health_check_success.txt exists on line $LINENO"
300
+ else
301
+ echo "PASS tmp/health_check_success.txt is missing as expected on line $LINENO"
302
+ fi
303
+ if [ -f tmp/health_check_failure.txt ] ; then
304
+ echo "FAIL tmp/health_check_failure.txt exists on line $LINENO"
305
+ else
306
+ echo "PASS tmp/health_check_failure.txt is missing as expected on line $LINENO"
307
+ fi
308
+
255
309
  test_no=`expr 1 + $test_no`
256
310
  if [ -z "$run_test" ] || [ $test_no == "$run_test" ]; then
257
- echo "${test_no}: TESTING ${route_prefix}/migration should pass with no database migrations ..."
311
+ echo "${test_no}[line $LINENO]: TESTING ${route_prefix}/migration should pass with no database migrations ..."
258
312
  ls db/migrate
313
+ rm -f tmp/health_check_success.txt tmp/health_check_failure.txt
259
314
  $testurl ${host}/${route_prefix}/migration 200 text/plain $success
315
+ if [ -f tmp/health_check_success.txt ] ; then
316
+ echo "PASS tmp/health_check_success.txt exists as expected on line $LINENO"
317
+ cat tmp/health_check_success.txt
318
+ else
319
+ echo "FAIL tmp/health_check_success.txt is missing on line $LINENO"
320
+ fi
321
+ if [ -f tmp/health_check_failure.txt ] ; then
322
+ echo "FAIL tmp/health_check_failure.txt exists on line $LINENO"
323
+ else
324
+ echo "PASS tmp/health_check_failure.txt is missing as expected on line $LINENO"
325
+ fi
260
326
  echo
261
327
  fi
262
328
 
263
329
  test_no=`expr 1 + $test_no`
264
330
  if [ -z "$run_test" ] || [ $test_no == "$run_test" ]; then
265
- echo "${test_no}: TESTING ${route_prefix}/migration should fail without initial database migration ..."
331
+ echo "${test_no}[line $LINENO]: TESTING ${route_prefix}/migration should fail without initial database migration ..."
266
332
  cp $base_dir/test/migrate/nine/* db/migrate
267
333
  ls db/migrate
334
+ rm -f tmp/health_check_success.txt tmp/health_check_failure.txt
268
335
  $testurl ${host}/${route_prefix}/migration 550 text/plain failed
336
+ if [ -f tmp/health_check_success.txt ] ; then
337
+ echo "FAIL tmp/health_check_success.txt exists on line $LINENO"
338
+ else
339
+ echo "PASS tmp/health_check_success.txt is missing as expected on line $LINENO"
340
+ fi
341
+ if [ -f tmp/health_check_failure.txt ] ; then
342
+ echo "PASS tmp/health_check_failure.txt exists as expected on line $LINENO"
343
+ cat tmp/health_check_failure.txt
344
+ else
345
+ echo "FAIL tmp/health_check_failure.txt is missing on line $LINENO"
346
+ fi
269
347
  echo
270
348
  fi
271
349
 
272
350
  test_no=`expr 1 + $test_no`
273
351
  if [ -z "$run_test" ] || [ $test_no == "$run_test" ]; then
274
- echo "${test_no}: TESTING ${route_prefix}/database should pass without initial database migration (since it ignores the difference) ..."
352
+ echo "${test_no}[line $LINENO]: TESTING ${route_prefix}/database should pass without initial database migration (since it ignores the difference) ..."
275
353
  $testurl ${host}/${route_prefix}/database 200 text/plain $success
276
354
  echo
277
355
  fi
@@ -280,14 +358,14 @@ common_tests()
280
358
 
281
359
  test_no=`expr 1 + $test_no`
282
360
  if [ -z "$run_test" ] || [ $test_no == "$run_test" ]; then
283
- echo "${test_no}: TESTING ${route_prefix}/site should pass ..."
361
+ echo "${test_no}[line $LINENO]: TESTING ${route_prefix}/site should pass ..."
284
362
  $testurl ${host}/${route_prefix}/site 200 text/plain $success
285
363
  echo
286
364
  fi
287
365
 
288
366
  test_no=`expr 1 + $test_no`
289
367
  if [ -z "$run_test" ] || [ $test_no == "$run_test" ]; then
290
- echo "${test_no}: TESTING ${route_prefix}/migration should pass after initial database migration ..."
368
+ echo "${test_no}[line $LINENO]: TESTING ${route_prefix}/migration should pass after initial database migration ..."
291
369
  $rake db:migrate
292
370
  $testurl ${host}/${route_prefix}/migration 200 text/plain $success
293
371
  echo
@@ -303,18 +381,33 @@ common_tests()
303
381
 
304
382
  test_no=`expr 1 + $test_no`
305
383
  if [ -z "$run_test" ] || [ $test_no == "$run_test" ]; then
306
- echo "${test_no}: TESTING ${route_prefix}/database should fail if the database has been corrupted ..."
384
+ echo "${test_no}[line $LINENO]: TESTING ${route_prefix}/database should fail if the database has been corrupted ..."
385
+
386
+ $testurl ${host}/${route_prefix}/database 550 text/plain failed:
387
+ echo
388
+ fi
307
389
 
308
- $testurl ${host}/${route_prefix}/database 550 text/plain failed
390
+ export HIDE_ERROR_RESPONSE=true
391
+ stop_server
392
+ start_server
393
+
394
+ test_no=`expr 1 + $test_no`
395
+ if [ -z "$run_test" ] || [ $test_no == "$run_test" ]; then
396
+ echo "${test_no}[line $LINENO]: TESTING ${route_prefix}/database should have response body 'health_check failed' but no error details if include_error_in_response_body is false"
397
+ $testurl ${host}/${route_prefix}/database 550 text/plain 'health_check failed' failed:
309
398
  echo
310
399
  fi
311
400
 
401
+ unset HIDE_ERROR_RESPONSE
402
+ stop_server
403
+ start_server
404
+
312
405
  test_no=`expr 1 + $test_no`
313
406
  if [ -z "$run_test" ] || [ $test_no == "$run_test" ]; then
314
- echo "${test_no}: TESTING ${route_prefix}/site should pass ..."
407
+ echo "${test_no}[line $LINENO]: TESTING ${route_prefix}/site should pass ..."
315
408
  $testurl ${host}/${route_prefix}/site 200 text/plain $success
316
409
  if $has_middleware; then
317
- echo "${test_no}: TESTING ${route_prefix}/middleware_site should pass ..."
410
+ echo "${test_no}[line $LINENO]: TESTING ${route_prefix}/middleware_site should pass ..."
318
411
  $testurl ${host}/${route_prefix}/middleware_site 200 text/plain $success
319
412
  fi
320
413
  echo
@@ -325,7 +418,7 @@ common_tests()
325
418
 
326
419
  test_no=`expr 1 + $test_no`
327
420
  if [ -z "$run_test" ] || [ $test_no == "$run_test" ]; then
328
- echo "${test_no}: TESTING ${route_prefix}/migration should fail without all migrations ..."
421
+ echo "${test_no}[line $LINENO]: TESTING ${route_prefix}/migration should fail without all migrations ..."
329
422
  cp $base_dir/test/migrate/twelve/* db/migrate
330
423
 
331
424
  ls db/migrate
@@ -335,7 +428,7 @@ common_tests()
335
428
 
336
429
  test_no=`expr 1 + $test_no`
337
430
  if [ -z "$run_test" ] || [ $test_no == "$run_test" ]; then
338
- echo "${test_no}: TESTING ${route_prefix}/migration should pass after both database migrations ..."
431
+ echo "${test_no}[line $LINENO]: TESTING ${route_prefix}/migration should pass after both database migrations ..."
339
432
  $rake db:migrate
340
433
  $testurl ${host}/${route_prefix}/migration 200 text/plain $success
341
434
  echo
@@ -343,7 +436,7 @@ common_tests()
343
436
 
344
437
  test_no=`expr 1 + $test_no`
345
438
  if [ -z "$run_test" ] || [ $test_no == "$run_test" ]; then
346
- echo "${test_no}: TESTING ${route_prefix}/migration should pass after both database migrations ..."
439
+ echo "${test_no}[line $LINENO]: TESTING ${route_prefix}/migration should pass after both database migrations ..."
347
440
  $rake db:migrate
348
441
  $testurl ${host}/${route_prefix}/migration 200 text/plain $success
349
442
  echo
@@ -351,14 +444,14 @@ common_tests()
351
444
 
352
445
  test_no=`expr 1 + $test_no`
353
446
  if [ -z "$run_test" ] || [ $test_no == "$run_test" ]; then
354
- echo "${test_no}: TESTING ${route_prefix}/email should fail without smtp available ..."
447
+ echo "${test_no}[line $LINENO]: TESTING ${route_prefix}/email should fail without smtp available ..."
355
448
  $testurl ${host}/${route_prefix}/email 550 text/plain failed
356
449
  echo
357
450
  fi
358
451
 
359
452
  test_no=`expr 1 + $test_no`
360
453
  if [ -z "$run_test" ] || [ $test_no == "$run_test" ]; then
361
- echo "${test_no}: TESTING ${route_prefix}/email should pass with smtp available ..."
454
+ echo "${test_no}[line $LINENO]: TESTING ${route_prefix}/email should pass with smtp available ..."
362
455
  $fake_smtp_server &
363
456
  fake_smtp_pid=$!
364
457
  sleep 5
@@ -368,14 +461,14 @@ common_tests()
368
461
 
369
462
  test_no=`expr 1 + $test_no`
370
463
  if [ -z "$run_test" ] || [ $test_no == "$run_test" ]; then
371
- echo "${test_no}: TESTING ${route_prefix} (all) should fail without smtp available ..."
464
+ echo "${test_no}[line $LINENO]: TESTING ${route_prefix} (all) should fail without smtp available ..."
372
465
  $testurl ${host}/${route_prefix} 550 text/plain failed
373
466
  echo
374
467
  fi
375
468
 
376
469
  test_no=`expr 1 + $test_no`
377
470
  if [ -z "$run_test" ] || [ $test_no == "$run_test" ]; then
378
- echo "${test_no}: TESTING ${route_prefix}/all should fail without smtp available ..."
471
+ echo "${test_no}[line $LINENO]: TESTING ${route_prefix}/all should fail without smtp available ..."
379
472
  $testurl ${host}/${route_prefix} 550 text/plain failed
380
473
  echo
381
474
  fi
@@ -383,7 +476,7 @@ common_tests()
383
476
  kill -9 $fake_smtp_pid || echo fake_smtp_server had finished as expected
384
477
  test_no=`expr 1 + $test_no`
385
478
  if [ -z "$run_test" ] || [ $test_no == "$run_test" ]; then
386
- echo "${test_no}: TESTING ${route_prefix} (all) should pass with smtp available ..."
479
+ echo "${test_no}[line $LINENO]: TESTING ${route_prefix} (all) should pass with smtp available ..."
387
480
  $fake_smtp_server &
388
481
  fake_smtp_pid=$!
389
482
  sleep 5
@@ -394,7 +487,7 @@ common_tests()
394
487
  kill -9 $fake_smtp_pid || echo fake_smtp_server had finished as expected
395
488
  test_no=`expr 1 + $test_no`
396
489
  if [ -z "$run_test" ] || [ $test_no == "$run_test" ]; then
397
- echo "${test_no}: TESTING ${route_prefix}/all should pass with smtp available ..."
490
+ echo "${test_no}[line $LINENO]: TESTING ${route_prefix}/all should pass with smtp available ..."
398
491
  $fake_smtp_server &
399
492
  fake_smtp_pid=$!
400
493
  sleep 5
@@ -404,28 +497,28 @@ common_tests()
404
497
 
405
498
  test_no=`expr 1 + $test_no`
406
499
  if [ -z "$run_test" ] || [ $test_no == "$run_test" ]; then
407
- echo "${test_no}: TESTING ${route_prefix}/pass should pass ..."
500
+ echo "${test_no}[line $LINENO]: TESTING ${route_prefix}/pass should pass ..."
408
501
  $testurl ${host}/${route_prefix}/pass 200 text/plain $success
409
502
  echo
410
503
  fi
411
504
 
412
505
  test_no=`expr 1 + $test_no`
413
506
  if [ -z "$run_test" ] || [ $test_no == "$run_test" ]; then
414
- echo "${test_no}: TESTING ${route_prefix}/custom should pass ..."
507
+ echo "${test_no}[line $LINENO]: TESTING ${route_prefix}/custom should pass ..."
415
508
  $testurl ${host}/${route_prefix}/custom 200 text/plain $success
416
509
  echo
417
510
  fi
418
511
 
419
512
  test_no=`expr 1 + $test_no`
420
513
  if [ -z "$run_test" ] || [ $test_no == "$run_test" ]; then
421
- echo "${test_no}: TESTING ${route_prefix}/custom.html should pass (returning plain text) ..."
514
+ echo "${test_no}[line $LINENO]: TESTING ${route_prefix}/custom.html should pass (returning plain text) ..."
422
515
  $testurl ${host}/${route_prefix}/custom.html 200 text/plain $success
423
516
  echo
424
517
  fi
425
518
 
426
519
  test_no=`expr 1 + $test_no`
427
520
  if [ -z "$run_test" ] || [ $test_no == "$run_test" ]; then
428
- echo "${test_no}: TESTING ${route_prefix}/custom.json should pass ..."
521
+ echo "${test_no}[line $LINENO]: TESTING ${route_prefix}/custom.json should pass ..."
429
522
  $testurl ${host}/${route_prefix}/custom.json 200 application/json '"healthy":true'
430
523
  $testurl ${host}/${route_prefix}/custom.json 200 application/json "\"message\":\"$success\""
431
524
  echo
@@ -433,7 +526,7 @@ common_tests()
433
526
 
434
527
  test_no=`expr 1 + $test_no`
435
528
  if [ -z "$run_test" ] || [ $test_no == "$run_test" ]; then
436
- echo "${test_no}: TESTING ${route_prefix}/custom.xml should pass ..."
529
+ echo "${test_no}[line $LINENO]: TESTING ${route_prefix}/custom.xml should pass ..."
437
530
  $testurl ${host}/${route_prefix}/custom.xml 200 application/xml '<healthy type="boolean">true</healthy>'
438
531
  $testurl ${host}/${route_prefix}/custom.xml 200 application/xml "<message>$success</message>"
439
532
  echo
@@ -442,27 +535,27 @@ common_tests()
442
535
  test_no=`expr 1 + $test_no`
443
536
  rm -f $custom_file
444
537
  if [ -z "$run_test" ] || [ $test_no == "$run_test" ]; then
445
- echo "${test_no}: TESTING ${route_prefix}/custom should fail when custom returns string ..."
538
+ echo "${test_no}[line $LINENO]: TESTING ${route_prefix}/custom should fail when custom returns string ..."
446
539
  $testurl ${host}/${route_prefix}/custom 550 text/plain failed
447
540
  echo
448
541
  fi
449
542
 
450
543
  if [ -z "$run_test" ] || [ $test_no == "$run_test" ]; then
451
- echo "${test_no}: TESTING ${route_prefix}/pass should pass even if other custom test returns string ..."
544
+ echo "${test_no}[line $LINENO]: TESTING ${route_prefix}/pass should pass even if other custom test returns string ..."
452
545
  $testurl ${host}/${route_prefix}/pass 200 text/plain $success
453
546
  echo
454
547
  fi
455
548
 
456
549
  test_no=`expr 1 + $test_no`
457
550
  if [ -z "$run_test" ] || [ $test_no == "$run_test" ]; then
458
- echo "${test_no}: TESTING ${route_prefix} (all) should fail when custom check fails ..."
551
+ echo "${test_no}[line $LINENO]: TESTING ${route_prefix} (all) should fail when custom check fails ..."
459
552
  $testurl ${host}/${route_prefix} 550 text/plain "$custom_file is missing!"
460
553
  echo
461
554
  fi
462
555
 
463
556
  test_no=`expr 1 + $test_no`
464
557
  if [ -z "$run_test" ] || [ $test_no == "$run_test" ]; then
465
- echo "${test_no}: TESTING ${route_prefix}.json (all) should fail when custom check fails ..."
558
+ echo "${test_no}[line $LINENO]: TESTING ${route_prefix}.json (all) should fail when custom check fails ..."
466
559
  $testurl ${host}/${route_prefix}.json 555 application/json '"healthy":false'
467
560
  $testurl ${host}/${route_prefix}.json 555 application/json "$custom_file is missing!"
468
561
  echo
@@ -470,7 +563,7 @@ common_tests()
470
563
 
471
564
  test_no=`expr 1 + $test_no`
472
565
  if [ -z "$run_test" ] || [ $test_no == "$run_test" ]; then
473
- echo "${test_no}: TESTING ${route_prefix}.xml (all) should fail when custom check fails ..."
566
+ echo "${test_no}[line $LINENO]: TESTING ${route_prefix}.xml (all) should fail when custom check fails ..."
474
567
  $testurl ${host}/${route_prefix}.xml 555 application/xml '<healthy type="boolean">false</healthy>'
475
568
  echo
476
569
  fi
@@ -478,10 +571,10 @@ common_tests()
478
571
  test_no=`expr 1 + $test_no`
479
572
  if [ -z "$run_test" ] || [ $test_no == "$run_test" ]; then
480
573
  if $has_middleware; then
481
- echo "${test_no}: TESTING ${route_prefix}/middleware_site should pass ..."
574
+ echo "${test_no}[line $LINENO]: TESTING ${route_prefix}/middleware_site should pass ..."
482
575
  $testurl ${host}/${route_prefix}/middleware_site 200 text/plain $success
483
576
  else
484
- echo "${test_no}: TESTING ${route_prefix}/middleware_site should fail ..."
577
+ echo "${test_no}[line $LINENO]: TESTING ${route_prefix}/middleware_site should fail ..."
485
578
  $testurl ${host}/${route_prefix}/middleware_site 550 text/plain failed
486
579
  fi
487
580
  echo
@@ -489,7 +582,7 @@ common_tests()
489
582
 
490
583
  test_no=`expr 1 + $test_no`
491
584
  if [ -z "$run_test" ] || [ $test_no == "$run_test" ]; then
492
- echo "${test_no}: TESTING log files to check for deprecation warnings ..."
585
+ echo "${test_no}[line $LINENO]: TESTING log files to check for deprecation warnings ..."
493
586
  if egrep ' is deprecated|DEPRECATION WARNING' $railsapp/log/[tp][er][so][td]*.log
494
587
  then
495
588
  echo Found deprecation warnings - failed test