oncall 0.1.4 → 0.2.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 31d579e917f9d0d901321e0d2338a6634242af577d39cc47aa03d6a16ca320bd
4
- data.tar.gz: 2d8ed801f79a30dfe9bd2229b5e480fbc1886fdd242383933afa7f1cdc171c5b
3
+ metadata.gz: 21e2e79f1d7b3f98525a89c1cb973f23f5f8f4f3962d5be9a7ed5f9585db5296
4
+ data.tar.gz: 074252b3271d4a441257b5fa171208ce33ac3f827f898cef75a9e93b6d81dc37
5
5
  SHA512:
6
- metadata.gz: d40805eb76731aa2759b4ead7d1ab76bbafae194b4117605972edd62f4d2f5c947201a18266176df99861682aa28e9360dfa008d03bb64c43dc76c8e355ae326
7
- data.tar.gz: fa7d697ca82deb7b7b793667f324ff7af89530339b9584dc2b4e79cf958258e2e8c39ef2c8eeeb088431b1f79e3665fb7c04ce6f731900b2ec9363b2da345ef3
6
+ metadata.gz: 37fbc99650d45997051797f65df88e3db15c32275f4db054bf46a689182a5b1580fde0e8a80eb67658f48fe84e7f848d26b145308bfa9afa0d2eeb42aa65a764
7
+ data.tar.gz: e9df5052851e20e227d61b4a51f8e9d6fbae36438233662f5b1fe1679a57940f803bf9af11f04c2f7baf08521067b33570d2fc0511538a20a4a0d6db7ef6377b
data/lib/oncall/cli.rb CHANGED
@@ -3,6 +3,7 @@
3
3
  require_relative 'commands/base_command'
4
4
  require_relative 'commands/init_command'
5
5
  require_relative 'commands/run_command'
6
+ require_relative 'commands/shell_command'
6
7
 
7
8
  module Oncall
8
9
  module CLI
@@ -14,6 +15,8 @@ module Oncall
14
15
  Oncall::Commands::InitCommand.invoke(ARGV.shift)
15
16
  when 'run'
16
17
  Oncall::Commands::RunCommand.invoke(ARGV.shift)
18
+ when 'shell'
19
+ Oncall::Commands::ShellCommand.invoke(ARGV.shift)
17
20
  else
18
21
  Oncall::Commands::BaseCommand.invoke(ARGV)
19
22
  end
@@ -1,10 +1,10 @@
1
+ require_relative '../core'
2
+
1
3
  module Oncall
2
4
  module Commands
3
5
  class RunCommand
4
6
  def self.invoke(args)
5
- env = ARGV[0]
6
- runner = Oncall::Runner.new(env)
7
- exit runner.run.to_i
7
+ Oncall::Core::Runner.invoke(args)
8
8
  end
9
9
  end
10
10
  end
@@ -0,0 +1,8 @@
1
+ module Oncall
2
+ module Commands
3
+ class ShellCommand
4
+ def self.invoke(args)
5
+ end
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,15 @@
1
+ module Oncall
2
+ module Core
3
+ class Assertion
4
+ def initialize(response)
5
+ @reporter = Oncall::Core.reporter
6
+ @response = response
7
+ end
8
+
9
+ def status(expected)
10
+ result = @response.code == expected.to_s
11
+ @reporter.report_status(result)
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,23 @@
1
+ module Oncall
2
+ module Core
3
+ class Config
4
+ DEFAULT_PATTERN = '**{,/*/**}/*_oncall.rb'.freeze
5
+
6
+ def initialize
7
+ @files = []
8
+ end
9
+
10
+ def pattern
11
+ DEFAULT_PATTERN
12
+ end
13
+
14
+ def failure_exit_code
15
+ 1
16
+ end
17
+
18
+ def test_files
19
+ Dir.glob(pattern)
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,18 @@
1
+ module Oncall
2
+ module Core
3
+ class Group
4
+ def initialize
5
+ @reporter = Oncall::Core.reporter
6
+ end
7
+
8
+ def describe(&block)
9
+ if block_given?
10
+ scenario = Oncall::Core::Scenario.new
11
+ scenario.instance_exec &block
12
+ else
13
+ @reporter.report_empty_group
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,49 @@
1
+ module Oncall
2
+ module Core
3
+ class Reporter
4
+ def initialize
5
+ @results = {
6
+ failure: 0,
7
+ success: 0,
8
+ empty: 0
9
+ }
10
+ end
11
+
12
+ def report(tests)
13
+ start
14
+ begin
15
+ yield self
16
+ ensure
17
+ finish
18
+ end
19
+ end
20
+
21
+ def start
22
+ end
23
+
24
+ def finish
25
+ puts "\n"
26
+ puts "#{@results[:success]} passed, #{@results[:failure]} failed."
27
+ end
28
+
29
+ def success?
30
+ @results[:failure].zero? && @results[:empty].zero?
31
+ end
32
+
33
+ def report_empty_group
34
+ print 'E'
35
+ @results[:empty] = @results[:empty] + 1
36
+ end
37
+
38
+ def report_status(result)
39
+ if result
40
+ print '.'
41
+ @results[:success] = @results[:success] + 1
42
+ else
43
+ print 'F'
44
+ @results[:failure] = @results[:failure] + 1
45
+ end
46
+ end
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,13 @@
1
+ module Oncall
2
+ module Core
3
+ class Request
4
+ def initialize(&block)
5
+ @proc = Proc.new &block
6
+ end
7
+
8
+ def call
9
+ @proc.call
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,39 @@
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
+ # TODO: init options class
17
+ new.run(err, out)
18
+ end
19
+
20
+ def run(err, out)
21
+ setup(err, out)
22
+ run_tests(@world.suite)
23
+ end
24
+
25
+ def setup(err, out)
26
+ files = @config.test_files
27
+ @world.register_suite(files)
28
+ end
29
+
30
+ def run_tests(suite)
31
+ @reporter.report(suite) do |reporter|
32
+ suite.map { |g| g.run(reporter) }
33
+ end
34
+
35
+ @reporter.success? ? 0 : @config.failure_exit_code
36
+ end
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,14 @@
1
+ module Oncall
2
+ module Core
3
+ class Scenario
4
+ def get(path, &block)
5
+ http = Net::HTTP.new('localhost', 4567)
6
+ request = Net::HTTP::Get.new(path)
7
+ response = http.request(request)
8
+
9
+ assertion = Oncall::Core::Assertion.new(response)
10
+ assertion.instance_exec(&block)
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,19 @@
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
@@ -0,0 +1,13 @@
1
+ module Oncall
2
+ module Core
3
+ class Wrapper
4
+ def initialize(file)
5
+ @file = file
6
+ end
7
+
8
+ def run(reporter)
9
+ Oncall::Core::Group.new.instance_eval File.read(@file)
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,31 @@
1
+ module Oncall
2
+ module Core
3
+ require_relative 'core/assertion'
4
+ require_relative 'core/config'
5
+ require_relative 'core/group'
6
+ require_relative 'core/reporter'
7
+ require_relative 'core/request'
8
+ require_relative 'core/runner'
9
+ require_relative 'core/scenario'
10
+ require_relative 'core/world'
11
+ require_relative 'core/wrapper'
12
+
13
+ STATUS_EMPTY = :empty
14
+
15
+ class << self
16
+ attr_writer :config, :world
17
+ end
18
+
19
+ def self.config
20
+ @config ||= Oncall::Core::Config.new
21
+ end
22
+
23
+ def self.world
24
+ @world ||= Oncall::Core::World.new
25
+ end
26
+
27
+ def self.reporter
28
+ @reporter ||= Oncall::Core::Reporter.new
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,17 @@
1
+ module Oncall
2
+ class Response
3
+ def initialize(request)
4
+ @request = request
5
+ end
6
+
7
+ private
8
+
9
+ def status(code)
10
+ if @request.code == code
11
+ true
12
+ else
13
+ 'failed'
14
+ end
15
+ end
16
+ end
17
+ end
data/lib/oncall/dsl.rb CHANGED
@@ -1,4 +1,32 @@
1
+ require_relative 'dsl/response'
2
+
1
3
  module Oncall
