faastruby-rpc 0.1.2 → 0.1.3

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: a2abf85651d49e5de1fb2ab7f62cdad8b2a5033608f93e648a5dd1ccd5cbbf13
4
- data.tar.gz: 906271fdcd72e2acd967bec7ff12a55d73285056754af0b73d64a300aa006c95
3
+ metadata.gz: 6156f5bfcd486038697b1ba4e232093527fe1794c7616ab12405047a1e2659fd
4
+ data.tar.gz: 8cc0fd2b4c0c954bf71034335a77696ec96d337e8cae58ad587722772d5f1be8
5
5
  SHA512:
6
- metadata.gz: c9cb7ef8be2bb3c0b90b7c8690d913f2d93b619beadea3b5e377ed06f3f97b62a6169cdcfb87b5b96ddd1615415a383fb18696dabc63752aea856a71742ff94d
7
- data.tar.gz: 92ee278e10983377186ffebabae90579bf37913dfdca841af035b18660309956e53371b22a3033478f5cba99f7dedf88b1fc6b0851a9f6d4ee2bec59cbf61e63
6
+ metadata.gz: 4af94ef769bfe71c805c5896ce1d07bba252f335ccad7c856189fcfc9c40d1dcd6175db6db08e200cb92c0d16bedf216b143cd64ea706703599793c7ba6bfbb0
7
+ data.tar.gz: 06cd23c88f89e7394b9374dfadf5d597c38f45435f7500dd66864e6fd7a56396dd18754cfe2818af7746de3f61deb2629fdd64d81a6982217b9e921ef983d29b
data/CHANGELOG.md CHANGED
@@ -1,6 +1,9 @@
1
1
  # Changelog
2
2
 
3
- ## 0.1.2 - Dec 9 2018 - First release
3
+ ## 0.1.3 - Dec 15 2018
4
+ - Add test helper to stub invoke()
5
+
6
+ ## 0.1.2 - Dec 9 2018
4
7
  - Disable SSLv2, v3 and compression when calling invoke.
5
8
 
6
9
  ## 0.1.1 - Dec 9 2018 - First release
data/Gemfile.lock CHANGED
@@ -1,9 +1,8 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- faastruby-rpc (0.1.0)
4
+ faastruby-rpc (0.1.3)
5
5
  oj (~> 3.6)
6
- rest-client (~> 2.0)
7
6
 
8
7
  GEM
9
8
  remote: https://rubygems.org/
@@ -13,22 +12,10 @@ GEM
13
12
  crack (0.4.3)
14
13
  safe_yaml (~> 1.0.0)
15
14
  diff-lcs (1.3)
16
- domain_name (0.5.20180417)
17
- unf (>= 0.0.5, < 1.0.0)
18
15
  hashdiff (0.3.7)
19
- http-cookie (1.0.3)
20
- domain_name (~> 0.5)
21
- mime-types (3.2.2)
22
- mime-types-data (~> 3.2015)
23
- mime-types-data (3.2018.0812)
24
- netrc (0.11.0)
25
16
  oj (3.7.4)
26
17
  public_suffix (3.0.3)
27
18
  rake (10.5.0)
28
- rest-client (2.0.2)
29
- http-cookie (>= 1.0.2, < 2.0)
30
- mime-types (>= 1.16, < 4.0)
31
- netrc (~> 0.8)
32
19
  rspec (3.8.0)
33
20
  rspec-core (~> 3.8.0)
34
21
  rspec-expectations (~> 3.8.0)
@@ -43,9 +30,6 @@ GEM
43
30
  rspec-support (~> 3.8.0)
44
31
  rspec-support (3.8.0)
45
32
  safe_yaml (1.0.4)
46
- unf (0.1.4)
47
- unf_ext
48
- unf_ext (0.0.7.5)
49
33
  webmock (3.4.2)
50
34
  addressable (>= 2.3.6)
51
35
  crack (>= 0.3.2)
data/README.md CHANGED
@@ -61,3 +61,18 @@ invoke('paulo/hello', raise_errors: false).call
61
61
  # or
