api_mini_tester 0.1.14 → 0.1.15
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.
- checksums.yaml +4 -4
- data/lib/api_mini_tester/test_step.rb +48 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 868c314aa5c1c44fcfc934efb75e1eeeb5a3591c
|
4
|
+
data.tar.gz: d205d3f88084c22025bea0f047761afbf0f720e8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: af4150a382255cebcba1b5c147523adf242fda1194216264940b87cd64cc36c70d9484804d9ba5d3c1c0770ed90e6095499adb68f3a88cc195ca81c8867aade9
|
7
|
+
data.tar.gz: b5319905e37feada8cef2a1c5d36fd92ca18194914de6ffe837c59e626f096d00c3b60d583bab77291ab04e957e57c8b45effb4da8cc90950365e3e95e0934a1
|
@@ -13,6 +13,11 @@ module ApiMiniTester
|
|
13
13
|
|
14
14
|
SUPPORTED_METHODS = %i[ get post put delete ].freeze
|
15
15
|
SUPPORTED_RANDOM_DISTRIBUTION = %w[ static norm uniform ].freeze
|
16
|
+
TYPE_TO_METHOD_MAP = {
|
17
|
+
'integer' => 'to_i',
|
18
|
+
'float' => 'to_f',
|
19
|
+
'string' => 'to_s'
|
20
|
+
}.freeze
|
16
21
|
|
17
22
|
attr_accessor :name, :input, :output, :timing
|
18
23
|
attr_reader :results, :sleeps, :method, :uri, :debug
|
@@ -81,12 +86,18 @@ module ApiMiniTester
|
|
81
86
|
when 'multipart/form-data'
|
82
87
|
body_to_form_data
|
83
88
|
else
|
84
|
-
|
89
|
+
body_by_anotations
|
85
90
|
end
|
86
91
|
end
|
87
92
|
|
93
|
+
def body_by_anotations
|
94
|
+
resolve_annotations(@input["body"]).to_json
|
95
|
+
end
|
96
|
+
|
88
97
|
def raw_body
|
89
98
|
@input["body"].to_hash
|
99
|
+
rescue StandardError
|
100
|
+
""
|
90
101
|
end
|
91
102
|
|
92
103
|
def body_to_form_data
|
@@ -280,6 +291,42 @@ module ApiMiniTester
|
|
280
291
|
end
|
281
292
|
end
|
282
293
|
end
|
294
|
+
|
295
|
+
def type_to_method(type)
|
296
|
+
TYPE_TO_METHOD_MAP[type.downcase].to_sym
|
297
|
+
end
|
298
|
+
|
299
|
+
def resolve_annotations(struct)
|
300
|
+
if struct.instance_of?(Hash)
|
301
|
+
struct = resolve_annotations_hash(struct)
|
302
|
+
end
|
303
|
+
struct
|
304
|
+
end
|
305
|
+
|
306
|
+
def resolve_annotations_hash(hash)
|
307
|
+
hash.each do |k, v|
|
308
|
+
next unless matched = /\A\.(?<key>.*)\Z/.match(k)
|
309
|
+
type = v
|
310
|
+
typed_key = matched[:key]
|
311
|
+
next if hash[typed_key].nil?
|
312
|
+
hash[typed_key] = if hash[typed_key].instance_of?(Array)
|
313
|
+
resolve_annotations_array(hash[typed_key], type)
|
314
|
+
else
|
315
|
+
resolve_annotations_value(hash[typed_key], type)
|
316
|
+
end
|
317
|
+
hash.delete(k)
|
318
|
+
end
|
319
|
+
end
|
320
|
+
|
321
|
+
def resolve_annotations_value(value, type)
|
322
|
+
value.send(type_to_method(type))
|
323
|
+
rescue StandardError
|
324
|
+
value
|
325
|
+
end
|
326
|
+
|
327
|
+
def resolve_annotations_array(array, type)
|
328
|
+
array.map(&type_to_method(type))
|
329
|
+
end
|
283
330
|
end
|
284
331
|
end
|
285
332
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: api_mini_tester
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.15
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jindrich Skupa (@eMan)
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-
|
11
|
+
date: 2019-03-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: builder
|