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 +4 -4
- data/CHANGELOG.md +4 -1
- data/Gemfile.lock +1 -17
- data/README.md +15 -0
- data/lib/faastruby-rpc/function.rb +16 -1
- data/lib/faastruby-rpc/test_helper.rb +14 -0
- data/lib/faastruby-rpc/version.rb +1 -1
- data/lib/faastruby-rpc.rb +1 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6156f5bfcd486038697b1ba4e232093527fe1794c7616ab12405047a1e2659fd
|
4
|
+
data.tar.gz: 8cc0fd2b4c0c954bf71034335a77696ec96d337e8cae58ad587722772d5f1be8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4af94ef769bfe71c805c5896ce1d07bba252f335ccad7c856189fcfc9c40d1dcd6175db6db08e200cb92c0d16bedf216b143cd64ea706703599793c7ba6bfbb0
|
7
|
+
data.tar.gz: 06cd23c88f89e7394b9374dfadf5d597c38f45435f7500dd66864e6fd7a56396dd18754cfe2818af7746de3f61deb2629fdd64d81a6982217b9e921ef983d29b
|
data/CHANGELOG.md
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,9 +1,8 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
faastruby-rpc (0.1.
|
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']
|
data/lib/faastruby-rpc.rb
CHANGED
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.
|
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-
|
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:
|