saddle 0.2.0 → 0.2.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/bin/template/lib/saddle-client/stub.rb +1 -1
- data/lib/saddle/requester.rb +2 -2
- data/lib/saddle/version.rb +1 -1
- data/spec/middleware/logging/statsd_spec.rb +2 -4
- data/spec/middleware/request/path_prefix_spec.rb +136 -0
- data/spec/multiple_spec.rb +2 -2
- data/spec/spec_helper.rb +4 -0
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 40349fa3b434064564e6060fafbfede9327e3ad28d28035ecc6ce3eefebc096d
|
4
|
+
data.tar.gz: 68d77c929a14a18571ec4be49fa2daf0e207840add48e3424220643a68c57be5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d84f468133bedaa13ecb030dc2819a0f23b39255b1e500301b5e220d638b2d125106ebea591f2b25628e366fc433e9f440217a94a84f30367a4acb471cbfb0a1
|
7
|
+
data.tar.gz: ab8fccb3facdd3d186627c6c76569e3209b8d7cad3608125a4c24799ba7eaf58c4e2ac04f5793d23c9d989a0a4c6bace879952ffa658bd5a76653aaa9547f85e
|
@@ -9,7 +9,7 @@ module <%= root_module %>
|
|
9
9
|
|
10
10
|
# Setup stubbing for all endpoints
|
11
11
|
def stub!
|
12
|
-
<%= root_module %>::Endpoints::Status.
|
12
|
+
allow_any_instance_of(<%= root_module %>::Endpoints::Status).to receive(:healthy?).and_return(
|
13
13
|
Stub::Data::TEST_STATUS_HEALTHY_RESPONSE
|
14
14
|
)
|
15
15
|
end
|
data/lib/saddle/requester.rb
CHANGED
@@ -47,13 +47,13 @@ module Saddle
|
|
47
47
|
@host = opt[:host] || 'localhost'
|
48
48
|
raise ':host must be a string' unless @host.is_a?(String)
|
49
49
|
@port = opt[:port]
|
50
|
-
raise ':port must be nil or an integer' unless (@port.nil? || @port.is_a?(
|
50
|
+
raise ':port must be nil or an integer' unless (@port.nil? || @port.is_a?(Integer))
|
51
51
|
@use_ssl = opt[:use_ssl] || false
|
52
52
|
raise ':use_ssl must be true or false' unless (@use_ssl.is_a?(TrueClass) || @use_ssl.is_a?(FalseClass))
|
53
53
|
@request_style = opt[:request_style] || :json
|
54
54
|
raise ":request_style must be in: #{VALID_BODY_STYLES.join(',')}" unless VALID_BODY_STYLES.include?(@request_style)
|
55
55
|
@num_retries = opt[:num_retries] || 3
|
56
|
-
raise ':num_retries must be an integer' unless @num_retries.is_a?(
|
56
|
+
raise ':num_retries must be an integer' unless @num_retries.is_a?(Integer)
|
57
57
|
@timeout = opt[:timeout]
|
58
58
|
raise ':timeout must be nil or an integer' unless (@timeout.nil? || @timeout.is_a?(Numeric))
|
59
59
|
@extra_env = opt[:extra_env] || {}
|
data/lib/saddle/version.rb
CHANGED
@@ -15,8 +15,7 @@ describe Saddle::Middleware::Logging::StatsdLogger do
|
|
15
15
|
end
|
16
16
|
|
17
17
|
it "should log a request" do
|
18
|
-
::Statsd.
|
19
|
-
|
18
|
+
allow_any_instance_of(::Statsd).to receive(:time).with("saddle.statsd_client.raw.localhost-test").and_yield
|
20
19
|
client = StatsdClient.create(
|
21
20
|
:stubs => Faraday::Adapter::Test::Stubs.new do |stub|
|
22
21
|
stub.get('/test') {
|
@@ -32,8 +31,7 @@ describe Saddle::Middleware::Logging::StatsdLogger do
|
|
32
31
|
end
|
33
32
|
|
34
33
|
it "should allow overriding the path" do
|
35
|
-
::Statsd.
|
36
|
-
|
34
|
+
allow_any_instance_of(::Statsd).to receive(:time).with("hello").and_yield
|
37
35
|
client = StatsdClient.create(
|
38
36
|
:stubs => Faraday::Adapter::Test::Stubs.new do |stub|
|
39
37
|
stub.get('/test') {
|
@@ -0,0 +1,136 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Saddle::Client do
|
4
|
+
context "when path_prefix is set" do
|
5
|
+
context "using the default client" do
|
6
|
+
before :each do
|
7
|
+
@stubs = Faraday::Adapter::Test::Stubs.new
|
8
|
+
@default_client = Saddle::Client.create(:stubs => @stubs, :path_prefix => 'api/v1')
|
9
|
+
end
|
10
|
+
|
11
|
+
context "with no path" do
|
12
|
+
context "for a GET request" do
|
13
|
+
context "with no params" do
|
14
|
+
it "should properly prefix the path" do
|
15
|
+
url = ''
|
16
|
+
@stubs.get('/api/v1/') {
|
17
|
+
[
|
18
|
+
200,
|
19
|
+
{},
|
20
|
+
'Party!',
|
21
|
+
]
|
22
|
+
}
|
23
|
+
@default_client.requester.get(url).should == 'Party!'
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
context "with params" do
|
28
|
+
it "should properly prefix the path" do
|
29
|
+
url = '?a=1'
|
30
|
+
@stubs.get('/api/v1/?a=1') {
|
31
|
+
[
|
32
|
+
200,
|
33
|
+
{},
|
34
|
+
'Party!',
|
35
|
+
]
|
36
|
+
}
|
37
|
+
@default_client.requester.get(url).should == 'Party!'
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
context "for a POST request" do
|
43
|
+
context "with no params" do
|
44
|
+
it "should properly prefix the path" do
|
45
|
+
url = ''
|
46
|
+
@stubs.post('/api/v1/') {
|
47
|
+
[
|
48
|
+
200,
|
49
|
+
{},
|
50
|
+
'Party!',
|
51
|
+
]
|
52
|
+
}
|
53
|
+
@default_client.requester.post(url).should == 'Party!'
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
context "with params" do
|
58
|
+
it "should properly prefix the path" do
|
59
|
+
url = '?a=1'
|
60
|
+
@stubs.post('/api/v1/?a=1') {
|
61
|
+
[
|
62
|
+
200,
|
63
|
+
{},
|
64
|
+
'Party!',
|
65
|
+
]
|
66
|
+
}
|
67
|
+
@default_client.requester.post(url).should == 'Party!'
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
context "with a path" do
|
74
|
+
context "for a GET request" do
|
75
|
+
context "with no params" do
|
76
|
+
it "should properly prefix the path" do
|
77
|
+
url = '/test'
|
78
|
+
@stubs.get('/api/v1/test') {
|
79
|
+
[
|
80
|
+
200,
|
81
|
+
{},
|
82
|
+
'Party!',
|
83
|
+
]
|
84
|
+
}
|
85
|
+
@default_client.requester.get(url).should == 'Party!'
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
context "with params" do
|
90
|
+
it "should properly prefix the path" do
|
91
|
+
url = '/test?a=1'
|
92
|
+
@stubs.get('/api/v1/test?a=1') {
|
93
|
+
[
|
94
|
+
200,
|
95
|
+
{},
|
96
|
+
'Party!',
|
97
|
+
]
|
98
|
+
}
|
99
|
+
@default_client.requester.get(url).should == 'Party!'
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
context "for a POST request" do
|
105
|
+
context "with no params" do
|
106
|
+
it "should properly prefix the path" do
|
107
|
+
url = '/test'
|
108
|
+
@stubs.post('/api/v1/test') {
|
109
|
+
[
|
110
|
+
200,
|
111
|
+
{},
|
112
|
+
'Party!',
|
113
|
+
]
|
114
|
+
}
|
115
|
+
@default_client.requester.post(url).should == 'Party!'
|
116
|
+
end
|
117
|
+
end
|
118
|
+
|
119
|
+
context "with params" do
|
120
|
+
it "should properly prefix the path" do
|
121
|
+
url = '/test?a=1'
|
122
|
+
@stubs.post('/api/v1/test?a=1') {
|
123
|
+
[
|
124
|
+
200,
|
125
|
+
{},
|
126
|
+
'Party!',
|
127
|
+
]
|
128
|
+
}
|
129
|
+
@default_client.requester.post(url).should == 'Party!'
|
130
|
+
end
|
131
|
+
end
|
132
|
+
end
|
133
|
+
end
|
134
|
+
end
|
135
|
+
end
|
136
|
+
end
|
data/spec/multiple_spec.rb
CHANGED
@@ -61,8 +61,8 @@ describe Saddle::Client do
|
|
61
61
|
client2 = Client2.create(:stubs => stubs)
|
62
62
|
|
63
63
|
# Make sure client2's middleware isn't called
|
64
|
-
Middleware1.
|
65
|
-
Middleware2.
|
64
|
+
allow_any_instance_of(Middleware1).to receive(:subcall)
|
65
|
+
allow_any_instance_of(Middleware2).to receive(:subcall)
|
66
66
|
|
67
67
|
# Make the call
|
68
68
|
client1.requester.get('/')
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: saddle
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mike Lewis
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-
|
11
|
+
date: 2023-06-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -128,6 +128,7 @@ files:
|
|
128
128
|
- spec/middleware/logging/airbrake_spec.rb
|
129
129
|
- spec/middleware/logging/rails_spec.rb
|
130
130
|
- spec/middleware/logging/statsd_spec.rb
|
131
|
+
- spec/middleware/request/path_prefix_spec.rb
|
131
132
|
- spec/middleware/request/retry_spec.rb
|
132
133
|
- spec/middleware/response/default_response_spec.rb
|
133
134
|
- spec/multiple_spec.rb
|
@@ -166,6 +167,7 @@ test_files:
|
|
166
167
|
- spec/middleware/logging/airbrake_spec.rb
|
167
168
|
- spec/middleware/logging/rails_spec.rb
|
168
169
|
- spec/middleware/logging/statsd_spec.rb
|
170
|
+
- spec/middleware/request/path_prefix_spec.rb
|
169
171
|
- spec/middleware/request/retry_spec.rb
|
170
172
|
- spec/middleware/response/default_response_spec.rb
|
171
173
|
- spec/multiple_spec.rb
|