kapnismology 1.12.0 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: cc04d3c658e30139dbf0adf893088832ba05706e
4
- data.tar.gz: a0b1a9b1050c75aa6907b3cf17a63dd63020ee71
3
+ metadata.gz: 1cbf3d487a4c5443e4d4cb4fd5cc77f432ed4954
4
+ data.tar.gz: 1e5c71a2f44f9da570c420ead7ff56e1b2445a4b
5
5
  SHA512:
6
- metadata.gz: 571e122ee54a4a433f02afc0c1b1d743d36c2eaada3375774dd454c0b0129826616171dfb1bad8862489bdcea4c26d5fadc2f8fc19e1e8b9d3f8f1d95adf32e9
7
- data.tar.gz: 126db5d5528ef6b4ec271d63ab5180892db62a7263f9e69b54d6e4d462125d8c77aad047b200c7b38398a99a396456767d2f16dea5115f9c56f94ce4c6da9bad
6
+ metadata.gz: 4cacad590a7220d64e4194abf8eefa561a550ec5d1d37fd08215ec4795f7e413acba81edd2ce7bb91db2d589f4f07d5ee89c5613a1dc1250769655d032b0bce2
7
+ data.tar.gz: e011b97bd0d5f35db1fa08bd37e57db69ef7c29097deef445e7e54c31a13d5a57d71045dc010a427d2f6ba03256b9e2575b5b4c519e9d063eb344ec04e52b16d
data/README.md CHANGED
@@ -5,13 +5,13 @@ Kapnismology 'the study of smoke', is a gem containing a Rails engine to easily
5
5
  ## Installation
6
6
 
7
7
  In the Gemfile write:
8
- ```
8
+ ```ruby
9
9
  gem 'kapnismology', '~> 1.7'
10
10
  ```
11
11
 
12
12
  In your config/routes write:
13
13
 
14
- ```
14
+ ```ruby
15
15
  Kapnismology::Routes.insert!('/smoke_test')
16
16
  ```
17
17
 
@@ -19,11 +19,48 @@ In your config/routes write:
19
19
 
20
20
  Access the path '/smoke_test' to see the results of the smoke_test
21
21
 
22
+ ## Smoke test output format
23
+
24
+ The output of the /smoke_test path is a Hypermedia document.
25
+
26
+ Sample:
27
+
28
+ ```ruby
29
+ {
30
+ "_links": {
31
+ "self": "https://www.example.org/smoke_test?tags=runtime",
32
+ "profile": "http://tbd.mdsol.com"
33
+ },
34
+ "passed": false,
35
+ "count": 2,
36
+ "trace_id": "d93abb9f-e0a2-467b-902f-b78069167e8f",
37
+ "items": [
38
+ {
39
+ "name": "database_smoke_test",
40
+ "passed": true,
41
+ "message": "The database is connected and responding correctly.",
42
+ "data": {
43
+ "database_name": "Polybus"
44
+ }
45
+ },
46
+ {
47
+ "name": "api_smoke_test",
48
+ "passed": false,
49
+ "message": "Api failed to respond correctly.",
50
+ "data": {
51
+ "exception": "name of exception class (StandardError, NoMethodError)",
52
+ "message": "exception message",
53
+ "stack": ["array of strings", "containing the backtrace","one string per backtrace entry"]
54
+ }
55
+ }
56
+ ]
57
+ }
58
+ ```
22
59
 
23
60
  ## Adding more smoke tests
24
61
 
25
62
  Create a class like this:
26
- ```
63
+ ```ruby
27
64
  class MySmokeTest < Kapnismology::SmokeTest
28
65
 
29
66
  def result
@@ -47,8 +84,8 @@ A test fails if it returns:
47
84
 
48
85
  Any class created this way will be called and its result will be merged with other results.
49
86
  In the example above the result of this class would be added to the results as:
50
- ```
51
- {'MySmokeTest': { passed: true, data: { connection: 'good' }, message: 'Connected!' }}
87
+ ```ruby
88
+ { name: 'my_smoke_test', passed: true, data: { connection: 'good' }, message: 'Connected!' }
52
89
  ```
53
90
 
54
91
  ## Loading tests
@@ -74,24 +111,10 @@ end
74
111
 
75
112
  Will produce:
76
113
  ```ruby
