rainforest-cli 1.10.0 → 1.10.1
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/CHANGELOG.md +4 -0
- data/lib/rainforest_cli.rb +18 -17
- data/lib/rainforest_cli/commands.rb +43 -0
- data/lib/rainforest_cli/csv_importer.rb +8 -12
- data/lib/rainforest_cli/options.rb +6 -2
- data/lib/rainforest_cli/version.rb +1 -1
- data/spec/rainforest_cli/commands_spec.rb +47 -0
- data/spec/rainforest_cli/csv_importer_spec.rb +12 -14
- data/spec/rainforest_cli/options_spec.rb +2 -2
- data/spec/rainforest_cli_spec.rb +9 -0
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2b75c82906788c8a2ee74b5d0ddb6311c7b644dd
|
4
|
+
data.tar.gz: 3a80fd662427ed53bc4e850d85f13a0ad7e4ae96
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 837d61212b55d32434c933547c50224522e5c0da42d10ed5da14f8db6784242927861815fa724d1bf8eeade388f2feedc74b06ec70a0336224e93a490b32db1e
|
7
|
+
data.tar.gz: 6dcf90bfca52ee02e8c1f72df2fd471bfef755c52cb374a8995b994e5d7605b159f63fd85b0947ba0a57904175d8a6e24b71a243fe9b97ca3e501c9e4b689d25
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,9 @@
|
|
1
1
|
# Rainforest CLI Changelog
|
2
2
|
|
3
|
+
## 1.10.1 - 10th October 2016
|
4
|
+
- Add documentation for commands to `--help` text. (fe3fddbe7086a6b914ffe74f65ae128a14277f82, @epaulet)
|
5
|
+
- Use more efficient CSV upload method. (e716e76b7627b334c4f8b50fd0afdad6fadd162e, @epaulet)
|
6
|
+
|
3
7
|
## 1.10.0 - 19th September 2016
|
4
8
|
- Add `--overwrite-variable` option to overwrite existing tabular variables if the
|
5
9
|
desired variable name is already taken when uploading CSVs. (ebf4ab90c5db2589695eaf6c3d4c4206bad17e7b,
|
data/lib/rainforest_cli.rb
CHANGED
@@ -5,6 +5,7 @@ require 'logger'
|
|
5
5
|
require 'rainforest_cli/version'
|
6
6
|
require 'rainforest_cli/constants'
|
7
7
|
require 'rainforest_cli/options'
|
8
|
+
require 'rainforest_cli/commands'
|
8
9
|
require 'rainforest_cli/runner'
|
9
10
|
require 'rainforest_cli/http_client'
|
10
11
|
require 'rainforest_cli/git_trigger'
|
@@ -23,9 +24,24 @@ require 'rainforest_cli/reporter'
|
|
23
24
|
module RainforestCli
|
24
25
|
def self.start(args)
|
25
26
|
options = OptionParser.new(args)
|
27
|
+
commands = Commands.new do |c|
|
28
|
+
c.add('run', 'Run your tests on Rainforest') { Runner.new(options).run }
|
29
|
+
c.add('new', 'Create a new RFML test') { TestFiles.new(options).create_file }
|
30
|
+
c.add('validate', 'Validate your RFML tests') { Validator.new(options).validate }
|
31
|
+
c.add('upload', 'Upload your RFML tests') { Uploader.new(options).upload }
|
32
|
+
c.add('rm', 'Remove an RFML test locally and remotely') { Deleter.new(options).delete }
|
33
|
+
c.add('export', 'Export your remote Rainforest tests to RFML') { Exporter.new(options).export }
|
34
|
+
c.add('csv-upload', 'Upload a new tabular variable from a CSV file') { CSVImporter.new(options).import }
|
35
|
+
c.add('report', 'Create a JUnit report from your run results') { Reporter.new(options).report }
|
36
|
+
end
|
37
|
+
|
26
38
|
@http_client = HttpClient.new(token: options.token)
|
27
39
|
::Rainforest.api_key = options.token
|
28
|
-
|
40
|
+
|
41
|
+
if args.size == 0
|
42
|
+
commands.print_documentation
|
43
|
+
options.print_documentation
|
44
|
+
end
|
29
45
|
|
30
46
|
begin
|
31
47
|
options.validate!
|
@@ -34,22 +50,7 @@ module RainforestCli
|
|
34
50
|
exit 2
|
35
51
|
end
|
36
52
|
|
37
|
-
|
38
|
-
when 'run' then Runner.new(options).run
|
39
|
-
when 'new' then TestFiles.new(options).create_file
|
40
|
-
when 'validate' then Validator.new(options).validate
|
41
|
-
when 'upload' then Uploader.new(options).upload
|
42
|
-
when 'rm' then Deleter.new(options).delete
|
43
|
-
when 'export' then Exporter.new(options).export
|
44
|
-
when 'csv-upload' then CSVImporter.new(options).import
|
45
|
-
when 'report' then Reporter.new(options).report
|
46
|
-
when 'sites', 'folders', 'browsers'
|
47
|
-
Resources.new(options).public_send(options.command)
|
48
|
-
else
|
49
|
-
logger.fatal 'Unknown command'
|
50
|
-
exit 2
|
51
|
-
end
|
52
|
-
|
53
|
+
commands.call(options.command) if options.command
|
53
54
|
true
|
54
55
|
end
|
55
56
|
|
@@ -0,0 +1,43 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RainforestCli
|
4
|
+
class Commands
|
5
|
+
Command = Struct.new(:name, :description, :block)
|
6
|
+
|
7
|
+
attr_reader :commands
|
8
|
+
|
9
|
+
def initialize
|
10
|
+
@commands = []
|
11
|
+
yield(self) if block_given?
|
12
|
+
end
|
13
|
+
|
14
|
+
def add(command, description, &blk)
|
15
|
+
@commands << Command.new(command, description, blk)
|
16
|
+
end
|
17
|
+
|
18
|
+
def call(command_name)
|
19
|
+
command = @commands.find { |c| c.name == command_name }
|
20
|
+
|
21
|
+
if command.nil?
|
22
|
+
logger.fatal "Unknown command: #{command_name}"
|
23
|
+
exit 2
|
24
|
+
end
|
25
|
+
|
26
|
+
command.block.call
|
27
|
+
end
|
28
|
+
|
29
|
+
def print_documentation
|
30
|
+
command_col_width = @commands.map { |c| c.name.length }.max
|
31
|
+
puts 'Usage: Rainforest CLI commands:'
|
32
|
+
@commands.each do |command|
|
33
|
+
puts "\t#{command.name.ljust(command_col_width)}\t\t#{command.description}"
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
private
|
38
|
+
|
39
|
+
def logger
|
40
|
+
RainforestCli.logger
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -1,8 +1,6 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
# frozen_string_literal: true
|
3
3
|
require 'csv'
|
4
|
-
require 'parallel'
|
5
|
-
require 'ruby-progressbar'
|
6
4
|
|
7
5
|
module RainforestCli
|
8
6
|
class CSVImporter
|
@@ -24,7 +22,7 @@ module RainforestCli
|
|
24
22
|
|
25
23
|
# Create the generator
|
26
24
|
columns = rows.shift.map do |column|
|
27
|
-
|
25
|
+
column.downcase.strip.gsub(/\s/, '_')
|
28
26
|
end
|
29
27
|
raise 'Invalid schema in CSV. You must include headers in first row.' if !columns
|
30
28
|
|
@@ -45,17 +43,15 @@ module RainforestCli
|
|
45
43
|
raise "Error creating tabular variable: #{response['error']}" if response['error']
|
46
44
|
puts "\t[OK]"
|
47
45
|
|
48
|
-
|
49
|
-
|
46
|
+
columns = response['columns']
|
47
|
+
generator_id = response['id']
|
48
|
+
data = rows.map { |row| row_data(columns, row) }
|
50
49
|
|
51
50
|
puts 'Uploading data...'
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
response = http_client.post("/generators/#{@generator_id}/rows", {data: row_data(@columns, row)})
|
57
|
-
raise response['error'] if response['error']
|
58
|
-
end
|
51
|
+
response = http_client.post("/generators/#{generator_id}/rows/batch", data: data)
|
52
|
+
# NOTE: Response for this endpoint will usually be an array representing all the rows created
|
53
|
+
raise response['error'] if response.is_a?(Hash) && response['error']
|
54
|
+
puts 'Upload complete.'
|
59
55
|
end
|
60
56
|
|
61
57
|
private
|
@@ -128,7 +128,7 @@ module RainforestCli
|
|
128
128
|
exit 0
|
129
129
|
end
|
130
130
|
|
131
|
-
opts.on_tail('--version', 'Display gem version') do
|
131
|
+
opts.on_tail('--version', '-v', 'Display gem version') do
|
132
132
|
puts opts.ver
|
133
133
|
exit 0
|
134
134
|
end
|
@@ -150,6 +150,10 @@ module RainforestCli
|
|
150
150
|
@tests = @args.dup
|
151
151
|
end
|
152
152
|
|
153
|
+
def print_documentation
|
154
|
+
self.class.new(['--help'])
|
155
|
+
end
|
156
|
+
|
153
157
|
def tests
|
154
158
|
@tests
|
155
159
|
end
|
@@ -175,7 +179,7 @@ module RainforestCli
|
|
175
179
|
end
|
176
180
|
|
177
181
|
def validate!
|
178
|
-
|
182
|
+
unless command.nil? || TOKEN_NOT_REQUIRED.include?(command)
|
179
183
|
unless token
|
180
184
|
raise ValidationError, 'You must pass your API token using: --token TOKEN'
|
181
185
|
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
describe RainforestCli::Commands do
|
3
|
+
subject { described_class.new }
|
4
|
+
|
5
|
+
describe '#initialize' do
|
6
|
+
it 'works without giving a block' do
|
7
|
+
expect { described_class.new }.to_not raise_error
|
8
|
+
end
|
9
|
+
|
10
|
+
it 'adds commands to list' do
|
11
|
+
commands = described_class.new do |c|
|
12
|
+
c.add('foo', 'bar') { 'baz' }
|
13
|
+
c.add('blah', 'blah') { 'blah' }
|
14
|
+
end
|
15
|
+
|
16
|
+
expect(commands.commands.length).to eq(2)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
describe '#add' do
|
21
|
+
let(:first_command) { subject.commands.first }
|
22
|
+
|
23
|
+
it 'properly adds a command to the list of commands' do
|
24
|
+
subject.add('foo', 'bar') { 'baz' }
|
25
|
+
expect(first_command.name).to eq('foo')
|
26
|
+
expect(first_command.description).to eq('bar')
|
27
|
+
expect(first_command.block.call).to eq('baz')
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
describe '#call' do
|
32
|
+
let(:service_object) { double }
|
33
|
+
|
34
|
+
before do
|
35
|
+
subject.add('my_command', 'desc') { service_object.my_method }
|
36
|
+
end
|
37
|
+
|
38
|
+
it "calls the corresponding command's block" do
|
39
|
+
expect(service_object).to receive(:my_method)
|
40
|
+
subject.call('my_command')
|
41
|
+
end
|
42
|
+
|
43
|
+
it 'raises a fatal error if the command does not exist' do
|
44
|
+
expect { subject.call('my_other_command') }.to raise_error(SystemExit)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
@@ -31,24 +31,22 @@ describe RainforestCli::CSVImporter do
|
|
31
31
|
.with('/generators', {
|
32
32
|
name: 'variables',
|
33
33
|
description: 'variables',
|
34
|
-
columns: columns
|
34
|
+
columns: columns,
|
35
35
|
})
|
36
36
|
.and_return success_response
|
37
37
|
|
38
38
|
expect(http_client).to receive(:post)
|
39
|
-
.with("/generators/#{generator_id}/rows", {
|
40
|
-
data:
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
1 => 'hunter2',
|
51
|
-
},
|
39
|
+
.with("/generators/#{generator_id}/rows/batch", {
|
40
|
+
data: [
|
41
|
+
{
|
42
|
+
0 => 'russ@rainforestqa.com',
|
43
|
+
1 => 'abc123',
|
44
|
+
},
|
45
|
+
{
|
46
|
+
0 => 'bob@example.com',
|
47
|
+
1 => 'hunter2',
|
48
|
+
},
|
49
|
+
],
|
52
50
|
}).and_return({})
|
53
51
|
subject.import
|
54
52
|
end
|
@@ -143,12 +143,12 @@ describe RainforestCli::OptionParser do
|
|
143
143
|
end
|
144
144
|
|
145
145
|
context 'with valid arguments' do
|
146
|
-
let(:args) { %w(
|
146
|
+
let(:args) { %w(new) }
|
147
147
|
it { does_not_raise_a_validation_exception }
|
148
148
|
end
|
149
149
|
|
150
150
|
context 'with missing token' do
|
151
|
-
let(:args) { %w() }
|
151
|
+
let(:args) { %w(upload) }
|
152
152
|
it { raises_a_validation_exception }
|
153
153
|
end
|
154
154
|
|
data/spec/rainforest_cli_spec.rb
CHANGED
@@ -40,6 +40,15 @@ describe RainforestCli do
|
|
40
40
|
end
|
41
41
|
end
|
42
42
|
|
43
|
+
context 'no parameters' do
|
44
|
+
let(:params) { %w() }
|
45
|
+
it 'prints out the help docs' do
|
46
|
+
expect_any_instance_of(RainforestCli::Commands).to receive(:print_documentation)
|
47
|
+
expect_any_instance_of(RainforestCli::OptionParser).to receive(:print_documentation)
|
48
|
+
described_class.start(params)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
43
52
|
context 'git-trigger' do
|
44
53
|
let(:params) { %w(run --token x --git-trigger) }
|
45
54
|
let(:commit_message) { 'a test commit message' }
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rainforest-cli
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.10.
|
4
|
+
version: 1.10.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Russell Smith
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2016-
|
12
|
+
date: 2016-10-10 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: httparty
|
@@ -190,6 +190,7 @@ files:
|
|
190
190
|
- bin/rainforest
|
191
191
|
- examples/inline_files.md
|
192
192
|
- lib/rainforest_cli.rb
|
193
|
+
- lib/rainforest_cli/commands.rb
|
193
194
|
- lib/rainforest_cli/constants.rb
|
194
195
|
- lib/rainforest_cli/csv_importer.rb
|
195
196
|
- lib/rainforest_cli/deleter.rb
|
@@ -220,6 +221,7 @@ files:
|
|
220
221
|
- spec/multiple-rainforest-examples/example_test.rfml
|
221
222
|
- spec/multiple-rainforest-examples/example_test_2.rfml
|
222
223
|
- spec/rainforest-example/example_test.rfml
|
224
|
+
- spec/rainforest_cli/commands_spec.rb
|
223
225
|
- spec/rainforest_cli/csv_importer_spec.rb
|
224
226
|
- spec/rainforest_cli/deleter_spec.rb
|
225
227
|
- spec/rainforest_cli/exporter_spec.rb
|
@@ -290,6 +292,7 @@ test_files:
|
|
290
292
|
- spec/multiple-rainforest-examples/example_test.rfml
|
291
293
|
- spec/multiple-rainforest-examples/example_test_2.rfml
|
292
294
|
- spec/rainforest-example/example_test.rfml
|
295
|
+
- spec/rainforest_cli/commands_spec.rb
|
293
296
|
- spec/rainforest_cli/csv_importer_spec.rb
|
294
297
|
- spec/rainforest_cli/deleter_spec.rb
|
295
298
|
- spec/rainforest_cli/exporter_spec.rb
|