kapnismology 2.4.1 → 2.6.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
  SHA256:
3
- metadata.gz: 432ba59104db7f2e855bcfb9c43d7d82861a13691e3abeeed2da3e1258aa2343
4
- data.tar.gz: e61f72fd371176d1d76451ff9b83748668b68ba2a76de6afb8ba16b44f8f9f8f
3
+ metadata.gz: 8eb5fe1d158d622fa0119a80efe3b816aeddf4cd0c7d0a965140c5889c258ab7
4
+ data.tar.gz: 3edf154c21c793c78bc53fbcca442409bd7827cd9a2ab78599f0255c9ba179a1
5
5
  SHA512:
6
- metadata.gz: a6dc6c24e8f5d1218c3731c9774f2c1e2a2318a9b4025fa591de690bd26aa20db8b056cb02537c70d099199fdd81e8951ea21d4e03865b9248b833694eca9cc9
7
- data.tar.gz: 436333b7043a832591af145cdfeea106fdfb004a00f91d5d75b53ea0ec442264e052d6ca01d85d47c38325aea70f31fbc0f229317260f62cf03c32ad02d25ccc
6
+ metadata.gz: a136af17d09e21c00e332b3740ad6678201be581b67dc6950d43163b5863bf5726ba0d5923242501414815c20bf61edb56f1d0a004f1038187498368721081ff
7
+ data.tar.gz: de593e01436167c00dbb5050cedc65471c29dae5938bbe37d585ad5c70fb2ef42c15b47d984e5ce77336f0e78972ad8a18ab90f3a4773f290ff58e88e2f57fb9
data/README.md CHANGED
@@ -38,7 +38,6 @@ Sample:
38
38
  },
39
39
  "passed": false,
40
40
  "count": 2,
41
- "trace_id": "d93abb9f-e0a2-467b-902f-b78069167e8f",
42
41
  "codebase_revision": "7beb617",
43
42
  "items": [
44
43
  {
@@ -2,7 +2,6 @@ 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
-
6
5
  def index
7
6
  response = SmokeTestResponse.new(SmokeTestCollection.evaluations(allowed_tags, blacklist))
8
7
  render json: response.render(request.original_url), status: response.status
@@ -18,5 +17,4 @@ module Kapnismology
18
17
  params[:skip].to_s.split(',')
19
18
  end
20
19
  end
21
-
22
20
  end
@@ -1,47 +1,54 @@
1
1
  require "json"
2
+ require "singleton"
2
3
 
3
4
  module Kapnismology
4
5
  # This class provides information about the running environment the smoketest is being
5
6
  # executed under.
6
7
  class ApplicationInformation
7
- GIT_SHOW_COMMAND = "git show HEAD --abbrev-commit --oneline 2>/dev/null".freeze
8
+ include Singleton
9
+
10
+ GIT_COMMAND = "git rev-parse --short HEAD 2>/dev/null".freeze
8
11
  ECS_CONTAINER_METADATA_FILE = ENV["ECS_CONTAINER_METADATA_FILE"].freeze
12
+ KUBERNETES_ANNOTATIONS_FILE = "/etc/podinfo/annotations".freeze
9
13
  INFO_UNKNOWN = "".freeze
10
14
 
11
- def trace_id
12
- Object.const_defined?(:Trace) ? Trace.id.trace_id.to_s : INFO_UNKNOWN
13
- end
14
-
15
15
  def codebase_revision
16
- ref = latest_commit_info
17
- ref ? ref.split(/\s/).first : INFO_UNKNOWN
18
- rescue Errno::ENOENT, StandardError
19
- INFO_UNKNOWN
16
+ @codebase_revision ||= begin
17
+ latest_commit_info[0...7]
18
+ rescue Errno::ENOENT, StandardError
19
+ INFO_UNKNOWN
20
+ end
20
21
  end
21
22
 
22
23
  private
23
24
 
24
25
  def latest_commit_info
25
- latest_ref_from_git || latest_ref_from_ecs_metadata || nil
26
+ latest_sha_from_ecs_metadata || latest_sha_from_k8s_annotations || latest_sha_from_git || INFO_UNKNOWN
26
27
  end
27
28
 
28
- def latest_ref_from_git
29
- result = `#{GIT_SHOW_COMMAND}`
29
+ def latest_sha_from_git
30
+ result = `#{GIT_COMMAND}`
30
31
  $?.success? ? result : nil
31
32
  end
32
33
 
33
- # This assumes the ImageName features the git ref as the last part of a string delimited by dots.
34
+ # This assumes the ImageName features the git sha as the last part of a string delimited by dots.
34
35
  # See spec/support/ecs_metadata.json as well as
35
36
  # https://docs.aws.amazon.com/AmazonECS/latest/developerguide/container-metadata.html
36
- def latest_ref_from_ecs_metadata
37
- return if ECS_CONTAINER_METADATA_FILE.nil?
38
- return unless !ECS_CONTAINER_METADATA_FILE.strip.empty? && File.readable?(ECS_CONTAINER_METADATA_FILE)
37
+ def latest_sha_from_ecs_metadata
38
+ return nil if ECS_CONTAINER_METADATA_FILE.nil?
39
+ return nil unless !ECS_CONTAINER_METADATA_FILE.strip.empty? && File.readable?(ECS_CONTAINER_METADATA_FILE)
39
40
 
40
41
  begin
41
- JSON.parse(File.read(ECS_CONTAINER_METADATA_FILE))["ImageName"].split(".").last[0...7]
42
+ JSON.parse(File.read(ECS_CONTAINER_METADATA_FILE))["ImageName"].split(".").last
42
43
  rescue JSON::ParserError
43
44
  nil
44
45
  end
45
46
  end
47
+
48
+ def latest_sha_from_k8s_annotations
49
+ return nil unless File.readable?(KUBERNETES_ANNOTATIONS_FILE)
50
+
51
+ File.read(KUBERNETES_ANNOTATIONS_FILE).scan(/gitSha="(.+)"$/).last&.first
52
+ end
46
53
  end
47
54
  end
@@ -21,6 +21,7 @@ if defined?(Rails)
21
21
  if defined?(Kapnismology) == false
22
22
  raise 'require kapnismology before trying to insert routes'
23
23
  end
24
+
24
25
  Rails.application.routes.draw do
25
26
  mount Kapnismology::Engine, at: path
26
27
  end
@@ -5,6 +5,7 @@ module Kapnismology
5
5
  # Mapping of test_name => returned result for each smoke test
6
6
  class Evaluation
7
7
  attr_reader :result
8
+
8
9
  def initialize(test_class)
9
10
  @name = test_class.name.split('::').last
10
11
  @result = test_class.new.__result__
@@ -25,6 +26,5 @@ module Kapnismology
25
26
  def duration
26
27
  @result.duration
27
28
  end
28
-
29
29
  end
30
30
  end
@@ -10,9 +10,7 @@ module Kapnismology
10
10
  end
11
11
 
12
12
  def each(&_block)
13
- evaluations.each do |member|
14
- yield(member)
15
- end
13
+ evaluations.each(&_block)
16
14
  end
17
15
 
18
16
  def passed?
@@ -30,10 +28,9 @@ module Kapnismology
30
28
  private
31
29
 
32
30
  def evaluations
33
- @evaluations ||= @smoke_tests_classes.inject([]) do |memo, klass|
31
+ @evaluations ||= @smoke_tests_classes.each_with_object([]) do |klass, memo|
34
32
  evaluation = Evaluation.new(klass)
35
- memo << evaluation if !evaluation.result.class.ancestors.include?(Kapnismology::NotApplicableResult)
36
- memo
33
+ memo << evaluation unless evaluation.result.class.ancestors.include?(Kapnismology::NotApplicableResult)
37
34
  end
38
35
  end
39
36
  end
@@ -2,7 +2,7 @@ require 'kapnismology/terminal'
2
2
  module Kapnismology
3
3
  class RakeTask
4
4
  def output(allowed_tags = [SmokeTest::RUNTIME_TAG], blacklist = [])
5
- puts "Running smoke test for codebase revision #{ApplicationInformation.new.codebase_revision}"
5
+ puts "Running smoke test for codebase revision #{ApplicationInformation.new.codebase_revision}"
6
6
  evaluations = SmokeTestCollection.evaluations(allowed_tags, blacklist)
7
7
  puts
8
8
  puts
@@ -4,16 +4,17 @@ module Kapnismology
4
4
  # It also have methods to add information and serialize it.
5
5
  class BaseResult
6
6
  attr_reader :data, :message, :debug_messages, :duration
7
+
7
8
  def to_hash
8
9
  { passed: passed?, data: @data, message: @message, debug_messages: @debug_messages, duration: @duration }
9
10
  end
10
11
 
11
12
  def to_s(name)
12
- <<-eos
13
- #{format_passed(passed?)}: #{name}
14
- #{format_duration(@duration)}#{format_debug_messages(@debug_messages)}#{Terminal.bold(@message)}
15
- #{@data}
16
- eos
13
+ <<~EOS
14
+ #{format_passed(passed?)}: #{name}
15
+ #{format_duration(@duration)}#{format_debug_messages(@debug_messages)}#{Terminal.bold(@message)}
16
+ #{@data}
17
+ EOS
17
18
  end
18
19
 
19
20
  def add_debug_messages(messages)
@@ -58,6 +59,7 @@ eos
58
59
  def initialize(passed, data, message)
59
60
  raise ArgumentError, 'passed argument must be true or false' unless !!passed == passed
60
61
  raise ArgumentError, 'data argument must be a hash' unless data.is_a?(Hash)
62
+
61
63
  @passed = passed
62
64
  @data = data
63
65
  @message = message
@@ -77,10 +79,10 @@ eos
77
79
  end
78
80
 
79
81
  def to_s(name)
80
- <<-eos
81
- #{Terminal.yellow('This test can not be run. Skipping...')}
82
- #{super(name).chomp}
83
- eos
82
+ <<~EOS
83
+ #{Terminal.yellow('This test can not be run. Skipping...')}
84
+ #{super(name).chomp}
85
+ EOS
84
86
  end
85
87
 
86
88
  # Nullresult does not output any data.
@@ -103,6 +105,7 @@ eos
103
105
  class Success < BaseResult
104
106
  def initialize(data, message)
105
107
  raise ArgumentError, 'data argument must be a hash' unless data.is_a?(Hash)
108
+
106
109
  @passed = true
107
110
  @data = data
108
111
  @message = message
@@ -13,13 +13,12 @@ module Kapnismology
13
13
  RUNTIME_TAG = 'runtime'.freeze
14
14
  DEFAULT_TAGS = [DEPLOYMENT_TAG, RUNTIME_TAG].freeze
15
15
 
16
- def result
17
- end
16
+ def result; end
18
17
 
19
18
  # Internally Kapnismology is calling this method. We are handling exceptions under the hood here
20
19
  def __result__
21
20
  start_time = Time.now
22
- execution = Timeout::timeout(self.class.timeout) { result }
21
+ execution = Timeout.timeout(self.class.timeout) { result }
23
22
  result_object = execution || Result.new(false, {}, 'This test has not returned any result')
24
23
  unless result_object.class.ancestors.include?(BaseResult)
25
24
  message = "Smoke test #{self.class}, returned #{result_object.class} instead of a Result"
@@ -63,12 +62,14 @@ module Kapnismology
63
62
  # These classes makes it very simple to implementors of results to use them without the module name
64
63
  class Result < Kapnismology::Result
65
64
  end
65
+
66
66
  class NullResult < Kapnismology::NullResult
67
67
  end
68
+
68
69
  class Success < Kapnismology::Success
69
70
  end
71
+
70
72
  class SmokeTestFailed < Kapnismology::SmokeTestFailed
71
73
  end
72
-
73
74
  end
74
75
  end
@@ -1,13 +1,12 @@
1
1
  module Kapnismology
2
-
3
2
  # This class can be raised to make Kapnismology create a failed result from your smoke test
4
3
  class SmokeTestFailed < StandardError
5
4
  def initialize(data, message)
6
5
  @data = if data.class.ancestors.include?(Exception)
7
- { exception: data.class, message: data.message }
8
- else
9
- data
10
- end
6
+ { exception: data.class, message: data.message }
7
+ else
8
+ data
9
+ end
11
10
  @message = message
12
11
  end
13
12
 
@@ -1,7 +1,6 @@
1
1
  module Kapnismology
2
2
  # A summary of a run containing smoke test evaluations
3
3
  class SmokeTestResponse
4
-
5
4
  PROFILE_URL = 'http://tbd.mdsol.com'.freeze
6
5
 
7
6
  def initialize(evaluations)
@@ -21,12 +20,10 @@ module Kapnismology
21
20
  },
22
21
  passed: @evaluations.passed?,
23
22
  count: items.size,
24
- trace_id: ApplicationInformation.new.trace_id,
25
- codebase_revision: ApplicationInformation.new.codebase_revision,
23
+ codebase_revision: ApplicationInformation.instance.codebase_revision,
26
24
  duration: @evaluations.total_duration,
27
25
  items: items
28
26
  }.to_json
29
27
  end
30
-
31
28
  end
32
29
  end
@@ -3,6 +3,7 @@ require 'kapnismology/result'
3
3
  module Kapnismology
4
4
  class RSpecResult < BaseResult
5
5
  attr_reader :data, :message, :debug_messages
6
+
6
7
  def initialize(result)
7
8
  hash = result.to_hash
8
9
  @data = hash[:data]
@@ -16,7 +16,6 @@ module Kapnismology
16
16
  colorize(msg, '')
17
17
  end
18
18
 
19
- private
20
19
  def self.colorize(msg, color_code)
21
20
  # \e[1m adds bold font, \e[0m resets all styles
22
21
  $stdout.isatty ? "#{color_code}\e[1m#{msg}\e[0m" : msg
@@ -1,3 +1,3 @@
1
1
  module Kapnismology
2
- VERSION = '2.4.1'.freeze
2
+ VERSION = '2.6.0'.freeze
3
3
  end
metadata CHANGED
@@ -1,71 +1,85 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kapnismology
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.4.1
4
+ version: 2.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jordi Polo Carres
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-04-17 00:00:00.000000000 Z
11
+ date: 2023-06-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: rails
14
+ name: actionpack
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: 3.2.22
19
+ version: '6.0'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: 3.2.22
26
+ version: '6.0'
27
27
  - !ruby/object:Gem::Dependency
28
- name: rspec
28
+ name: appraisal
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '3.5'
33
+ version: '2.1'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '3.5'
40
+ version: '2.1'
41
41
  - !ruby/object:Gem::Dependency
42
- name: rspec-json_expectations
42
+ name: byebug
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: '1.4'
47
+ version: '10'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: '1.4'
54
+ version: '10'
55
55
  - !ruby/object:Gem::Dependency
56
- name: byebug
56
+ name: capybara
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
59
  - - "~>"
60
60
  - !ruby/object:Gem::Version
61
- version: '10'
61
+ version: '3.5'
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
- version: '10'
68
+ version: '3.5'
69
+ - !ruby/object:Gem::Dependency
70
+ name: combustion
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '1.0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '1.0'
69
83
  - !ruby/object:Gem::Dependency
70
84
  name: mutant
71
85
  requirement: !ruby/object:Gem::Requirement
@@ -95,75 +109,75 @@ dependencies:
95
109
  - !ruby/object:Gem::Version
96
110
  version: '0.8'
97
111
  - !ruby/object:Gem::Dependency
98
- name: appraisal
112
+ name: rspec
99
113
  requirement: !ruby/object:Gem::Requirement
100
114
  requirements:
101
115
  - - "~>"
102
116
  - !ruby/object:Gem::Version
103
- version: '2.1'
117
+ version: '3.5'
104
118
  type: :development
105
119
  prerelease: false
106
120
  version_requirements: !ruby/object:Gem::Requirement
107
121
  requirements:
108
122
  - - "~>"
109
123
  - !ruby/object:Gem::Version
110
- version: '2.1'
124
+ version: '3.5'
111
125
  - !ruby/object:Gem::Dependency
112
- name: combustion
126
+ name: rspec-json_expectations
113
127
  requirement: !ruby/object:Gem::Requirement
114
128
  requirements:
115
129
  - - "~>"
116
130
  - !ruby/object:Gem::Version
117
- version: '1.0'
131
+ version: '2.2'
118
132
  type: :development
119
133
  prerelease: false
120
134
  version_requirements: !ruby/object:Gem::Requirement
121
135
  requirements:
122
136
  - - "~>"
123
137
  - !ruby/object:Gem::Version
124
- version: '1.0'
138
+ version: '2.2'
125
139
  - !ruby/object:Gem::Dependency
126
- name: sqlite3
140
+ name: rubocop
127
141
  requirement: !ruby/object:Gem::Requirement
128
142
  requirements:
129
143
  - - "~>"
130
144
  - !ruby/object:Gem::Version
131
- version: 1.3.6
145
+ version: '1.42'
132
146
  type: :development
133
147
  prerelease: false
134
148
  version_requirements: !ruby/object:Gem::Requirement
135
149
  requirements:
136
150
  - - "~>"
137
151
  - !ruby/object:Gem::Version
138
- version: 1.3.6
152
+ version: '1.42'
139
153
  - !ruby/object:Gem::Dependency
140
- name: capybara
154
+ name: rubocop-mdsol
141
155
  requirement: !ruby/object:Gem::Requirement
142
156
  requirements:
143
157
  - - "~>"
144
158
  - !ruby/object:Gem::Version
145
- version: '2.10'
159
+ version: '0.1'
146
160
  type: :development
147
161
  prerelease: false
148
162
  version_requirements: !ruby/object:Gem::Requirement
149
163
  requirements:
150
164
  - - "~>"
151
165
  - !ruby/object:Gem::Version
152
- version: '2.10'
166
+ version: '0.1'
153
167
  - !ruby/object:Gem::Dependency
154
- name: timecop
168
+ name: rubocop-performance
155
169
  requirement: !ruby/object:Gem::Requirement
156
170
  requirements:
157
171
  - - "~>"
158
172
  - !ruby/object:Gem::Version
159
- version: '0.7'
173
+ version: '1.15'
160
174
  type: :development
161
175
  prerelease: false
162
176
  version_requirements: !ruby/object:Gem::Requirement
163
177
  requirements:
164
178
  - - "~>"
165
179
  - !ruby/object:Gem::Version
166
- version: '0.7'
180
+ version: '1.15'
167
181
  - !ruby/object:Gem::Dependency
168
182
  name: simplecov
169
183
  requirement: !ruby/object:Gem::Requirement
@@ -178,6 +192,34 @@ dependencies:
178
192
  - - "~>"
179
193
  - !ruby/object:Gem::Version
180
194
  version: '0.16'
195
+ - !ruby/object:Gem::Dependency
196
+ name: sqlite3
197
+ requirement: !ruby/object:Gem::Requirement
198
+ requirements:
199
+ - - "~>"
200
+ - !ruby/object:Gem::Version
201
+ version: '1.4'
202
+ type: :development
203
+ prerelease: false
204
+ version_requirements: !ruby/object:Gem::Requirement
205
+ requirements:
206
+ - - "~>"
207
+ - !ruby/object:Gem::Version
208
+ version: '1.4'
209
+ - !ruby/object:Gem::Dependency
210
+ name: timecop
211
+ requirement: !ruby/object:Gem::Requirement
212
+ requirements:
213
+ - - "~>"
214
+ - !ruby/object:Gem::Version
215
+ version: '0.7'
216
+ type: :development
217
+ prerelease: false
218
+ version_requirements: !ruby/object:Gem::Requirement
219
+ requirements:
220
+ - - "~>"
221
+ - !ruby/object:Gem::Version
222
+ version: '0.7'
181
223
  description: Engine for smoke tests and base classes
182
224
  email:
183
225
  - mumismo@gmail.com
@@ -207,7 +249,7 @@ homepage: https://github.com/JordiPolo/kapnismology
207
249
  licenses:
208
250
  - MIT
209
251
  metadata: {}
210
- post_install_message:
252
+ post_install_message:
211
253
  rdoc_options: []
212
254
  require_paths:
213
255
  - lib
@@ -215,15 +257,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
215
257
  requirements:
216
258
  - - ">="
217
259
  - !ruby/object:Gem::Version
218
- version: 2.3.0
260
+ version: 2.7.0
219
261
  required_rubygems_version: !ruby/object:Gem::Requirement
220
262
  requirements:
221
263
  - - ">="
222
264
  - !ruby/object:Gem::Version
223
265
  version: '0'
224
266
  requirements: []
225
- rubygems_version: 3.0.2
226
- signing_key:
267
+ rubygems_version: 3.2.15
268
+ signing_key:
227
269
  specification_version: 4
228
270
  summary: Engine for smoke tests.
229
271
  test_files: []