oncall 0.2.5 → 0.3.0
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/README.md +34 -2
- data/bin/oncall +1 -1
- data/lib/oncall/cli.rb +75 -19
- data/lib/oncall/config.rb +4 -0
- data/lib/oncall/dsl.rb +82 -4
- data/lib/oncall/invocations.rb +73 -0
- data/lib/oncall/options.rb +26 -0
- data/lib/oncall/reporter.rb +120 -0
- data/lib/oncall/test_file.rb +13 -0
- data/lib/oncall/version.rb +1 -1
- data/lib/oncall.rb +29 -1
- metadata +11 -21
- data/lib/oncall/commands/base_command.rb +0 -32
- data/lib/oncall/commands/init_command.rb +0 -16
- data/lib/oncall/commands/run_command.rb +0 -11
- data/lib/oncall/commands/shell_command.rb +0 -17
- data/lib/oncall/core/config.rb +0 -40
- data/lib/oncall/core/reporter.rb +0 -70
- data/lib/oncall/core/runner.rb +0 -50
- data/lib/oncall/core/world.rb +0 -19
- data/lib/oncall/core/wrapper.rb +0 -15
- data/lib/oncall/core.rb +0 -25
- data/lib/oncall/dsl/assertion.rb +0 -28
- data/lib/oncall/dsl/call.rb +0 -54
- data/lib/oncall/dsl/group.rb +0 -18
- data/lib/oncall/http/request.rb +0 -6
- data/lib/oncall/http/response.rb +0 -6
- data/lib/oncall/http.rb +0 -17
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b32fb0bf81e7eb52f7ed4a716584e5634d2109d00f68e9d99ac687576b7dafe7
|
4
|
+
data.tar.gz: 8896c3f2830722e034f7de93c907e5d40ac257114f49179aa875937c0a59687a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 121096a38968f48da32314255339cef94e526a6d30a9ff31331e2e1c0f93f2d443169f3e52ec7ab44180f01904bd469d3517f7f7cf0ae532d95c4793dbbbd6bf
|
7
|
+
data.tar.gz: 56acd28d76bfd3a65c8a94f89f6b10052efaab80e135d41e35b8e017c0a479aae09ac960ae2c2c4bc450e6370368a6bb769a7f411be6ee623313e9c1fba8827c
|
data/README.md
CHANGED
@@ -6,11 +6,11 @@
|
|
6
6
|
|
7
7
|
#### Install
|
8
8
|
```
|
9
|
-
gem install oncall
|
9
|
+
$ gem install oncall
|
10
10
|
```
|
11
11
|
|
12
12
|
|
13
|
-
|
13
|
+
#### Table of content
|
14
14
|
|
15
15
|
* [Get started](#get-started)
|
16
16
|
* [Usage](#usage)
|
@@ -21,6 +21,37 @@ gem install oncall
|
|
21
21
|
|
22
22
|
## Get started
|
23
23
|
|
24
|
+
Initialize
|
25
|
+
```
|
26
|
+
$ oncall --init
|
27
|
+
```
|
28
|
+
|
29
|
+
Add tests
|
30
|
+
```
|
31
|
+
group :user do
|
32
|
+
header 'Content-Type' => 'application/json'
|
33
|
+
|
34
|
+
schema = {
|
35
|
+
'type' => 'object',
|
36
|
+
'required' => ['foo'],
|
37
|
+
'properties' => {
|
38
|
+
'foo' => { 'type' => 'string' }
|
39
|
+
}
|
40
|
+
}
|
41
|
+
|
42
|
+
param id: 1
|
43
|
+
|
44
|
+
get '/users/:id' do
|
45
|
+
status 200
|
46
|
+
validate schema
|
47
|
+
end
|
48
|
+
end
|
49
|
+
```
|
50
|
+
|
51
|
+
Run them
|
52
|
+
```
|
53
|
+
$ oncall
|
54
|
+
```
|
24
55
|
|
25
56
|
## Usage
|
26
57
|
|
@@ -36,3 +67,4 @@ This project is licensed under the MIT License - see the [LICENSE](LICENSE) file
|
|
36
67
|
## Acknowledgments
|
37
68
|
|
38
69
|
* Inspired by [rspec](https://github.com/rspec/rspec).
|
70
|
+
* And using [Ruby JSON Schema Validator](https://github.com/ruby-json-schema/json-schema).
|
data/bin/oncall
CHANGED
data/lib/oncall/cli.rb
CHANGED
@@ -1,24 +1,80 @@
|
|
1
|
-
|
1
|
+
module Oncall
|
2
|
+
# Manage the processing of command line options
|
3
|
+
class CLI
|
4
|
+
SCRIPT = 'oncall'
|
2
5
|
|
3
|
-
|
4
|
-
require_relative 'commands/init_command'
|
5
|
-
require_relative 'commands/run_command'
|
6
|
-
require_relative 'commands/shell_command'
|
6
|
+
attr_reader :args, :options
|
7
7
|
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
8
|
+
def initialize(args, options=Oncall.options)
|
9
|
+
@args = args
|
10
|
+
@options = options
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.run(args)
|
14
|
+
new(args).run
|
15
|
+
end
|
16
|
+
|
17
|
+
def run
|
18
|
+
begin
|
19
|
+
parser.parse!(args)
|
20
|
+
rescue OptionParser::InvalidOption => e
|
21
|
+
abort "#{SCRIPT}: #{e.message}\nPlease use --help for a listing of valid options"
|
22
|
+
rescue OptionParser::MissingArgument => e
|
23
|
+
abort "#{SCRIPT}: #{e.message}"
|
24
|
+
end
|
25
|
+
|
26
|
+
status = options.runner.run($stderr, $stdout)
|
27
|
+
exit(status) if status.is_a? Integer
|
28
|
+
end
|
29
|
+
|
30
|
+
private
|
31
|
+
|
32
|
+
def parser
|
33
|
+
OptionParser.new do |opt|
|
34
|
+
opt.on('--env ENV', String) do |env|
|
35
|
+
options.env= env
|
36
|
+
end
|
37
|
+
|
38
|
+
opt.on('--path PATH', String) do |path|
|
39
|
+
options.path= path
|
40
|
+
end
|
41
|
+
|
42
|
+
opt.on('--pattern PATTERN', String) do |pattern|
|
43
|
+
options.pattern= pattern
|
44
|
+
end
|
45
|
+
|
46
|
+
opt.on('--exclude PATTERN', String) do |pattern|
|
47
|
+
options.exclude= pattern
|
48
|
+
end
|
49
|
+
|
50
|
+
opt.on('--group GROUP', String) do |group|
|
51
|
+
options.group= group
|
52
|
+
end
|
53
|
+
|
54
|
+
opt.on('--persist PATH', String) do |path|
|
55
|
+
options.persist= path
|
56
|
+
end
|
57
|
+
|
58
|
+
opt.on('--config PATH', String) do |path|
|
59
|
+
options.config= path
|
60
|
+
end
|
61
|
+
|
62
|
+
opt.on('--init', '') do
|
63
|
+
options.runner= Oncall::Invocations::InitRunner.new
|
64
|
+
end
|
65
|
+
|
66
|
+
# This is for later
|
67
|
+
# opt.on('--console', '') do
|
68
|
+
# options.runner= Oncall::Invocations::ConsoleRunner.new
|
69
|
+
# end
|
70
|
+
|
71
|
+
opt.on('--version', '') do
|
72
|
+
options.runner= Oncall::Invocations::VersionRunner.new
|
73
|
+
end
|
74
|
+
|
75
|
+
opt.on_tail('--help', 'This help message') do
|
76
|
+
options.runner= Oncall::Invocations::HelpRunner.new(parser)
|
77
|
+
end
|
22
78
|
end
|
23
79
|
end
|
24
80
|
end
|
data/lib/oncall/dsl.rb
CHANGED
@@ -1,7 +1,85 @@
|
|
1
1
|
module Oncall
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
2
|
+
class DSL
|
3
|
+
private
|
4
|
+
|
5
|
+
attr_accessor :response, :request
|
6
|
+
attr_reader :reporter, :file, :http
|
7
|
+
|
8
|
+
public
|
9
|
+
|
10
|
+
def initialize(file, reporter)
|
11
|
+
@reporter = reporter
|
12
|
+
@file = file
|
13
|
+
@http = Net::HTTP.new('localhost', 4567)
|
14
|
+
@headers = { 'User-Agent' => "oncall/#{Oncall::VERSION}" }
|
15
|
+
@params = {}
|
16
|
+
@query = {}
|
17
|
+
@response = nil
|
18
|
+
@request = nil
|
19
|
+
end
|
20
|
+
|
21
|
+
def to_s
|
22
|
+
file
|
23
|
+
end
|
24
|
+
|
25
|
+
private
|
26
|
+
|
27
|
+
def group(name=nil, &block)
|
28
|
+
return reporter.empty_group(self) unless block_given?
|
29
|
+
|
30
|
+
instance_exec &block
|
31
|
+
end
|
32
|
+
|
33
|
+
def get(path, &block)
|
34
|
+
return reporter.empty_call(self) unless block_given?
|
35
|
+
|
36
|
+
uri = Oncall.uri(path, @params)
|
37
|
+
@request = Net::HTTP::Get.new(uri)
|
38
|
+
|
39
|
+
@headers.each do |key, value|
|
40
|
+
@request[key] = value
|
41
|
+
end
|
42
|
+
|
43
|
+
@response = http.request(request)
|
44
|
+
|
45
|
+
instance_exec &block
|
46
|
+
end
|
47
|
+
|
48
|
+
def post(path, &block)
|
49
|
+
return reporter.empty_call(self) unless block_given?
|
50
|
+
|
51
|
+
uri = Oncall.uri(path, @params)
|
52
|
+
@request = Net::HTTP::Post.new(uri)
|
53
|
+
|
54
|
+
@headers.each do |key, value|
|
55
|
+
@request[key] = value
|
56
|
+
end
|
57
|
+
|
58
|
+
@response = http.request(request)
|
59
|
+
|
60
|
+
instance_exec &block
|
61
|
+
end
|
62
|
+
|
63
|
+
def header(key_value)
|
64
|
+
key_value.each do |key, value|
|
65
|
+
@headers[key] = value
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
def param(key_value)
|
70
|
+
key_value.each do |key, value|
|
71
|
+
@params[key] = value
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
def validate(expected)
|
76
|
+
result = JSON::Validator.validate(expected, @response.body)
|
77
|
+
reporter.json_schema(self, result, expected)
|
78
|
+
end
|
79
|
+
|
80
|
+
def status(expected)
|
81
|
+
result = response.code == expected.to_s
|
82
|
+
reporter.status(self, result, expected)
|
83
|
+
end
|
6
84
|
end
|
7
85
|
end
|
@@ -0,0 +1,73 @@
|
|
1
|
+
module Oncall
|
2
|
+
module Invocations
|
3
|
+
class ConsoleRunner
|
4
|
+
def run(err, out); end
|
5
|
+
end
|
6
|
+
|
7
|
+
class HelpRunner
|
8
|
+
attr_reader :parser
|
9
|
+
|
10
|
+
def initialize(parser)
|
11
|
+
@parser = parser
|
12
|
+
end
|
13
|
+
|
14
|
+
def run(err, out)
|
15
|
+
out.puts parser
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
class InitRunner
|
20
|
+
def run(err, out)
|
21
|
+
config_template_path = File.join(File.dirname(__FILE__), 'templates', 'oncall.yml.template')
|
22
|
+
template = File.read(config_template_path)
|
23
|
+
|
24
|
+
File.open(File.join(Dir.getwd, 'oncall.yml'), 'w') do |file|
|
25
|
+
file.write(template)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
class VersionRunner
|
31
|
+
def run(err, out)
|
32
|
+
out.puts "Oncall: v#{Oncall::VERSION}"
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
class TestRunner
|
37
|
+
def run(err, out)
|
38
|
+
reporter.report do |r|
|
39
|
+
suite.map { |g| g.run(r) }
|
40
|
+
end
|
41
|
+
|
42
|
+
reporter.success? ? 0 : 1
|
43
|
+
end
|
44
|
+
|
45
|
+
private
|
46
|
+
|
47
|
+
def reporter
|
48
|
+
@reporter ||= Oncall::Reporter.new
|
49
|
+
end
|
50
|
+
|
51
|
+
def suite
|
52
|
+
files = []
|
53
|
+
|
54
|
+
test_files.each do |file|
|
55
|
+
test_file = Oncall::TestFile.new(file)
|
56
|
+
files << test_file
|
57
|
+
end
|
58
|
+
|
59
|
+
files
|
60
|
+
end
|
61
|
+
|
62
|
+
def test_files
|
63
|
+
matched_files = Dir.glob(options.pattern)
|
64
|
+
excluded_files = Dir.glob(options.exclude)
|
65
|
+
matched_files - excluded_files
|
66
|
+
end
|
67
|
+
|
68
|
+
def options
|
69
|
+
Oncall.options
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
module Oncall
|
2
|
+
class Options
|
3
|
+
attr_writer :runner
|
4
|
+
attr_accessor :env,
|
5
|
+
:pattern,
|
6
|
+
:exclude,
|
7
|
+
:group,
|
8
|
+
:persist,
|
9
|
+
:config,
|
10
|
+
:path
|
11
|
+
|
12
|
+
def initialize
|
13
|
+
@env = 'develop'
|
14
|
+
@pattern = '**{,/*/**}/*_oncall.rb'
|
15
|
+
@exclude = ''
|
16
|
+
@group = nil
|
17
|
+
@persist = nil
|
18
|
+
@config = nil
|
19
|
+
@path = nil
|
20
|
+
end
|
21
|
+
|
22
|
+
def runner
|
23
|
+
@runner ||= Oncall::Invocations::TestRunner.new
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,120 @@
|
|
1
|
+
require 'colorize'
|
2
|
+
|
3
|
+
module Oncall
|
4
|
+
class Reporter
|
5
|
+
attr_accessor :results
|
6
|
+
|
7
|
+
def initialize
|
8
|
+
@messages = []
|
9
|
+
@start_time = nil
|
10
|
+
@end_time = nil
|
11
|
+
@results = {
|
12
|
+
success: 0,
|
13
|
+
failed: 0,
|
14
|
+
warn: 0,
|
15
|
+
skipped: 0
|
16
|
+
}
|
17
|
+
end
|
18
|
+
|
19
|
+
def report
|
20
|
+
start
|
21
|
+
begin
|
22
|
+
yield self
|
23
|
+
ensure
|
24
|
+
finish
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def empty_group(test_case)
|
29
|
+
add_warn
|
30
|
+
report_empty_group
|
31
|
+
end
|
32
|
+
|
33
|
+
def empty_call(test_case)
|
34
|
+
add_skipped
|
35
|
+
report_empty_call
|
36
|
+
end
|
37
|
+
|
38
|
+
def status(test_case, result, expected)
|
39
|
+
if result
|
40
|
+
add_success
|
41
|
+
report_success
|
42
|
+
else
|
43
|
+
add_failed
|
44
|
+
report_failure
|
45
|
+
@messages << "#{test_case.to_s}: Expected status: #{expected}"
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
def json_schema(test_case, result, expected)
|
50
|
+
if result
|
51
|
+
add_success
|
52
|
+
report_success
|
53
|
+
else
|
54
|
+
add_failed
|
55
|
+
report_failure
|
56
|
+
@messages << "#{test_case.to_s}: JSON schema didn't match:\n#{expected}"
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
def success?
|
61
|
+
@results[:failed].zero?
|
62
|
+
end
|
63
|
+
|
64
|
+
private
|
65
|
+
|
66
|
+
def add_success
|
67
|
+
@results[:success] = @results[:success] + 1
|
68
|
+
end
|
69
|
+
|
70
|
+
def add_failed
|
71
|
+
@results[:failed] = @results[:failed] + 1
|
72
|
+
end
|
73
|
+
|
74
|
+
def add_warn
|
75
|
+
@results[:warn] = @results[:warn] + 1
|
76
|
+
end
|
77
|
+
|
78
|
+
def add_skipped
|
79
|
+
@results[:skipped] = @results[:skipped] + 1
|
80
|
+
end
|
81
|
+
|
82
|
+
def report_success
|
83
|
+
print '.'
|
84
|
+
end
|
85
|
+
|
86
|
+
def report_failure
|
87
|
+
print 'F'
|
88
|
+
end
|
89
|
+
|
90
|
+
def report_empty_group
|
91
|
+
print 'W'
|
92
|
+
end
|
93
|
+
|
94
|
+
def report_empty_call
|
95
|
+
print '*'
|
96
|
+
end
|
97
|
+
|
98
|
+
def start
|
99
|
+
@start_time = Time.now
|
100
|
+
end
|
101
|
+
|
102
|
+
def finish
|
103
|
+
@end_time = Time.now
|
104
|
+
|
105
|
+
puts "\n\n"
|
106
|
+
puts @messages
|
107
|
+
|
108
|
+
elapsed_seconds = (@end_time.to_f - @start_time.to_f).to_f
|
109
|
+
puts "\nFinished in #{elapsed_seconds.round(4)} seconds"
|
110
|
+
|
111
|
+
result = "#{@results[:success]} passed.\n#{@results[:failed]} failed.\n#{@results[:warn]} warnings.\n#{@results[:skipped]} skipped.\n"
|
112
|
+
|
113
|
+
if success?
|
114
|
+
puts result.green
|
115
|
+
else
|
116
|
+
puts result.red
|
117
|
+
end
|
118
|
+
end
|
119
|
+
end
|
120
|
+
end
|
data/lib/oncall/version.rb
CHANGED
data/lib/oncall.rb
CHANGED
@@ -7,5 +7,33 @@ require 'json-schema'
|
|
7
7
|
|
8
8
|
# Oncall
|
9
9
|
module Oncall
|
10
|
-
|
10
|
+
require_relative 'oncall/cli'
|
11
|
+
require_relative 'oncall/dsl'
|
12
|
+
require_relative 'oncall/options'
|
13
|
+
require_relative 'oncall/invocations'
|
14
|
+
require_relative 'oncall/test_file'
|
15
|
+
require_relative 'oncall/reporter'
|
16
|
+
require_relative 'oncall/version'
|
17
|
+
|
18
|
+
class << self
|
19
|
+
attr_writer :options
|
20
|
+
end
|
21
|
+
|
22
|
+
def self.options
|
23
|
+
@options ||= Oncall::Options.new
|
24
|
+
end
|
25
|
+
|
26
|
+
def self.uri(path, params)
|
27
|
+
parts = path.split('/')
|
28
|
+
return '/' if parts.empty?
|
29
|
+
|
30
|
+
parts.each_with_index do |part, index|
|
31
|
+
if part.start_with?(':')
|
32
|
+
part[0] = ''
|
33
|
+
parts[index] = params[part.to_sym]
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
parts.join('/')
|
38
|
+
end
|
11
39
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: oncall
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Koen Woortman
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-11-
|
11
|
+
date: 2019-11-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: colorize
|
@@ -80,7 +80,7 @@ dependencies:
|
|
80
80
|
- - '='
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: 2.0.7
|
83
|
-
description: '
|
83
|
+
description: BDD for JSON API's
|
84
84
|
email: koensw@outlook.com
|
85
85
|
executables:
|
86
86
|
- oncall
|
@@ -92,29 +92,19 @@ files:
|
|
92
92
|
- bin/oncall
|
93
93
|
- lib/oncall.rb
|
94
94
|
- lib/oncall/cli.rb
|
95
|
-
- lib/oncall/
|
96
|
-
- lib/oncall/commands/init_command.rb
|
97
|
-
- lib/oncall/commands/run_command.rb
|
98
|
-
- lib/oncall/commands/shell_command.rb
|
99
|
-
- lib/oncall/core.rb
|
100
|
-
- lib/oncall/core/config.rb
|
101
|
-
- lib/oncall/core/reporter.rb
|
102
|
-
- lib/oncall/core/runner.rb
|
103
|
-
- lib/oncall/core/world.rb
|
104
|
-
- lib/oncall/core/wrapper.rb
|
95
|
+
- lib/oncall/config.rb
|
105
96
|
- lib/oncall/dsl.rb
|
106
|
-
- lib/oncall/
|
107
|
-
- lib/oncall/
|
108
|
-
- lib/oncall/
|
109
|
-
- lib/oncall/http.rb
|
110
|
-
- lib/oncall/http/request.rb
|
111
|
-
- lib/oncall/http/response.rb
|
97
|
+
- lib/oncall/invocations.rb
|
98
|
+
- lib/oncall/options.rb
|
99
|
+
- lib/oncall/reporter.rb
|
112
100
|
- lib/oncall/templates/oncall.yml.template
|
101
|
+
- lib/oncall/test_file.rb
|
113
102
|
- lib/oncall/version.rb
|
114
|
-
homepage:
|
103
|
+
homepage: https://github.com/koenwoortman/oncall
|
115
104
|
licenses:
|
116
105
|
- MIT
|
117
|
-
metadata:
|
106
|
+
metadata:
|
107
|
+
bug_tracker_uri: https://github.com/koenwoortman/oncall/issues
|
118
108
|
post_install_message:
|
119
109
|
rdoc_options: []
|
120
110
|
require_paths:
|
@@ -1,32 +0,0 @@
|
|
1
|
-
require_relative '../version'
|
2
|
-
|
3
|
-
module Oncall
|
4
|
-
module Commands
|
5
|
-
class BaseCommand
|
6
|
-
def self.invoke(args)
|
7
|
-
OptionParser.new do |opts|
|
8
|
-
opts.banner = 'Usage: oncall'
|
9
|
-
opts.separator ''
|
10
|
-
opts.separator 'Commands:'
|
11
|
-
opts.separator ' init Create an empty oncall project.'
|
12
|
-
opts.separator ' run [ENV] Run the test suite.'
|
13
|
-
opts.separator ''
|
14
|
-
opts.separator 'Options:'
|
15
|
-
|
16
|
-
opts.on('--version', 'Show version information.') do
|
17
|
-
puts "oncall: version #{Oncall::VERSION}"
|
18
|
-
exit
|
19
|
-
end
|
20
|
-
|
21
|
-
opts.on('--help', 'Display this help message.') do
|
22
|
-
puts opts
|
23
|
-
exit
|
24
|
-
end
|
25
|
-
|
26
|
-
puts opts
|
27
|
-
exit
|
28
|
-
end.parse!
|
29
|
-
end
|
30
|
-
end
|
31
|
-
end
|
32
|
-
end
|
@@ -1,16 +0,0 @@
|
|
1
|
-
module Oncall
|
2
|
-
module Commands
|
3
|
-
class InitCommand
|
4
|
-
def self.invoke(args)
|
5
|
-
config_template_path = File.join(File.dirname(__FILE__), '..', 'templates', 'oncall.yml.template')
|
6
|
-
template = File.read(config_template_path)
|
7
|
-
|
8
|
-
File.open(File.join(Dir.getwd, 'oncall.yml'), 'w') do |file|
|
9
|
-
file.write(template)
|
10
|
-
end
|
11
|
-
|
12
|
-
exit
|
13
|
-
end
|
14
|
-
end
|
15
|
-
end
|
16
|
-
end
|
@@ -1,17 +0,0 @@
|
|
1
|
-
require 'readline'
|
2
|
-
|
3
|
-
module Oncall
|
4
|
-
module Commands
|
5
|
-
class ShellCommand
|
6
|
-
def self.invoke(args)
|
7
|
-
while input = Readline.readline("> ", true)
|
8
|
-
break if input == "exit"
|
9
|
-
|
10
|
-
# Remove blank lines from history
|
11
|
-
Readline::HISTORY.pop if input == ""
|
12
|
-
system(input)
|
13
|
-
end
|
14
|
-
end
|
15
|
-
end
|
16
|
-
end
|
17
|
-
end
|
data/lib/oncall/core/config.rb
DELETED
@@ -1,40 +0,0 @@
|
|
1
|
-
module Oncall
|
2
|
-
module Core
|
3
|
-
class Config
|
4
|
-
DEFAULT_PATTERN = '**{,/*/**}/*_oncall.rb'.freeze
|
5
|
-
|
6
|
-
def initialize
|
7
|
-
@config = []
|
8
|
-
@env = 'develop'
|
9
|
-
end
|
10
|
-
|
11
|
-
def set_config(config)
|
12
|
-
@config = config
|
13
|
-
end
|
14
|
-
|
15
|
-
def set_env(env)
|
16
|
-
@env = env
|
17
|
-
end
|
18
|
-
|
19
|
-
def pattern
|
20
|
-
DEFAULT_PATTERN
|
21
|
-
end
|
22
|
-
|
23
|
-
def failure_exit_code
|
24
|
-
1
|
25
|
-
end
|
26
|
-
|
27
|
-
def domain
|
28
|
-
@config[@env]['domain'] || 'localhost'
|
29
|
-
end
|
30
|
-
|
31
|
-
def port
|
32
|
-
@config[@env]['port'] || 4567
|
33
|
-
end
|
34
|
-
|
35
|
-
def test_files
|
36
|
-
Dir.glob(pattern)
|
37
|
-
end
|
38
|
-
end
|
39
|
-
end
|
40
|
-
end
|
data/lib/oncall/core/reporter.rb
DELETED
@@ -1,70 +0,0 @@
|
|
1
|
-
require 'colorize'
|
2
|
-
|
3
|
-
module Oncall
|
4
|
-
module Core
|
5
|
-
class Reporter
|
6
|
-
def initialize
|
7
|
-
@results = {
|
8
|
-
failure: 0,
|
9
|
-
success: 0,
|
10
|
-
empty: 0
|
11
|
-
}
|
12
|
-
|
13
|
-
@start_time = nil
|
14
|
-
@end_time = nil
|
15
|
-
@messages = []
|
16
|
-
end
|
17
|
-
|
18
|
-
def report(tests)
|
19
|
-
start
|
20
|
-
begin
|
21
|
-
yield self
|
22
|
-
ensure
|
23
|
-
finish
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
def start
|
28
|
-
@start_time = Time.now
|
29
|
-
end
|
30
|
-
|
31
|
-
def finish
|
32
|
-
@end_time = Time.now
|
33
|
-
|
34
|
-
puts "\n\n"
|
35
|
-
puts @messages
|
36
|
-
|
37
|
-
elapsed_seconds = (@end_time.to_f - @start_time.to_f).to_f
|
38
|
-
puts "Finished in #{elapsed_seconds.round(4)} seconds"
|
39
|
-
|
40
|
-
result = "#{@results[:success]} passed, #{@results[:failure]} failed.\n"
|
41
|
-
|
42
|
-
if success?
|
43
|
-
puts result.green
|
44
|
-
else
|
45
|
-
puts result.red
|
46
|
-
end
|
47
|
-
end
|
48
|
-
|
49
|
-
def success?
|
50
|
-
@results[:failure].zero? && @results[:empty].zero?
|
51
|
-
end
|
52
|
-
|
53
|
-
def report_empty_group
|
54
|
-
print '*'
|
55
|
-
@results[:empty] = @results[:empty] + 1
|
56
|
-
end
|
57
|
-
|
58
|
-
def report_status(result, message)
|
59
|
-
if result
|
60
|
-
print '.'
|
61
|
-
@results[:success] = @results[:success] + 1
|
62
|
-
else
|
63
|
-
print 'F'
|
64
|
-
@results[:failure] = @results[:failure] + 1
|
65
|
-
@messages << message
|
66
|
-
end
|
67
|
-
end
|
68
|
-
end
|
69
|
-
end
|
70
|
-
end
|
data/lib/oncall/core/runner.rb
DELETED
@@ -1,50 +0,0 @@
|
|
1
|
-
module Oncall
|
2
|
-
module Core
|
3
|
-
class Runner
|
4
|
-
def initialize(reporter=Oncall::Core.reporter, config=Oncall::Core.config, world=Oncall::Core.world)
|
5
|
-
@config = config
|
6
|
-
@world = world
|
7
|
-
@reporter = reporter
|
8
|
-
end
|
9
|
-
|
10
|
-
def self.invoke(args)
|
11
|
-
status = run(args, $stderr, $stdout).to_i
|
12
|
-
exit(status) if status != 0
|
13
|
-
end
|
14
|
-
|
15
|
-
def self.run(args, err=$stderr, out=$stdout)
|
16
|
-
new.run(args, err, out)
|
17
|
-
end
|
18
|
-
|
19
|
-
def run(args, err, out)
|
20
|
-
setup(args, err, out)
|
21
|
-
run_tests(@world.suite)
|
22
|
-
end
|
23
|
-
|
24
|
-
def setup(args, err, out)
|
25
|
-
begin
|
26
|
-
config = YAML.load_file('oncall.yml')
|
27
|
-
rescue StandardError
|
28
|
-
puts 'Cannot load oncall.yml'
|
29
|
-
exit 1
|
30
|
-
end
|
31
|
-
|
32
|
-
env = args[1] || config['default']
|
33
|
-
|
34
|
-
@config.set_config(config)
|
35
|
-
@config.set_env(env)
|
36
|
-
|
37
|
-
files = @config.test_files
|
38
|
-
@world.register_suite(files)
|
39
|
-
end
|
40
|
-
|
41
|
-
def run_tests(suite)
|
42
|
-
@reporter.report(suite) do |reporter|
|
43
|
-
suite.map { |g| g.run(reporter) }
|
44
|
-
end
|
45
|
-
|
46
|
-
@reporter.success? ? 0 : @config.failure_exit_code
|
47
|
-
end
|
48
|
-
end
|
49
|
-
end
|
50
|
-
end
|
data/lib/oncall/core/world.rb
DELETED
@@ -1,19 +0,0 @@
|
|
1
|
-
module Oncall
|
2
|
-
module Core
|
3
|
-
class World
|
4
|
-
|
5
|
-
attr_reader :suite
|
6
|
-
|
7
|
-
def initialize
|
8
|
-
@suite = []
|
9
|
-
end
|
10
|
-
|
11
|
-
def register_suite(files)
|
12
|
-
files.each do |file|
|
13
|
-
wrapper = Oncall::Core::Wrapper.new(file)
|
14
|
-
@suite << wrapper
|
15
|
-
end
|
16
|
-
end
|
17
|
-
end
|
18
|
-
end
|
19
|
-
end
|
data/lib/oncall/core/wrapper.rb
DELETED
data/lib/oncall/core.rb
DELETED
@@ -1,25 +0,0 @@
|
|
1
|
-
module Oncall
|
2
|
-
module Core
|
3
|
-
require_relative 'core/config'
|
4
|
-
require_relative 'core/reporter'
|
5
|
-
require_relative 'core/runner'
|
6
|
-
require_relative 'core/world'
|
7
|
-
require_relative 'core/wrapper'
|
8
|
-
|
9
|
-
class << self
|
10
|
-
attr_writer :config, :world, :reporter
|
11
|
-
end
|
12
|
-
|
13
|
-
def self.config
|
14
|
-
@config ||= Oncall::Core::Config.new
|
15
|
-
end
|
16
|
-
|
17
|
-
def self.world
|
18
|
-
@world ||= Oncall::Core::World.new
|
19
|
-
end
|
20
|
-
|
21
|
-
def self.reporter
|
22
|
-
@reporter ||= Oncall::Core::Reporter.new
|
23
|
-
end
|
24
|
-
end
|
25
|
-
end
|
data/lib/oncall/dsl/assertion.rb
DELETED
@@ -1,28 +0,0 @@
|
|
1
|
-
module Oncall
|
2
|
-
module DSL
|
3
|
-
class Assertion
|
4
|
-
def initialize(response, method, path)
|
5
|
-
@reporter = Oncall::Core.reporter
|
6
|
-
@response = response
|
7
|
-
@method = method
|
8
|
-
@path = path
|
9
|
-
end
|
10
|
-
|
11
|
-
def status(expected)
|
12
|
-
result = @response.code == expected.to_s
|
13
|
-
|
14
|
-
message = "#{@method} #{@path}\nexpected: #{expected}\nactual: #{@response.code}"
|
15
|
-
|
16
|
-
@reporter.report_status(result, message)
|
17
|
-
end
|
18
|
-
|
19
|
-
def validate(expected)
|
20
|
-
result = JSON::Validator.validate(expected, @response.body)
|
21
|
-
|
22
|
-
message = "#{@method} #{@path}\nexpected: #{expected}\nactual: #{@response.body}"
|
23
|
-
|
24
|
-
@reporter.report_status(result, message)
|
25
|
-
end
|
26
|
-
end
|
27
|
-
end
|
28
|
-
end
|
data/lib/oncall/dsl/call.rb
DELETED
@@ -1,54 +0,0 @@
|
|
1
|
-
require_relative '../http'
|
2
|
-
|
3
|
-
module Oncall
|
4
|
-
module DSL
|
5
|
-
class Call
|
6
|
-
def initialize
|
7
|
-
@config = Oncall::Core.config
|
8
|
-
@http = Net::HTTP.new(@config.domain, @config.port)
|
9
|
-
@headers = { 'User-Agent' => "oncall/#{Oncall::VERSION}" }
|
10
|
-
@params = {}
|
11
|
-
end
|
12
|
-
|
13
|
-
def header(hash)
|
14
|
-
hash.each do |key, value|
|
15
|
-
@headers[key] = value
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
def param(hash)
|
20
|
-
hash.each do |key, value|
|
21
|
-
@params[key] = value
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
|
-
def get(path, &block)
|
26
|
-
uri = Oncall::HTTP.uri(path, @params)
|
27
|
-
request = Net::HTTP::Get.new(uri)
|
28
|
-
|
29
|
-
@headers.each do |key, value|
|
30
|
-
request[key] = value
|
31
|
-
end
|
32
|
-
|
33
|
-
response = @http.request(request)
|
34
|
-
|
35
|
-
assertion = Oncall::DSL::Assertion.new(response, 'GET', path)
|
36
|
-
assertion.instance_exec(&block)
|
37
|
-
end
|
38
|
-
|
39
|
-
def post(path, &block)
|
40
|
-
uri = Oncall::HTTP.uri(path, @params)
|
41
|
-
request = Net::HTTP::Post.new(uri)
|
42
|
-
|
43
|
-
@headers.each do |key, value|
|
44
|
-
request[key] = value
|
45
|
-
end
|
46
|
-
|
47
|
-
response = @http.request(request)
|
48
|
-
|
49
|
-
assertion = Oncall::DSL::Assertion.new(response, 'POST', path)
|
50
|
-
assertion.instance_exec(&block)
|
51
|
-
end
|
52
|
-
end
|
53
|
-
end
|
54
|
-
end
|
data/lib/oncall/dsl/group.rb
DELETED
@@ -1,18 +0,0 @@
|
|
1
|
-
module Oncall
|
2
|
-
module DSL
|
3
|
-
class Group
|
4
|
-
def initialize
|
5
|
-
@reporter = Oncall::Core.reporter
|
6
|
-
end
|
7
|
-
|
8
|
-
def group(name=nil, &block)
|
9
|
-
if block_given?
|
10
|
-
scenario = Oncall::DSL::Call.new
|
11
|
-
scenario.instance_exec &block
|
12
|
-
else
|
13
|
-
@reporter.report_empty_group
|
14
|
-
end
|
15
|
-
end
|
16
|
-
end
|
17
|
-
end
|
18
|
-
end
|
data/lib/oncall/http/request.rb
DELETED
data/lib/oncall/http/response.rb
DELETED
data/lib/oncall/http.rb
DELETED
@@ -1,17 +0,0 @@
|
|
1
|
-
module Oncall
|
2
|
-
module HTTP
|
3
|
-
def self.uri(path, params)
|
4
|
-
parts = path.split('/')
|
5
|
-
return '/' if parts.empty?
|
6
|
-
|
7
|
-
parts.each_with_index do |part, index|
|
8
|
-
if part.start_with?(':')
|
9
|
-
part[0] = ''
|
10
|
-
parts[index] = params[part.to_sym]
|
11
|
-
end
|
12
|
-
end
|
13
|
-
|
14
|
-
parts.join('/')
|
15
|
-
end
|
16
|
-
end
|
17
|
-
end
|