77
- {'Database smoke test': { passed: true, data: { connection: 'good' }, message: 'Connected!' }}
78
-
79
- ```
114
+ { name: 'database smoke test', passed: true, data: { connection: 'good' }, message: 'Connected!' }
80
115
 
81
- ## Not runnable tests
82
-
83
- If your check finds a situation when it does not make sense to test, you can return a `InfoResult` instead of a `Result`. Like:
84
- ```ruby
85
- if (File.exist?('necessary file'))
86
- Result.new(....)
87
- else
88
- InfoResult.new({}, 'There is no need to run this test')
89
- end
90
116
  ```
91
117
 
92
- Be very careful of not returning InfoResult when you should be returning a failing Result.
93
-
94
-
95
118
  ## Tagging and running tags
96
119
 
97
120
  All smoke tests are tagged by default with 'deployment' and 'runtime'.
@@ -147,7 +170,7 @@ For instance:
147
170
 
148
171
  Hopefully Kapnismology is flexible enough so you can code your smoke test as you prefer, our recommended style is this:
149
172
 
150
- ```
173
+ ```ruby
151
174
  def result
152
175
  user = user_from_remote
153
176
  puts_to_result('User successfully retrieved')
@@ -178,7 +201,7 @@ You can pass your own data to SmokeTestFailed or you can pass an exception which
178
201
 
179
202
  There is a Kapnismology::SpecHelper which can be useful when running your tests.
180
203
  Usage:
181
- ```
204
+ ```ruby
182
205
  RSpec.describe DatabaseSmokeTest do
183
206
  let(:result) { Kapnismology::SpecHelper.result_for(described_class.new) }
184
207
  ...
@@ -2,9 +2,11 @@ module Kapnismology
2
2
  # This is called when the user goes to the /smoke_test URL. This calls all the
3
3
  # smoke tests registered in the application and gather the results
4
4
  class SmokeTestsController < ApplicationController
5
+ PROFILE_URL = 'http://tbd.mdsol.com'.freeze
6
+
5
7
  def index
6
8
  evaluations = SmokeTestCollection.evaluations(allowed_tags, blacklist)
7
- render json: evaluations.to_json, status: status(evaluations)
9
+ render json: results(evaluations).to_json, status: status(evaluations)
8
10
  end
9
11
 
10
12
  private
@@ -24,5 +26,19 @@ module Kapnismology
24
26
  :service_unavailable
25
27
  end
26
28
  end
29
+
30
+ def results(evaluations)
31
+ items = evaluations.as_json.select { |e| e.has_key?(:passed) }
32
+ {
33
+ _links: {
34
+ self: CGI.unescape(request.original_url),
35
+ profile: PROFILE_URL
36
+ },
37
+ passed: evaluations.passed?,
38
+ count: items.size,
39
+ trace_id: Object.const_defined?(:Trace) ? Trace.id.trace_id.to_s : nil,
40
+ items: items
41
+ }
42
+ end
27
43
  end
28
44
  end
@@ -15,7 +15,7 @@ module Kapnismology
15
15
  end
16
16
 
17
17
  def as_json(_options = nil)
18
- { @name => @result.to_hash }
18
+ { name: @name.underscore }.merge(@result.to_hash)
19
19
  end
20
20
 
21
21
  def to_s
@@ -3,21 +3,21 @@ module Kapnismology
3
3
  # It is useful to be able to test if the object is of a correct result type.
4
4
  # It also have methods to add information and serialize it.
5
5
  class BaseResult
6
- attr_reader :data, :message, :extra_messages # Deprecated but many users test on these properties
6
+ attr_reader :data, :message, :debug_messages
7
7
  def to_hash
8
- { passed: passed?, data: @data, message: @message, extra_messages: @extra_messages }
8
+ { passed: passed?, data: @data, message: @message, debug_messages: @debug_messages }
9
9
  end
10
10
 
11
11
  def to_s(name)
12
12
  <<-eos
13
13
  #{format_passed(passed?)}: #{name}
14
- #{format_extra_messages(@extra_messages)}#{Terminal.bold(@message)}
14
+ #{format_debug_messages(@debug_messages)}#{Terminal.bold(@message)}
15
15
  #{@data}
16
16
  eos
17
17
  end
18
18
 
19
- def add_extra_messages(messages)
20
- @extra_messages = (messages || []).compact.flatten
19
+ def add_debug_messages(messages)
20
+ @debug_messages = (messages || []).compact.flatten
21
21
  self
22
22
  end
23
23
 
@@ -27,11 +27,11 @@ eos
27
27
 
28
28
  private
29
29
 
30
- def format_extra_messages(extra_messages)
31
- if extra_messages.empty?
30
+ def format_debug_messages(debug_messages)
31
+ if debug_messages.empty?
32
32
  ''
33
33
  else
34
- extra_messages.join("\n") + "\n"
34
+ debug_messages.join("\n") + "\n"
35
35
  end
36
36
  end
37
37
 
@@ -52,23 +52,29 @@ eos
52
52
  @passed = passed
53
53
  @data = data
54
54
  @message = message
55
- @extra_messages = []
55
+ @debug_messages = []
56
56
  end
57
57
  end
58
58
 
59
- # This class can be returned when a check do not want to assert if it passed or not.
60
- # Instead it can return certain information about the check or the system.
61
- class InfoResult < BaseResult
59
+ # Deprecated NullResult class provided for compatibility.
60
+ class NullResult < BaseResult
62
61
  def initialize(data, message = 'The result could not be determined')
63
62
  @passed = true
64
63
  @data = data
65
64
  @message = message
66
- @extra_messages = []
65
+ @debug_messages = []
67
66
  end
68
67
 
69
- # Redefining to have our own unique output
68
+ def to_s(name)
69
+ <<-eos
70
+ #{Terminal.yellow('This test can not be run. Skipping...')}
71
+ #{super(name).chomp}
72
+ eos
73
+ end
74
+
75
+ # Nullresult does not output any data.
70
76
  def to_hash
71
- { data: @data, message: @message, extra_messages: @extra_messages }
77
+ {}
72
78
  end
73
79
 
74
80
  private
@@ -78,10 +84,6 @@ eos
78
84
  end
79
85
  end
80
86
 
81
- # Deprecated NullResult class provided for compatibility.
82
- class NullResult < InfoResult
83
- end
84
-
85
87
  class NotApplicableResult < BaseResult
86
88
  end
87
89
 
@@ -92,7 +94,7 @@ eos
92
94
  @passed = true
93
95
  @data = data
94
96
  @message = message
95
- @extra_messages = []
97
+ @debug_messages = []
96
98
  end
97
99
  end
98
100
  end
@@ -32,7 +32,7 @@ module Kapnismology
32
32
  message = "Unrescued error happened in #{self.class}"
33
33
  result_object = Result.new(false, { exception: e.class, message: e.message }, message)
34
34
  ensure
35
- return result_object.add_extra_messages(@all_result_messages)
35
+ return result_object.add_debug_messages(@all_result_messages)
36
36
  end
37
37
 
38
38
  class << self
@@ -59,8 +59,6 @@ module Kapnismology
59
59
  # These classes makes it very simple to implementors of results to use them without the module name
60
60
  class Result < Kapnismology::Result
61
61
  end
62
- class InfoResult < Kapnismology::InfoResult
63
- end
64
62
  class NullResult < Kapnismology::NullResult
65
63
  end
66
64
  class Success < Kapnismology::Success
@@ -2,13 +2,13 @@ require 'kapnismology/result'
2
2
 
3
3
  module Kapnismology
4
4
  class RSpecResult < BaseResult
5
- attr_reader :data, :message, :extra_messages # Deprecated but many users test on these properties
5
+ attr_reader :data, :message, :debug_messages
6
6
  def initialize(result)
7
7
  hash = result.to_hash
8
8
  @data = hash[:data]
9
9
  @message = hash[:message]
10
10
  @passed = hash[:passed]
11
- @extra_messages = hash[:extra_messages]
11
+ @debug_messages = hash[:debug_messages]
12
12
  end
13
13
  end
14
14
 
@@ -1,3 +1,3 @@
1
1
  module Kapnismology
2
- VERSION = '1.12.0'.freeze
2
+ VERSION = '2.0.0'.freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kapnismology
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.12.0
4
+ version: 2.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jordi Polo Carres
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-05-28 00:00:00.000000000 Z
11
+ date: 2016-07-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails