rainforest-cli 1.6.5 → 1.7.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +3 -0
- data/CHANGELOG.md +8 -0
- data/README.md +42 -7
- data/bin/rainforest +1 -1
- data/lib/{rainforest/cli.rb → rainforest_cli.rb} +23 -15
- data/lib/{rainforest/cli → rainforest_cli}/constants.rb +0 -0
- data/lib/{rainforest/cli → rainforest_cli}/csv_importer.rb +0 -0
- data/lib/{rainforest/cli → rainforest_cli}/deleter.rb +0 -0
- data/lib/{rainforest/cli → rainforest_cli}/exporter.rb +0 -0
- data/lib/{rainforest/cli → rainforest_cli}/git_trigger.rb +0 -0
- data/lib/{rainforest/cli → rainforest_cli}/http_client.rb +5 -4
- data/lib/rainforest_cli/junit_outputter.rb +69 -0
- data/lib/{rainforest/cli → rainforest_cli}/options.rb +40 -1
- data/lib/{rainforest/cli → rainforest_cli}/remote_tests.rb +0 -0
- data/lib/rainforest_cli/reporter.rb +64 -0
- data/lib/{rainforest/cli → rainforest_cli}/resources.rb +0 -0
- data/lib/{rainforest/cli → rainforest_cli}/runner.rb +20 -6
- data/lib/{rainforest/cli → rainforest_cli}/test_files.rb +0 -0
- data/lib/{rainforest/cli → rainforest_cli}/test_parser.rb +4 -65
- data/lib/rainforest_cli/test_parser/embedded_test.rb +14 -0
- data/lib/rainforest_cli/test_parser/step.rb +24 -0
- data/lib/rainforest_cli/test_parser/test.rb +40 -0
- data/lib/{rainforest/cli → rainforest_cli}/uploader.rb +32 -27
- data/lib/rainforest_cli/uploader/multi_form_post_request.rb +50 -0
- data/lib/rainforest_cli/uploader/uploadable_parser.rb +143 -0
- data/lib/{rainforest/cli → rainforest_cli}/validator.rb +0 -0
- data/lib/{rainforest/cli → rainforest_cli}/version.rb +1 -1
- data/rainforest-cli.gemspec +3 -1
- data/spec/fixtures/failed_test_response.json +29 -0
- data/spec/fixtures/runs_response.json +275 -0
- data/spec/fixtures/tests_response.json +130 -0
- data/spec/{csv_importer_spec.rb → rainforest_cli/csv_importer_spec.rb} +7 -14
- data/spec/{deleter_spec.rb → rainforest_cli/deleter_spec.rb} +0 -0
- data/spec/{exporter_spec.rb → rainforest_cli/exporter_spec.rb} +0 -0
- data/spec/{git_trigger_spec.rb → rainforest_cli/git_trigger_spec.rb} +0 -0
- data/spec/{http_client_spec.rb → rainforest_cli/http_client_spec.rb} +23 -0
- data/spec/rainforest_cli/junit_outputter_spec.rb +32 -0
- data/spec/{options_spec.rb → rainforest_cli/options_spec.rb} +33 -0
- data/spec/{remote_tests_spec.rb → rainforest_cli/remote_tests_spec.rb} +0 -0
- data/spec/rainforest_cli/reporter_spec.rb +51 -0
- data/spec/{resources_spec.rb → rainforest_cli/resources_spec.rb} +0 -0
- data/spec/{runner_spec.rb → rainforest_cli/runner_spec.rb} +0 -0
- data/spec/{test_files_spec.rb → rainforest_cli/test_files_spec.rb} +1 -1
- data/spec/rainforest_cli/test_parser/step_spec.rb +53 -0
- data/spec/rainforest_cli/test_parser_spec.rb +15 -0
- data/spec/rainforest_cli/uploader/uploadable_parser_spec.rb +84 -0
- data/spec/{uploader_spec.rb → rainforest_cli/uploader_spec.rb} +2 -2
- data/spec/{validator_spec.rb → rainforest_cli/validator_spec.rb} +6 -7
- data/spec/{cli_spec.rb → rainforest_cli_spec.rb} +5 -5
- data/spec/spec_helper.rb +4 -1
- metadata +95 -47
- data/.rvmrc +0 -1
- data/spec/test_parser_spec.rb +0 -95
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e73f6818b72f61f2b152943bc46f066b95c43630
|
4
|
+
data.tar.gz: a5a82d24cf2b5d5d4be4fafe0c3a0ebab1cca626
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: add946c11dd743c5fb9796d00a12526c87a7453bfe52341a28272d22ae0fb05458b95bf2cb52080623a67d17bc1318a09db75a2c96c9d94ec4041b0724e48da5
|
7
|
+
data.tar.gz: 712af1181c2892308dd5396c63653f0e61e5944ad74044788589326258e74b3075cf40a93a672e5c19dabe7d38fba7328d43fe85b7630683c2ee9542dad183e2
|
data/.rubocop.yml
CHANGED
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,13 @@
|
|
1
1
|
# Rainforest CLI Changelog
|
2
2
|
|
3
|
+
## 1.7.0 - 8th August 2016
|
4
|
+
- New run flag: `--wait` for hooking into existing run instead of starting a new one.
|
5
|
+
(77df41bf79b8635fb8c2d8a93968f975db092c69, @shosti)
|
6
|
+
- New run flag: `--junit-file` for exporting run results into JUnit format.
|
7
|
+
(349f2b1f5c8b423766875751c7cafed692fc2bed, @briancolby)
|
8
|
+
- New feature: Embed screenshots and file download links in your RFML tests.
|
9
|
+
(e081072c591c810b8bc3edce6d2e507d12a1a18e, @epaulet)
|
10
|
+
|
3
11
|
## 1.6.5 - 13th June 2016
|
4
12
|
- Exit with non-zero status code when `validate` fails. (8db1d38be39aa50d2afcdef817f78c654b3108b6,
|
5
13
|
@DyerSituation)
|
data/README.md
CHANGED
@@ -32,9 +32,9 @@ You can customize the amount of threads to use when making HTTP requests by sett
|
|
32
32
|
API errors when fetching or updating multiple tests, lowering this value can help.
|
33
33
|
The default value is `16`.
|
34
34
|
|
35
|
-
|
35
|
+
## Options
|
36
36
|
|
37
|
-
|
37
|
+
#### Running Tests
|
38
38
|
|
39
39
|
Run all tests.
|
40
40
|
|
@@ -54,7 +54,13 @@ Run all tests with tag 'run-me' and abort previous in-progress runs.
|
|
54
54
|
rainforest run --tag run-me --fg --conflict abort
|
55
55
|
```
|
56
56
|
|
57
|
-
|
57
|
+
Run all in the foreground and generate a junit xml report.
|
58
|
+
|
59
|
+
```bash
|
60
|
+
rainforest run all --fg --junit-file rainforest.xml
|
61
|
+
```
|
62
|
+
|
63
|
+
#### Creating and Managing Tests
|
58
64
|
|
59
65
|
Create new Rainforest test in RFML format (Rainforest Markup Language).
|
60
66
|
|
@@ -82,12 +88,19 @@ Upload tests to Rainforest
|
|
82
88
|
rainforest upload
|
83
89
|
```
|
84
90
|
|
91
|
+
Remove RFML file and remove test from Rainforest test suite.
|
92
|
+
|
93
|
+
```bash
|
94
|
+
rainforest rm /path/to/test/file.rfml
|
95
|
+
```
|
96
|
+
|
85
97
|
Export all tests from Rainforest
|
98
|
+
|
86
99
|
```bash
|
87
100
|
rainforest export
|
88
101
|
```
|
89
102
|
|
90
|
-
|
103
|
+
#### Viewing Account Specific Information
|
91
104
|
|
92
105
|
See a list of all of your sites and their IDs
|
93
106
|
```bash
|
@@ -104,6 +117,11 @@ See a list of all of your browsers and their IDs
|
|
104
117
|
rainforest browsers
|
105
118
|
```
|
106
119
|
|
120
|
+
To generate a junit xml report for a test run which has already completed
|
121
|
+
```bash
|
122
|
+
rainforest report --run-id <run-id> --junit-file rainforest.xml
|
123
|
+
```
|
124
|
+
|
107
125
|
## Options
|
108
126
|
|
109
127
|
### General
|
@@ -128,8 +146,11 @@ Rainforest Tests written using RFML have the following format
|
|
128
146
|
# redirect: [REDIRECT FLAG]
|
129
147
|
- [EMBEDDED TEST RFML ID]
|
130
148
|
|
131
|
-
|
132
|
-
|
149
|
+
Action with an embedded screenshot: {{ file.screenshot(./relative/path/to/screenshot.jpg) }}
|
150
|
+
Response with an embedded file download: {{ file.download(./relative/path/to/file.txt) }}
|
151
|
+
|
152
|
+
[ACTION 3]
|
153
|
+
[QUESTION 3]
|
133
154
|
|
134
155
|
... etc.
|
135
156
|
```
|
@@ -161,6 +182,13 @@ tests and the first step of a test.
|
|
161
182
|
- `EMBEDDED TEST RFML ID` - Embed the steps of another test within the current test
|
162
183
|
using the embedded test's RFML ID.
|
163
184
|
|
185
|
+
Embedding Screenshots and Downloadable Files:
|
186
|
+
- Your embedded files must be checked into version control with along your RFML tests.
|
187
|
+
- `{{ file.screenshot(RELATIVE_PATH) }}` will embed screenshot found at RELATIVE_PATH
|
188
|
+
which is a path to the screenshot relative to the RFML file.
|
189
|
+
- `{{ file.download(RELATIVE_PATH) }}` will embed downloadable file link found at RELATIVE_PATH
|
190
|
+
which is a path to the downloadable file relative to the RFML file.
|
191
|
+
|
164
192
|
For more information on test writing, please visit our [documentation](http://support.rainforestqa.com/hc/en-us/sections/200585603-Writing-Tests).
|
165
193
|
|
166
194
|
### Command Line Options
|
@@ -173,6 +201,7 @@ Popular command line options are:
|
|
173
201
|
- `--environment-id` - run your tests using this environment. Otherwise it will use your default environment
|
174
202
|
- `--conflict OPTION` - use the `abort` option to abort any runs in progress in the same environment as your new run. use the `abort-all` option to abort all runs in progress.
|
175
203
|
- `--fg` - results in the foreground - rainforest-cli will not return until the run is complete. This is what you want to make the build pass / fail dependent on rainforest results
|
204
|
+
- `--wait RUN_ID` - wait for an existing run to finish instead of starting a new one, and exit with a non-0 code if the run fails. rainforest-cli will exit immediately if the run is already complete.
|
176
205
|
- `--fail-fast` - fail the build as soon as the first failed result comes in. If you don't pass this it will wait until 100% of the run is done. Use with `--fg`.
|
177
206
|
- `--custom-url` - use a custom url for this run. Example use case: an ad-hoc QA environment with [Fourchette](https://github.com/rainforestapp/fourchette). You will need to specify a `site_id` too for this to work. Note that we will be creating a new environment for this particular run.
|
178
207
|
- `--git-trigger` - only trigger a run when the last commit (for a git repo in the current working directory) has contains `@rainforest` and a list of one or more tags. E.g. "Fix checkout process. @rainforest #checkout" would trigger a run for everything tagged `checkout`. This over-rides `--tag` and any tests specified. If no `@rainforest` is detected it will exit 0.
|
@@ -180,6 +209,12 @@ Popular command line options are:
|
|
180
209
|
- `--embed-tests` - Use with `rainforest export` to export your tests without extracting the
|
181
210
|
steps of an embedded test.
|
182
211
|
- `--test-folder /path/to/directory` - Use with `rainforest [new, upload, export]`. If this option is not provided, rainforest-cli will, in the case of 'new' create a directory, or in the case of 'upload' and 'export' use the directory, at the default path `./spec/rainforest/`.
|
212
|
+
- `--junit-file` - Create a junit xml report file with the specified name. Must be run in foreground mode, or with the report command. Uses the rainforest
|
213
|
+
api to construct a junit report. This is useful to track tests in CI such as Jenkins or Bamboo.
|
214
|
+
- `--run-id` - Only used with the report command. Specify a past rainforest run by ID number to generate a report for.
|
215
|
+
- `--import-variable-csv-file /path/to/csv/file.csv` - Use with `run` and `--import-variable-name` to upload new tabular variable values before your run to specify the path to your CSV file.
|
216
|
+
- `--import-variable-name NAME` - Use with `run` and `import-variable-csv-file` to upload
|
217
|
+
new tabular variable values before your run to specify the name of your tabular variable.
|
183
218
|
|
184
219
|
|
185
220
|
#### Specifying Test IDs
|
@@ -192,7 +227,7 @@ test IDs taken from the Rainforest dashboard. ie:
|
|
192
227
|
All other argument types should be specified as seen above.
|
193
228
|
|
194
229
|
|
195
|
-
More detailed info on options can be [found here](https://github.com/rainforestapp/rainforest-cli/blob/master/lib/
|
230
|
+
More detailed info on options can be [found here](https://github.com/rainforestapp/rainforest-cli/blob/master/lib/rainforest_cli/options.rb#L23-L74).
|
196
231
|
|
197
232
|
## Support
|
198
233
|
|
data/bin/rainforest
CHANGED
@@ -2,25 +2,28 @@
|
|
2
2
|
require 'erb'
|
3
3
|
require 'json'
|
4
4
|
require 'logger'
|
5
|
-
require '
|
6
|
-
require '
|
7
|
-
require '
|
8
|
-
require '
|
9
|
-
require '
|
10
|
-
require '
|
11
|
-
require '
|
12
|
-
require '
|
13
|
-
require '
|
14
|
-
require '
|
15
|
-
require '
|
16
|
-
require '
|
17
|
-
require '
|
18
|
-
require '
|
19
|
-
require '
|
5
|
+
require 'rainforest_cli/version'
|
6
|
+
require 'rainforest_cli/constants'
|
7
|
+
require 'rainforest_cli/options'
|
8
|
+
require 'rainforest_cli/runner'
|
9
|
+
require 'rainforest_cli/http_client'
|
10
|
+
require 'rainforest_cli/git_trigger'
|
11
|
+
require 'rainforest_cli/csv_importer'
|
12
|
+
require 'rainforest_cli/test_parser'
|
13
|
+
require 'rainforest_cli/test_files'
|
14
|
+
require 'rainforest_cli/remote_tests'
|
15
|
+
require 'rainforest_cli/validator'
|
16
|
+
require 'rainforest_cli/exporter'
|
17
|
+
require 'rainforest_cli/deleter'
|
18
|
+
require 'rainforest_cli/uploader'
|
19
|
+
require 'rainforest_cli/resources'
|
20
|
+
require 'rainforest_cli/junit_outputter'
|
21
|
+
require 'rainforest_cli/reporter'
|
20
22
|
|
21
23
|
module RainforestCli
|
22
24
|
def self.start(args)
|
23
25
|
options = OptionParser.new(args)
|
26
|
+
@http_client = HttpClient.new(token: options.token)
|
24
27
|
OptionParser.new(['--help']) if args.size == 0
|
25
28
|
|
26
29
|
begin
|
@@ -37,6 +40,7 @@ module RainforestCli
|
|
37
40
|
when 'upload' then Uploader.new(options).upload
|
38
41
|
when 'rm' then Deleter.new(options).delete
|
39
42
|
when 'export' then Exporter.new(options).export
|
43
|
+
when 'report' then Reporter.new(options).report
|
40
44
|
when 'sites', 'folders', 'browsers'
|
41
45
|
Resources.new(options).public_send(options.command)
|
42
46
|
else
|
@@ -54,4 +58,8 @@ module RainforestCli
|
|
54
58
|
def self.logger=(logger)
|
55
59
|
@logger = logger
|
56
60
|
end
|
61
|
+
|
62
|
+
def self.http_client
|
63
|
+
@http_client
|
64
|
+
end
|
57
65
|
end
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
@@ -17,7 +17,7 @@ module RainforestCli
|
|
17
17
|
response = HTTParty.delete make_url(url), {
|
18
18
|
body: body,
|
19
19
|
headers: headers,
|
20
|
-
verify: false
|
20
|
+
verify: false,
|
21
21
|
}
|
22
22
|
|
23
23
|
JSON.parse(response.body)
|
@@ -28,7 +28,7 @@ module RainforestCli
|
|
28
28
|
response = HTTParty.post make_url(url), {
|
29
29
|
body: body,
|
30
30
|
headers: headers,
|
31
|
-
verify: false
|
31
|
+
verify: false,
|
32
32
|
}
|
33
33
|
|
34
34
|
return JSON.parse(response.body)
|
@@ -40,12 +40,13 @@ module RainforestCli
|
|
40
40
|
response = HTTParty.get make_url(url), {
|
41
41
|
body: body,
|
42
42
|
headers: headers,
|
43
|
-
verify: false
|
43
|
+
verify: false,
|
44
44
|
}
|
45
45
|
|
46
46
|
if response.code == 200
|
47
47
|
return JSON.parse(response.body)
|
48
48
|
else
|
49
|
+
RainforestCli.logger.warn("Status Code: #{response.code}, #{response.body}")
|
49
50
|
return nil
|
50
51
|
end
|
51
52
|
end
|
@@ -89,7 +90,7 @@ module RainforestCli
|
|
89
90
|
def headers
|
90
91
|
{
|
91
92
|
'CLIENT_TOKEN' => @token,
|
92
|
-
'User-Agent' => "Rainforest-cli-#{RainforestCli::VERSION}"
|
93
|
+
'User-Agent' => "Rainforest-cli-#{RainforestCli::VERSION}",
|
93
94
|
}
|
94
95
|
end
|
95
96
|
end
|
@@ -0,0 +1,69 @@
|
|
1
|
+
require 'builder'
|
2
|
+
require 'time'
|
3
|
+
require 'json'
|
4
|
+
|
5
|
+
# frozen_string_literal: true
|
6
|
+
module RainforestCli
|
7
|
+
class JunitOutputter
|
8
|
+
attr_reader :builder, :client
|
9
|
+
|
10
|
+
def initialize(token, run, tests)
|
11
|
+
@client = HttpClient.new token: token
|
12
|
+
@json_run = run # JSON containing the results of /1/runs/{run_id}.json
|
13
|
+
@json_tests = tests # JSON containing the results of /1/runs/{run_id}/tests.json
|
14
|
+
@builder = Builder::XmlMarkup.new( :indent => 2)
|
15
|
+
end # end initialize
|
16
|
+
|
17
|
+
def build_test_suite
|
18
|
+
@json_tests.each do | test |
|
19
|
+
build_test test
|
20
|
+
end # end do
|
21
|
+
end # end process_run_results
|
22
|
+
|
23
|
+
def build_test(test)
|
24
|
+
test_name = test['title']
|
25
|
+
execution_time = Time.parse(test['updated_at']) - Time.parse(test['created_at'])
|
26
|
+
test_status = test['result']
|
27
|
+
@builder.testcase(:name => test_name, :time => execution_time) do
|
28
|
+
case test_status
|
29
|
+
when "failed"
|
30
|
+
build_failed_test test
|
31
|
+
end # end case
|
32
|
+
end # end do
|
33
|
+
end # end build_test
|
34
|
+
|
35
|
+
def build_failed_test(test)
|
36
|
+
response = client.get("/runs/#{@json_run['id']}/tests/#{test['id']}.json")
|
37
|
+
response['steps'].each do | step |
|
38
|
+
step['browsers'].each do | browser |
|
39
|
+
browser_name = browser['name']
|
40
|
+
browser['feedback'].each do | opinion |
|
41
|
+
if opinion['answer_given'] == 'no' and opinion['job_state'] == 'approved'
|
42
|
+
if opinion['note'] != ""
|
43
|
+
@builder.failure(:type => browser_name, :message => opinion['note'])
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end # end build_failed_test
|
50
|
+
|
51
|
+
def parse
|
52
|
+
@builder.instruct! :xml, :version => "1.0", :encoding => "UTF-8"
|
53
|
+
@builder.testsuite(
|
54
|
+
:name => @json_run['description'],
|
55
|
+
:errors => @json_run['total_no_result_tests'],
|
56
|
+
:failures => @json_run['total_failed_tests'],
|
57
|
+
:tests => @json_run['total_tests'],
|
58
|
+
:time => Time.parse(@json_run['timestamps']['complete']) - Time.parse(@json_run['timestamps']['created_at']),
|
59
|
+
:timestamp => @json_run['created_at']) do
|
60
|
+
build_test_suite
|
61
|
+
end
|
62
|
+
end # end parse
|
63
|
+
|
64
|
+
def output(stream)
|
65
|
+
stream.write(@builder.target!)
|
66
|
+
end #end output
|
67
|
+
|
68
|
+
end # end class
|
69
|
+
end # end module
|
@@ -6,7 +6,8 @@ module RainforestCli
|
|
6
6
|
attr_writer :file_name, :tags
|
7
7
|
attr_reader :command, :token, :tags, :conflict, :browsers, :site_id, :environment_id,
|
8
8
|
:import_file_name, :import_name, :custom_url, :description, :folder,
|
9
|
-
:debug, :file_name, :test_folder, :embed_tests, :app_source_url, :crowd
|
9
|
+
:debug, :file_name, :test_folder, :embed_tests, :app_source_url, :crowd, :run_id,
|
10
|
+
:junit_file
|
10
11
|
|
11
12
|
TOKEN_NOT_REQUIRED = %w{new validate}.freeze
|
12
13
|
|
@@ -15,6 +16,8 @@ module RainforestCli
|
|
15
16
|
@tags = []
|
16
17
|
@browsers = nil
|
17
18
|
@debug = false
|
19
|
+
@junit_file = nil
|
20
|
+
@run_id = nil
|
18
21
|
@token = ENV['RAINFOREST_API_TOKEN']
|
19
22
|
|
20
23
|
# NOTE: Disabling line length cop to allow for consistency of syntax
|
@@ -55,6 +58,11 @@ module RainforestCli
|
|
55
58
|
@foreground = value
|
56
59
|
end
|
57
60
|
|
61
|
+
opts.on('--wait ID', Integer, 'Wait for run #ID to complete') do |value|
|
62
|
+
@wait = true
|
63
|
+
@run_id = value
|
64
|
+
end
|
65
|
+
|
58
66
|
opts.on('--fail-fast', String, "Fail as soon as there is a failure (don't wait for completion)") do |_value|
|
59
67
|
@failfast = true
|
60
68
|
end
|
@@ -103,6 +111,14 @@ module RainforestCli
|
|
103
111
|
@app_source_url = value
|
104
112
|
end
|
105
113
|
|
114
|
+
opts.on('--junit-file FILE', 'Gather the results of a run and create junit output in FILE.xml, must be run with --fg') do |value|
|
115
|
+
@junit_file = value
|
116
|
+
end
|
117
|
+
|
118
|
+
opts.on('--run-id ID', 'Gather the results of a completed run, must be run with export and --junit-file') do |value|
|
119
|
+
@run_id = value
|
120
|
+
end
|
121
|
+
|
106
122
|
opts.on_tail('--help', 'Display help message and exit') do |_value|
|
107
123
|
puts opts
|
108
124
|
exit 0
|
@@ -142,10 +158,18 @@ module RainforestCli
|
|
142
158
|
@failfast
|
143
159
|
end
|
144
160
|
|
161
|
+
def wait?
|
162
|
+
!!@wait
|
163
|
+
end
|
164
|
+
|
145
165
|
def foreground?
|
146
166
|
@foreground
|
147
167
|
end
|
148
168
|
|
169
|
+
def junit_file?
|
170
|
+
@junit_file
|
171
|
+
end
|
172
|
+
|
149
173
|
def validate!
|
150
174
|
if !TOKEN_NOT_REQUIRED.include?(command)
|
151
175
|
unless token
|
@@ -169,6 +193,21 @@ module RainforestCli
|
|
169
193
|
raise ValidationError, 'You must include a file name'
|
170
194
|
end
|
171
195
|
|
196
|
+
if command == 'run' && junit_file?
|
197
|
+
unless foreground?
|
198
|
+
raise ValidationError, 'You can only generate junit test output in foreground mode'
|
199
|
+
end
|
200
|
+
end
|
201
|
+
|
202
|
+
if command == 'report'
|
203
|
+
if junit_file.nil?
|
204
|
+
raise ValidationError, 'You must specify a junit ouptut filename'
|
205
|
+
end
|
206
|
+
if run_id.nil?
|
207
|
+
raise ValidationError, 'You must specify a run-id to generate a report for'
|
208
|
+
end
|
209
|
+
end
|
210
|
+
|
172
211
|
true
|
173
212
|
end
|
174
213
|
|
File without changes
|
@@ -0,0 +1,64 @@
|
|
1
|
+
require 'fileutils'
|
2
|
+
|
3
|
+
#frozen_string_literal: true
|
4
|
+
module RainforestCli
|
5
|
+
class Reporter
|
6
|
+
attr_reader :client
|
7
|
+
attr_writer :run_id
|
8
|
+
|
9
|
+
def initialize(options)
|
10
|
+
@options = options
|
11
|
+
@client = HttpClient.new token: options.token
|
12
|
+
@run_id = options.run_id
|
13
|
+
@output_filename = options.junit_file
|
14
|
+
end
|
15
|
+
|
16
|
+
def report
|
17
|
+
if @run_id == nil
|
18
|
+
logger.fatal "Reporter needs a valid run_id to report on"
|
19
|
+
else
|
20
|
+
logger.info "Generating JUNIT report for #{@run_id} : #{@output_filename}"
|
21
|
+
end
|
22
|
+
|
23
|
+
run = client.get("/runs/#{@run_id}.json")
|
24
|
+
|
25
|
+
if run == nil
|
26
|
+
logger.fatal "Non 200 code recieved"
|
27
|
+
exit 1
|
28
|
+
end
|
29
|
+
|
30
|
+
if run['error']
|
31
|
+
logger.fatal "Error retrieving results for your run: #{run['error']}"
|
32
|
+
exit 1
|
33
|
+
end
|
34
|
+
|
35
|
+
if run.has_key?('total_tests') and run['total_tests'] != 0
|
36
|
+
tests = client.get("/runs/#{@run_id}/tests.json?page_size=#{run['total_tests']}")
|
37
|
+
|
38
|
+
if tests == nil
|
39
|
+
logger.fatal "Non 200 code recieved"
|
40
|
+
exit 1
|
41
|
+
end
|
42
|
+
|
43
|
+
if tests.kind_of?(Hash) and tests['error'] # if this had worked tests would be an array
|
44
|
+
logger.fatal "Error retrieving test details for your run: #{tests['error']}"
|
45
|
+
exit 1
|
46
|
+
end
|
47
|
+
|
48
|
+
outputter = JunitOutputter.new(@options.token, run, tests)
|
49
|
+
outputter.parse
|
50
|
+
end
|
51
|
+
|
52
|
+
unless File.directory?(File.dirname(@output_filename))
|
53
|
+
FileUtils.mkdir_p(File.dirname(@output_filename))
|
54
|
+
end
|
55
|
+
|
56
|
+
File.open(@output_filename, 'w') { |file| outputter.output(file) }
|
57
|
+
end
|
58
|
+
|
59
|
+
def logger
|
60
|
+
RainforestCli.logger
|
61
|
+
end
|
62
|
+
|
63
|
+
end
|
64
|
+
end
|