2
- module DSL
4
+ class DSL
5
+ private
6
+
7
+ def describe(group, &block)
8
+ if block_given?
9
+ begin
10
+ yield
11
+ end
12
+ else
13
+ # Return status empty
14
+ end
15
+ end
16
+
17
+ def get(path, &block)
18
+ if block_given?
19
+ http = Net::HTTP.new('localhost', 4567)
20
+ request = Net::HTTP::Get.new(path)
21
+ response = Oncall::Response.new(http.request(request))
22
+
23
+ begin
24
+ resuls = response.instance_eval &block
25
+ resuls
26
+ end
27
+ else
28
+ # Return status empty
29
+ end
30
+ end
3
31
  end
4
32
  end
@@ -0,0 +1,4 @@
1
+ module Oncall
2
+ module HTTP
3
+ end
4
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Oncall
4
- VERSION = '0.1.4'
4
+ VERSION = '0.2.0'
5
5
  end
data/lib/oncall.rb CHANGED
@@ -7,10 +7,5 @@ require 'json-schema'
7
7
 
8
8
  # Oncall
9
9
  module Oncall
10
- require File.expand_path(File.join(File.dirname(__FILE__), 'oncall', 'body_test'))
11
10
  require File.expand_path(File.join(File.dirname(__FILE__), 'oncall', 'cli'))
12
- require File.expand_path(File.join(File.dirname(__FILE__), 'oncall', 'request'))
13
- require File.expand_path(File.join(File.dirname(__FILE__), 'oncall', 'test_case'))
14
- require File.expand_path(File.join(File.dirname(__FILE__), 'oncall', 'test_wrapper'))
15
- require File.expand_path(File.join(File.dirname(__FILE__), 'oncall', 'runner'))
16
11
  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.1.4
4
+ version: 0.2.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-10-30 00:00:00.000000000 Z
11
+ date: 2019-11-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: json-schema
@@ -76,18 +76,25 @@ files:
76
76
  - README.md
77
77
  - bin/oncall
78
78
  - lib/oncall.rb
79
- - lib/oncall/body_test.rb
80
79
  - lib/oncall/cli.rb
81
80
  - lib/oncall/commands/base_command.rb
82
81
  - lib/oncall/commands/init_command.rb
83
82
  - lib/oncall/commands/run_command.rb
84
- - lib/oncall/configuration.rb
83
+ - lib/oncall/commands/shell_command.rb
84
+ - lib/oncall/core.rb
85
+ - lib/oncall/core/assertion.rb
86
+ - lib/oncall/core/config.rb
87
+ - lib/oncall/core/group.rb
88
+ - lib/oncall/core/reporter.rb
89
+ - lib/oncall/core/request.rb
90
+ - lib/oncall/core/runner.rb
91
+ - lib/oncall/core/scenario.rb
92
+ - lib/oncall/core/world.rb
93
+ - lib/oncall/core/wrapper.rb
85
94
  - lib/oncall/dsl.rb
86
- - lib/oncall/request.rb
87
- - lib/oncall/runner.rb
95
+ - lib/oncall/dsl/response.rb
96
+ - lib/oncall/http.rb
88
97
  - lib/oncall/templates/oncall.yml.template
89
- - lib/oncall/test_case.rb
90
- - lib/oncall/test_wrapper.rb
91
98
  - lib/oncall/version.rb
92
99
  homepage:
93
100
  licenses:
@@ -1,20 +0,0 @@
1
- module Oncall
2
- class BodyTest
3
- def initialize(body, description)
4
- @body = body
5
- @description = description
6
- @result = false
7
- end
8
-
9
- def run(&block)
10
- instance_eval(&block)
11
- @result
12
- end
13
-
14
- private
15
-
16
- def matches(schema)
17
- @result = JSON::Validator.validate(schema, @body)
18
- end
19
- end
20
- end
@@ -1,5 +0,0 @@
1
- module Oncall
2
- class Configuration
3
- DEFAULT_PATTERN = '**{,/*/**}/*_oncall.rb'.freeze
4
- end
5
- end
@@ -1,52 +0,0 @@
1
- module Oncall
2
- class Request
3
- def initialize(config, endpoint)
4
- @config = config
5
- @endpoint = endpoint
6
- @headers = {}
7
- @expectations = []
8
- @http = nil
9
- @response = nil
10
- @request = nil
11
- end
12
-
13
- def bootstrap
14
- @http = Net::HTTP.new(@config['domain'], @config['port'])
15
-
16
- @request = Net::HTTP::Get.new(@endpoint)
17
-
18
- @request['User-Agent'] = 'Oncall'
19
-
20
- @headers.each do |key, value|
21
- request[key] = value
22
- end
23
-
24
- end
25
-
26
- def run(&block)
27
- @response = @http.request(@request)
28
-
29
- instance_eval(&block)
30
- end
31
-
32
- private
33
-
34
- def header(header)
35
- @headers.merge!(header)
36
- end
37
-
38
- def body(description, &block)
39
- result = Oncall::BodyTest.new(@response.body, description).run(&block)
40
- puts "Endpoint: #{@endpoint} -----"
41
- puts " Body: #{description}: #{result}"
42
- end
43
-
44
- def status(description, &block)
45
- @expectations.push(description)
46
- end
47
-
48
- def profiler(description, &block)
49
- @expectations.push(description)
50
- end
51
- end
52
- end
data/lib/oncall/runner.rb DELETED
@@ -1,49 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Oncall
4
- class Runner
5
- DEFAULT_PATTERN = '**{,/*/**}/*_oncall.rb'
6
-
7
- def initialize(env)
8
- @config = {}
9
- @pattern = DEFAULT_PATTERN
10
- @test_wrapper = Oncall::TestWrapper.new
11
- @env = env
12
- end
13
-
14
- def run
15
- begin
16
- config = YAML.load_file('oncall.yml')
17
- merge_config(config)
18
- rescue StandardError
19
- puts 'Cannot load oncall.yml'
20
- exit 1
21
- end
22
-
23
- files = Dir.glob(@pattern)
24
-
25
- process_files(files)
26
- 0
27
- end
28
-
29
- def process_files(files)
30
- @test_wrapper.set_config(@config)
31
-
32
- files.each do |file|
33
- @test_wrapper.evaluate(file)
34
- end
35
- end
36
-
37
- private
38
-
39
- def merge_config(config)
40
- if config.key?(@env)
41
- @config = config[@env]
42
- elsif config.key?('default')
43
- @config = config[config['default']]
44
- else
45
- raise 'Config error'
46
- end
47
- end
48
- end
49
- end
@@ -1,24 +0,0 @@
1
- module Oncall
2
- class TestCase
3
-
4
- def initialize(config)
5
- @config = config
6
- end
7
-
8
- def run(file)
9
- instance_eval File.read(file)
10
- end
11
-
12
- def get(endpoint, &block)
13
- test = Oncall::Request.new(@config, endpoint)
14
- test.bootstrap
15
- test.run(&block)
16
- end
17
-
18
- def post(endpoint, &block)
19
- test = Oncall::Request.new(@config, endpoint)
20
- test.bootstrap(&block)
21
- test.run
22
- end
23
- end
24
- end
@@ -1,16 +0,0 @@
1
- module Oncall
2
- class TestWrapper
3
- def initialize
4
- @config = nil
5
- end
6
-
7
- def evaluate(file)
8
- test_case = Oncall::TestCase.new(@config)
9
- test_case.run(file)
10
- end
11
-
12
- def set_config(config)
13
- @config = config
14
- end
15
- end
16
- end