62
62
  FaaStRuby::RPC::Function.new("paulo/hello", raise_errors: false).call(body: nil)
63
63
  ```
64
+
65
+ ## Stubbing invoke() in your function tests
66
+ If you are testing a function that invokes another one, you likely will want to fake that call. To do that, use the following test helper:
67
+
68
+ ```ruby
69
+ # This will cause invoke('paulo/hello-world')... to fake the call to
70
+ # 'paulo/hello-world' and instead return the values you pass in the block.
71
+ require 'faastruby-rpc/test_helper'
72
+
73
+ FaaStRuby::RPC.stub_call('paulo/hello-world') do |response|
74
+ response.body = "hello, world!"
75
+ response.code = 200
76
+ response.headers = {'A-Header' => 'foobar'}
77
+ end
78
+ ```
@@ -1,6 +1,21 @@
1
1
  module FaaStRuby
2
2
  FAASTRUBY_HOST = ENV['FAASTRUBY_HOST'] || "http://localhost:3000"
3
3
  module RPC
4
+ @@response = {}
5
+ def self.stub_call(function_path, &block)
6
+ helper = TestHelper.new
7
+ block.call(helper)
8
+ response = Struct.new(:body, :code, :headers, :klass)
9
+ @@response[function_path] = response.new(helper.body, helper.code, helper.headers, helper.klass)
10
+ end
11
+ def self.stub_call?(path)
12
+ @@response[path]
13
+ end
14
+
15
+ def self.response(path)
16
+ @@response[path]
17
+ end
18
+
4
19
  class ExecutionError < StandardError
5
20
  end
6
21
  class Function
@@ -24,7 +39,7 @@ module FaaStRuby
24
39
  url = "#{FAASTRUBY_HOST}/#{@path}#{convert_query_params(query_params)}"
25
40
  uri = URI.parse(url)
26
41
  use_ssl = uri.scheme == 'https' ? true : false
27
- response = fetch(use_ssl: use_ssl, uri: uri, headers: headers, method: @methods[method], body: body)
42
+ response = FaaStRuby::RPC.stub_call?(@path) ? FaaStRuby::RPC.response(@path) : fetch(use_ssl: use_ssl, uri: uri, headers: headers, method: @methods[method], body: body)
28
43
  resp_headers = {}
29
44
  response.each{|k,v| resp_headers[k] = v}
30
45
  case resp_headers['content-type']
@@ -0,0 +1,14 @@
1
+ require 'faastruby-rpc'
2
+ module FaaStRuby
3
+ module RPC
4
+ class TestHelper
5
+ attr_accessor :body, :code, :headers, :klass
6
+ def initialize
7
+ @body = nil
8
+ @code = 200
9
+ @headers = {}
10
+ @klass = nil
11
+ end
12
+ end
13
+ end
14
+ end
@@ -1,5 +1,5 @@
1
1
  module FaaStRuby
2
2
  module RPC
3
- VERSION = '0.1.2'
3
+ VERSION = '0.1.3'
4
4
  end
5
5
  end
data/lib/faastruby-rpc.rb CHANGED
@@ -1,6 +1,7 @@
1
1
  require 'net/http'
2
2
  require 'oj'
3
3
  require 'yaml'
4
+ require 'openssl'
4
5
  require 'faastruby-rpc/version'
5
6
  require 'faastruby-rpc/function'
6
7
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: faastruby-rpc
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Paulo Arruda
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-12-10 00:00:00.000000000 Z
11
+ date: 2018-12-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: oj
@@ -101,6 +101,7 @@ files:
101
101
  - faastruby-rpc.gemspec
102
102
  - lib/faastruby-rpc.rb
103
103
  - lib/faastruby-rpc/function.rb
104
+ - lib/faastruby-rpc/test_helper.rb
104
105
  - lib/faastruby-rpc/version.rb
105
106
  homepage: https://github.com/faastruby/faastruby-rpc
106
107
  licenses: