inferno_core 0.4.36 → 0.4.37.dev

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,171 @@
1
+ require_relative '../repositories/test_kits'
2
+ require_relative '../repositories/test_suites'
3
+
4
+ module Inferno
5
+ module Entities
6
+ # @example
7
+ #
8
+ # module USCoreTestKit
9
+ # class TestKit < Inferno::Entities::TestKit
10
+ # id :us_core
11
+ # title 'US Core Test Kit'
12
+ # description <<~DESCRIPTION
13
+ # This is a big markdown description of the test kit.
14
+ # DESCRIPTION
15
+ # suite_ids ['us_core_v311', 'us_core_v400', 'us_core_v501', 'us_core_v610']
16
+ # tags ['SMART App Launch', 'US Core']
17
+ # last_updated '2024-03-07'
18
+ # version '0.6.4'
19
+ # maturity 'High'
20
+ # authors ['Author One', 'Author Two']
21
+ # repo 'https://github.com/inferno-framework/us-core-test-kit'
22
+ # end
23
+ # end
24
+ class TestKit
25
+ class << self
26
+ def inherited(inheriting_class)
27
+ super
28
+ inheriting_class.define_singleton_method(:inherited) do |subclass|
29
+ copy_instance_variables(subclass)
30
+ end
31
+ end
32
+
33
+ # Set/get the id for the test kit
34
+ #
35
+ # @param new_id [Symbol, String]
36
+ # @return [Symbol, String]
37
+ def id(new_id = nil)
38
+ return @id if new_id.nil?
39
+
40
+ @id = new_id
41
+ end
42
+
43
+ # Set/get the title for the test kit
44
+ #
45
+ # @param new_title [String]
46
+ # @return [String]
47
+ def title(new_title = nil)
48
+ return @title if new_title.nil?
49
+
50
+ @title = new_title
51
+ end
52
+
53
+ # Set/get the description for the test kit
54
+ #
55
+ # @param new_description [String]
56
+ # @return [String]
57
+ def description(new_description = nil)
58
+ return @description if new_description.nil?
59
+
60
+ @description = new_description
61
+ end
62
+
63
+ # Set/get the tags for the test kit
64
+ #
65
+ # @param new_tags [Array<String>]
66
+ # @return [Array<String>]
67
+ def tags(new_tags = nil)
68
+ return @tags if new_tags.nil?
69
+
70
+ @tags = new_tags
71
+ end
72
+
73
+ # Set/get the last updated date for the test kit
74
+ #
75
+ # @param new_last_updated [String]
76
+ # @return [String]
77
+ def last_updated(new_last_updated = nil)
78
+ return @last_updated if new_last_updated.nil?
79
+
80
+ @last_updated = new_last_updated
81
+ end
82
+
83
+ # Set/get the version for the test kit
84
+ #
85
+ # @param new_version [String]
86
+ # @return [String]
87
+ def version(new_version = nil)
88
+ return @version if new_version.nil?
89
+
90
+ @version = new_version
91
+ end
92
+
93
+ # Set/get the maturity level for the test kit
94
+ #
95
+ # @param new_maturity [String]
96
+ # @return [String]
97
+ def maturity(new_maturity = nil)
98
+ return @maturity if new_maturity.nil?
99
+
100
+ @maturity = new_maturity
101
+ end
102
+
103
+ # Set/get the suite ids for the test kit
104
+ #
105
+ # @param new_ids [Array<Symbol,String>]
106
+ # @return [Array<Symbol,String>]
107
+ def suite_ids(new_ids = nil)
108
+ return @suite_ids || [] if new_ids.nil?
109
+
110
+ @suite_ids = new_ids
111
+ end
112
+
113
+ # Set/get the code repository url for the test kit
114
+ #
115
+ # @param new_repo [String]
116
+ # @return [String]
117
+ def repo(new_repo = nil)
118
+ return @repo if new_repo.nil?
119
+
120
+ @repo = new_repo
121
+ end
122
+
123
+ # Set/get the list of authors for the test kit
124
+ #
125
+ # @param new_authors [Array<String>]
126
+ # @return [Array<String>]
127
+ def authors(new_authors = nil)
128
+ return @authors if new_authors.nil?
129
+
130
+ @authors = new_authors
131
+ end
132
+
133
+ # Get the suites whose ids are defined in `suite_ids`
134
+ #
135
+ # @return [Array<Inferno::Entities::TestSuite>]
136
+ def suites
137
+ return @suites if @suites.present?
138
+
139
+ repo = Inferno::Repositories::TestSuites.new
140
+ @suites = suite_ids.map { |id| repo.find(id) }
141
+ end
142
+
143
+ # Get the options for the suites in the test kit
144
+ #
145
+ # @return [Hash{Symbol,String=>Array<Inferno::DSL::SuiteOption>}]
146
+ def options
147
+ return @options if @options.present?
148
+
149
+ @options = suites.each_with_object({}) { |suite, hash| hash[suite.id] = suite.suite_options }
150
+ end
151
+
152
+ # @private
153
+ def add_self_to_repository
154
+ repository.insert(self)
155
+ end
156
+
157
+ # @private
158
+ def repository
159
+ @repository ||= Inferno::Repositories::TestKits
160
+ end
161
+
162
+ # @private
163
+ def copy_instance_variables
164
+ instance_variables
165
+ .reject { |variable| [:id].include? variable }
166
+ .each { |variable| subclass.instance_variable_set(variable, instance_variable_get(variable).dup) }
167
+ end
168
+ end
169
+ end
170
+ end
171
+ end
@@ -0,0 +1,88 @@
1
+ # Patch based on https://github.com/rack/rack/pull/1881
2
+ # This should be removed when/if this functionality makes its way into a rack
3
+ # release (possible rack 3.1.0)
4
+ module Rack
5
+ class Request
6
+ def headers
7
+ @headers ||= Headers.new(@env)
8
+ end
9
+
10
+ class Headers
11
+ def initialize(env)
12
+ @env = env
13
+ end
14
+
15
+ def [](k)
16
+ @env[header_to_env_key(k)]
17
+ end
18
+
19
+ def []=(k, v)
20
+ @env[header_to_env_key(k)] = v
21
+ end
22
+
23
+ def add(k, v)
24
+ k = header_to_env_key(k)
25
+ case existing = @env[k]
26
+ when nil
27
+ @env[k] = v
28
+ when String
29
+ @env[k] = [existing, v]
30
+ when Array
31
+ existing << v
32
+ end
33
+ end
34
+
35
+ def delete(k)
36
+ @env.delete(header_to_env_key(k))
37
+ end
38
+
39
+ def each
40
+ return to_enum(:each) unless block_given?
41
+
42
+ @env.each do |k, v|
43
+ next unless k = env_to_header_key(k)
44
+ yield k, v
45
+ end
46
+ end
47
+
48
+ def fetch(k, &block)
49
+ @env.fetch(header_to_env_key(k), &block)
50
+ end
51
+
52
+ def has_key?(k)
53
+ @env.has_key?(header_to_env_key(k))
54
+ end
55
+
56
+ def to_h
57
+ h = {}
58
+ each{|k, v| h[k] = v}
59
+ h
60
+ end
61
+
62
+ private
63
+
64
+ def env_to_header_key(k)
65
+ case k
66
+ when /\AHTTP_/
67
+ k = k[5..-1]
68
+ k.downcase!
69
+ k.tr!('_', '-')
70
+ k
71
+ when "CONTENT_LENGTH", "CONTENT_TYPE"
72
+ k = k.downcase
73
+ k.tr!('_', '-')
74
+ k
75
+ end
76
+ end
77
+
78
+ def header_to_env_key(k)
79
+ k = k.upcase
80
+ k.tr!('-', '_')
81
+ unless k == "CONTENT_LENGTH" || k == "CONTENT_TYPE"
82
+ k = "HTTP_#{k}"
83
+ end
84
+ k
85
+ end
86
+ end
87
+ end
88
+ end