api_mini_tester 0.1.4 → 0.1.5
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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6217a0f3741f405f67be1d00fb16460ea10958b9
|
4
|
+
data.tar.gz: a6b132d8192eb00255ab4a019022b4e81cb12b77
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 758c351cd3150f369bfd3452662d94bde7399fb24177b5766cd9dad9c334c7036cc71e199d46b9620e9cedfa1e033ffd4062095f9ee657daa44073b5daf44305
|
7
|
+
data.tar.gz: cf363712920a53022fc35b4f1a54b9ed67dd71a66c3e805a503ac5984dfd8dc7f28e82e4ecc050beb6f0954ad60c0905c2ae7e2bf62601c5ee32c065152644a2
|
@@ -1,52 +1,54 @@
|
|
1
1
|
require 'builder'
|
2
2
|
require 'socket'
|
3
3
|
|
4
|
-
|
4
|
+
module ApiMiniTester
|
5
|
+
class TestFormatter
|
5
6
|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
7
|
+
RESULT_SECTIONS = %i[status headers body timing].freeze
|
8
|
+
SECTION_TRANSLATE = {
|
9
|
+
status: "Status",
|
10
|
+
headers: "Headers",
|
11
|
+
body: "Body",
|
12
|
+
timing: "Timing"
|
13
|
+
}.freeze
|
13
14
|
|
14
|
-
|
15
|
+
attr_accessor :results
|
15
16
|
|
16
|
-
|
17
|
-
|
18
|
-
|
17
|
+
def initialize(results)
|
18
|
+
@results = results
|
19
|
+
end
|
19
20
|
|
20
|
-
|
21
|
-
|
22
|
-
|
21
|
+
def to_json
|
22
|
+
clean_up_infinity.to_json
|
23
|
+
end
|
23
24
|
|
24
|
-
|
25
|
-
|
26
|
-
|
25
|
+
def to_yaml
|
26
|
+
clean_up_infinity.to_yaml
|
27
|
+
end
|
27
28
|
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
29
|
+
def to_junit_xml
|
30
|
+
xml = Builder::XmlMarkup.new(indent: 2)
|
31
|
+
xml.instruct! :xml, encoding: "UTF-8"
|
32
|
+
xml.testsuites do
|
33
|
+
results[:scenarios].each do |scenario|
|
34
|
+
xml.testsuite name: scenario[:name],
|
35
|
+
timestamp: timestamp,
|
36
|
+
hostname: hostname,
|
37
|
+
tests: tests_in_scenario(scenario),
|
38
|
+
skipped: 0,
|
39
|
+
failures: failed_in_scenario(scenario),
|
40
|
+
errors: 0,
|
41
|
+
time: time_in_scenario(scenario) do
|
42
|
+
scenario[:steps].each do |step|
|
43
|
+
classname = name_to_camelcase(step[:name])
|
44
|
+
RESULT_SECTIONS.each do |section|
|
45
|
+
step[section].each do |s|
|
46
|
+
xml.testcase classname: classname,
|
47
|
+
name: s[:name],
|
48
|
+
time: step_timing(step),
|
49
|
+
file: "./#{classname}.rb" do
|
50
|
+
s[:result] ? nil : xml.failure(message: s[:desc])
|
51
|
+
end
|
50
52
|
end
|
51
53
|
end
|
52
54
|
end
|
@@ -54,156 +56,155 @@ class TestFormatter
|
|
54
56
|
end
|
55
57
|
end
|
56
58
|
end
|
57
|
-
end
|
58
59
|
|
59
|
-
|
60
|
-
|
61
|
-
|
60
|
+
def timestamp
|
61
|
+
Time.now.strftime("%FT%T%:z")
|
62
|
+
end
|
62
63
|
|
63
|
-
|
64
|
-
|
65
|
-
|
64
|
+
def scenarios_count
|
65
|
+
results[:scenarios].size
|
66
|
+
end
|
66
67
|
|
67
|
-
|
68
|
-
|
69
|
-
|
68
|
+
def steps_count(scenario)
|
69
|
+
scenario[:steps].size
|
70
|
+
end
|
70
71
|
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
72
|
+
def test_count(step)
|
73
|
+
count = 0
|
74
|
+
[:status, :headers, :body, :timing].each do |section|
|
75
|
+
count += step[section].size
|
76
|
+
end
|
77
|
+
count
|
75
78
|
end
|
76
|
-
count
|
77
|
-
end
|
78
79
|
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
80
|
+
def tests_in_scenario(scenario)
|
81
|
+
count = 0
|
82
|
+
scenario[:steps].each do |step|
|
83
|
+
count += test_count(step)
|
84
|
+
end
|
85
|
+
count
|
83
86
|
end
|
84
|
-
count
|
85
|
-
end
|
86
87
|
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
88
|
+
def time_in_scenario(scenario)
|
89
|
+
time = 0.0
|
90
|
+
scenario[:steps].each do |step|
|
91
|
+
time += step[:timing].first[:real]
|
92
|
+
end
|
93
|
+
time
|
91
94
|
end
|
92
|
-
time
|
93
|
-
end
|
94
95
|
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
96
|
+
def failed_in_scenario(scenario)
|
97
|
+
count = 0
|
98
|
+
scenario[:steps].each do |step|
|
99
|
+
[:status, :headers, :body, :timing].each do |section|
|
100
|
+
count += step[section].map { |res| res[:result] }.select(&:!).size
|
101
|
+
end
|
100
102
|
end
|
103
|
+
count
|
101
104
|
end
|
102
|
-
count
|
103
|
-
end
|
104
105
|
|
105
|
-
|
106
|
-
|
107
|
-
|
106
|
+
def hostname
|
107
|
+
Socket.gethostname
|
108
|
+
end
|
108
109
|
|
109
|
-
|
110
|
-
|
111
|
-
|
110
|
+
def name_to_camelcase(name)
|
111
|
+
name.gsub(/[[:space:]]+/, '_').downcase.gsub(/(?:^|_)([a-z])/) { $1.upcase }
|
112
|
+
end
|
112
113
|
|
113
|
-
|
114
|
-
|
115
|
-
|
114
|
+
def step_timing(step)
|
115
|
+
step[:timing].first ? step[:timing].first[:real] : 0
|
116
|
+
end
|
116
117
|
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
118
|
+
def clean_up_infinity
|
119
|
+
res = results.dup
|
120
|
+
res[:scenarios].each do |scenario|
|
121
|
+
scenario[:steps].each do |step|
|
122
|
+
step[:timing].each do |timing|
|
123
|
+
timing[:exp] = "Not Specified" if timing.is_a?(Hash) && timing[:exp] && timing[:exp] == Float::INFINITY
|
124
|
+
end
|
123
125
|
end
|
124
126
|
end
|
127
|
+
res
|
125
128
|
end
|
126
|
-
res
|
127
|
-
end
|
128
129
|
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
130
|
+
def array_in(array)
|
131
|
+
list = ''
|
132
|
+
array.each do |item|
|
133
|
+
if item.instance_of?(Array)
|
134
|
+
list << array_in(item)
|
135
|
+
elsif item.instance_of?(Hash)
|
136
|
+
list << hash_in(item)
|
137
|
+
end
|
136
138
|
end
|
139
|
+
list
|
137
140
|
end
|
138
|
-
list
|
139
|
-
end
|
140
141
|
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
142
|
+
def hash_in(hash)
|
143
|
+
list = ''
|
144
|
+
hash.each do |k, v|
|
145
|
+
if v.instance_of?(Hash)
|
146
|
+
list << hash_in(v)
|
147
|
+
elsif v.instance_of?(Array)
|
148
|
+
list << array_in(v)
|
149
|
+
elsif k == :result
|
150
|
+
list << (v ? '.' : 'E')
|
151
|
+
end
|
150
152
|
end
|
153
|
+
list
|
151
154
|
end
|
152
|
-
list
|
153
|
-
end
|
154
155
|
|
155
|
-
|
156
|
-
|
157
|
-
|
156
|
+
def to_simple
|
157
|
+
hash_in results
|
158
|
+
end
|
158
159
|
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
output << ""
|
163
|
-
if desc
|
164
|
-
output << "Desc: #{desc}"
|
160
|
+
def md_section_header(header, desc, level)
|
161
|
+
output = []
|
162
|
+
output << "#{'#' * level} #{header}"
|
165
163
|
output << ""
|
164
|
+
if desc
|
165
|
+
output << "Desc: #{desc}"
|
166
|
+
output << ""
|
167
|
+
end
|
168
|
+
output
|
166
169
|
end
|
167
|
-
output
|
168
|
-
end
|
169
170
|
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
171
|
+
def md_step_header(step)
|
172
|
+
output = []
|
173
|
+
output.push(*md_section_header(step[:name], step[:desc], 3))
|
174
|
+
output.push(*md_section_header("Call", nil, 4))
|
175
|
+
step[:url].each do |url|
|
176
|
+
output << "* #{url[:desc]}"
|
177
|
+
end
|
178
|
+
step[:method].each do |method|
|
179
|
+
output << "* #{method[:desc]}"
|
180
|
+
end
|
181
|
+
output << ""
|
182
|
+
output
|
179
183
|
end
|
180
|
-
output << ""
|
181
|
-
output
|
182
|
-
end
|
183
184
|
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
185
|
+
def md_section_content(step, section)
|
186
|
+
output = []
|
187
|
+
output << md_section_header(SECTION_TRANSLATE[section], nil, 4)
|
188
|
+
step[section].each do |status|
|
189
|
+
output << "* `#{status[:result]}`: #{status[:desc]}"
|
190
|
+
end
|
191
|
+
output << ""
|
192
|
+
output
|
189
193
|
end
|
190
|
-
output << ""
|
191
|
-
output
|
192
|
-
end
|
193
194
|
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
195
|
+
def to_markdown
|
196
|
+
output = []
|
197
|
+
output << md_section_header(results[:name], results[:desc], 1)
|
198
|
+
results[:scenarios].each do |scenario|
|
199
|
+
output << md_section_header(scenario[:name], scenario[:desc], 2)
|
200
|
+
scenario[:steps].each do |step|
|
201
|
+
output.push(*md_step_header(step))
|
202
|
+
RESULT_SECTIONS.each do |section|
|
203
|
+
output.push(*md_section_content(step, section))
|
204
|
+
end
|
203
205
|
end
|
204
206
|
end
|
207
|
+
output.join("\n")
|
205
208
|
end
|
206
|
-
output.join("\n")
|
207
209
|
end
|
208
|
-
|
209
210
|
end
|
@@ -2,8 +2,9 @@ require 'httparty'
|
|
2
2
|
require 'liquid'
|
3
3
|
require 'hash_parser'
|
4
4
|
require 'uri'
|
5
|
-
require 'faker'
|
6
5
|
require 'json'
|
6
|
+
require_relative 'test_faker_filter'
|
7
|
+
|
7
8
|
|
8
9
|
module ApiMiniTester
|
9
10
|
class TestStep
|
@@ -16,17 +17,23 @@ module ApiMiniTester
|
|
16
17
|
attr_reader :results
|
17
18
|
|
18
19
|
def initialize(base_uri, step, context = nil, data = nil)
|
20
|
+
Liquid::Template.register_filter(::TestFakerFilter)
|
19
21
|
@context = context
|
20
22
|
uri_template = Liquid::Template.parse([base_uri, step['uri']].join("/"), error_mode: :strict)
|
21
23
|
@name = step['name']
|
22
|
-
|
24
|
+
|
25
|
+
@uri = uri_template.render(
|
26
|
+
{'context' => context, 'data' => data},
|
27
|
+
{ strict_variables: true })
|
23
28
|
@method = step['method'].downcase.to_sym
|
24
29
|
|
25
30
|
input_template = Liquid::Template.parse(step['input'].to_yaml.to_s, error_mode: :strict)
|
26
|
-
@input = YAML.load(
|
31
|
+
@input = YAML.load(
|
32
|
+
input_template.render({'context' => context, 'data' => data}, { strict_variables: true }))
|
27
33
|
|
28
34
|
output_template = Liquid::Template.parse(step['output'].to_yaml.to_s, error_mode: :strict)
|
29
|
-
@output = YAML.load(
|
35
|
+
@output = YAML.load(
|
36
|
+
output_template.render({'context' => context, 'data' => data}, { strict_variables: true }))
|
30
37
|
|
31
38
|
@results = { name: step['name'], desc: step['desc'], status: [], headers: [], body: [], url: [], method: [], timing: [] }
|
32
39
|
end
|
@@ -154,7 +161,11 @@ module ApiMiniTester
|
|
154
161
|
|
155
162
|
def array_diff(a, b, path = nil, section = :body)
|
156
163
|
a.each do |a_item|
|
157
|
-
if
|
164
|
+
if b.nil?
|
165
|
+
add_result section, { result: false,
|
166
|
+
name: "Response boby value: #{[path].join(".")}",
|
167
|
+
desc: "Assert #{[path].join(".")} is empty" }
|
168
|
+
elsif a_item.instance_of?(Hash)
|
158
169
|
found = false
|
159
170
|
b.each do |b_item|
|
160
171
|
matching = true
|
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.5
|
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: 2018-09-
|
11
|
+
date: 2018-09-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: builder
|
@@ -230,13 +230,14 @@ dependencies:
|
|
230
230
|
- - ">="
|
231
231
|
- !ruby/object:Gem::Version
|
232
232
|
version: 3.4.2
|
233
|
-
description: Runs automated REST API based on YAML
|
233
|
+
description: Runs automated REST API based on YAML definition
|
234
234
|
email: jindrich.skupa@gmail.com
|
235
235
|
executables: []
|
236
236
|
extensions: []
|
237
237
|
extra_rdoc_files: []
|
238
238
|
files:
|
239
239
|
- lib/api_mini_tester.rb
|
240
|
+
- lib/api_mini_tester/test_faker_filter.rb
|
240
241
|
- lib/api_mini_tester/test_formatter.rb
|
241
242
|
- lib/api_mini_tester/test_scenario.rb
|
242
243
|
- lib/api_mini_tester/test_step.rb
|