stacker_bee 2.0.0 → 2.1.0.pre180
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +13 -5
- data/.travis.yml +13 -1
- data/README.md +134 -64
- data/bin/stacker_bee +4 -3
- data/config.default.yml +1 -1
- data/lib/stacker_bee/api.rb +2 -3
- data/lib/stacker_bee/client.rb +101 -19
- data/lib/stacker_bee/connection.rb +31 -16
- data/lib/stacker_bee/{middleware → http_middleware}/detokenizer.rb +3 -2
- data/lib/stacker_bee/http_middleware/graylog.rb +14 -0
- data/lib/stacker_bee/{middleware → http_middleware}/signed_query.rb +1 -1
- data/lib/stacker_bee/middleware/adapter.rb +16 -0
- data/lib/stacker_bee/middleware/base.rb +33 -0
- data/lib/stacker_bee/middleware/clean_response.rb +42 -0
- data/lib/stacker_bee/middleware/cloud_stack_api.rb +17 -0
- data/lib/stacker_bee/middleware/console_access.rb +38 -0
- data/lib/stacker_bee/middleware/de_namespace.rb +15 -0
- data/lib/stacker_bee/middleware/dictionary_flattener.rb +44 -0
- data/lib/stacker_bee/middleware/endpoint_normalizer.rb +23 -0
- data/lib/stacker_bee/middleware/environment.rb +23 -0
- data/lib/stacker_bee/middleware/format_keys.rb +13 -0
- data/lib/stacker_bee/middleware/format_values.rb +13 -0
- data/lib/stacker_bee/middleware/http_status.rb +14 -0
- data/lib/stacker_bee/middleware/json_body.rb +14 -0
- data/lib/stacker_bee/middleware/raise_on_http_error.rb +11 -0
- data/lib/stacker_bee/middleware/rashify_response.rb +21 -0
- data/lib/stacker_bee/middleware/remove_empty_strings.rb +11 -0
- data/lib/stacker_bee/middleware/remove_nils.rb +9 -0
- data/lib/stacker_bee/request_error.rb +8 -16
- data/lib/stacker_bee/utilities.rb +30 -0
- data/lib/stacker_bee/version.rb +1 -1
- data/lib/stacker_bee.rb +1 -1
- data/spec/cassettes/A_request_sent_to_CloudStack_for_console_access/returns_html_for_console_access.yml +33 -0
- data/spec/cassettes/A_response_to_a_request_sent_to_the_CloudStack_API/{a_request_parameter_with_a_Map → a_request_parameter_with_a_map}/can_create_an_object.yml +0 -0
- data/spec/cassettes/A_response_to_a_request_sent_to_the_CloudStack_API/a_request_that_triggers_an_error/properly_signs_the_request.yml +35 -0
- data/spec/cassettes/A_response_to_a_request_sent_to_the_CloudStack_API/middleware/a_middleware_that_doesn_t_match_the_content_type/uses_the_middleware.yml +33 -0
- data/spec/cassettes/A_response_to_a_request_sent_to_the_CloudStack_API/middleware/a_middleware_that_matches_the_content_type/uses_the_middleware.yml +33 -0
- data/spec/integration/check_spec.rb +48 -0
- data/spec/integration/configure_middleware_spec.rb +54 -16
- data/spec/integration/console_spec.rb +21 -0
- data/spec/integration/request_spec.rb +57 -2
- data/spec/spec_helper.rb +11 -1
- data/spec/units/faraday_graylog_middleware_spec.rb +1 -1
- data/spec/units/stacker_bee/client_spec.rb +47 -78
- data/spec/units/stacker_bee/connection_spec.rb +34 -11
- data/spec/units/stacker_bee/console_spec.rb +0 -0
- data/spec/units/stacker_bee/{graylog_faraday_middleware_spec.rb → http_middleware/graylog_spec.rb} +18 -2
- data/spec/units/stacker_bee/middleware/adapter_spec.rb +54 -0
- data/spec/units/stacker_bee/middleware/base_spec.rb +128 -0
- data/spec/units/stacker_bee/middleware/cloudstack_api_spec.rb +37 -0
- data/spec/units/stacker_bee/middleware/console_access_spec.rb +59 -0
- data/spec/units/stacker_bee/{dictionary_flattener_spec.rb → middleware/dictionary_flattener_spec.rb} +7 -7
- data/spec/units/stacker_bee/middleware/endpoint_normalizer_spec.rb +36 -0
- data/spec/units/stacker_bee/middleware/format_keys_spec.rb +18 -0
- data/spec/units/stacker_bee/middleware/format_values_spec.rb +15 -0
- data/spec/units/stacker_bee/middleware/http_status_spec.rb +34 -0
- data/spec/units/stacker_bee/middleware/raise_on_http_errors_spec.rb +5 -0
- data/spec/units/stacker_bee/middleware/remove_empty_strings_spec.rb +54 -0
- data/spec/units/stacker_bee/middleware/remove_nils_spec.rb +8 -0
- data/spec/units/stacker_bee/request_error_spec.rb +25 -37
- data/spec/units/stacker_bee/utilities_spec.rb +26 -0
- data/stacker_bee.gemspec +6 -2
- metadata +84 -38
- data/lib/stacker_bee/body_parser.rb +0 -23
- data/lib/stacker_bee/dictionary_flattener.rb +0 -41
- data/lib/stacker_bee/graylog_faraday_middleware.rb +0 -12
- data/lib/stacker_bee/middleware/logger.rb +0 -47
- data/lib/stacker_bee/request.rb +0 -46
- data/lib/stacker_bee/response.rb +0 -29
- data/spec/cassettes/A_response_to_a_request_sent_to_the_CloudStack_API/a_request_parameter_with_a_Map/object.yml +0 -153
- data/spec/units/stacker_bee/middleware/logger_spec.rb +0 -55
- data/spec/units/stacker_bee/request_spec.rb +0 -51
- data/spec/units/stacker_bee/response_spec.rb +0 -79
@@ -1,30 +1,68 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe "
|
3
|
+
describe "Configuring middlewares" do
|
4
|
+
let(:configuration) do
|
5
|
+
{
|
6
|
+
url: "http://garbagestring",
|
7
|
+
api_key: "HI!",
|
8
|
+
secret_key: "SECRET",
|
9
|
+
faraday_middlewares: faraday_middlewares,
|
10
|
+
middlewares: middlewares
|
11
|
+
}
|
12
|
+
end
|
4
13
|
|
5
|
-
|
6
|
-
|
14
|
+
let(:faraday_middlewares) { proc {} }
|
15
|
+
let(:middlewares) { proc {} }
|
7
16
|
|
8
|
-
|
9
|
-
|
10
|
-
url: "http://garbagestring",
|
11
|
-
api_key: "HI!",
|
12
|
-
secret_key: "SECRETT",
|
13
|
-
middlewares: ->(faraday) { faraday.use middleware_class }
|
14
|
-
}
|
15
|
-
end
|
17
|
+
let(:middleware_class) { Class.new(StackerBee::Middleware::Base, &body) }
|
18
|
+
let(:faraday_middleware_class) { Class.new(Faraday::Middleware, &body) }
|
16
19
|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
end
|
20
|
+
let(:body) do
|
21
|
+
proc do
|
22
|
+
def call(env)
|
23
|
+
fail "MiddlewareUsed"
|
22
24
|
end
|
23
25
|
end
|
26
|
+
end
|
24
27
|
|
28
|
+
def self.it_uses_the_middleware
|
25
29
|
it "uses the middle ware" do
|
26
30
|
expect { subject.list_virtual_machines }
|
27
31
|
.to raise_exception "MiddlewareUsed"
|
28
32
|
end
|
29
33
|
end
|
34
|
+
|
35
|
+
def self.it_configures_a_faraday_middleware
|
36
|
+
describe "a Faraday middleware" do
|
37
|
+
let(:faraday_middlewares) do
|
38
|
+
->(faraday) { faraday.use faraday_middleware_class }
|
39
|
+
end
|
40
|
+
|
41
|
+
it_uses_the_middleware
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
def self.it_configures_a_middleware
|
46
|
+
describe "a StackerBee middleware" do
|
47
|
+
let(:middlewares) do
|
48
|
+
->(builder) { builder.use middleware_class }
|
49
|
+
end
|
50
|
+
it_uses_the_middleware
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
describe "via StackerBee::Client.configuration=" do
|
55
|
+
subject { StackerBee::Client.new }
|
56
|
+
before { StackerBee::Client.configuration = configuration }
|
57
|
+
|
58
|
+
it_configures_a_middleware
|
59
|
+
it_configures_a_faraday_middleware
|
60
|
+
end
|
61
|
+
|
62
|
+
describe "via the Client initializer" do
|
63
|
+
subject { StackerBee::Client.new(configuration) }
|
64
|
+
|
65
|
+
it_configures_a_middleware
|
66
|
+
it_configures_a_faraday_middleware
|
67
|
+
end
|
30
68
|
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe "A request sent to CloudStack for console access", :vcr do
|
4
|
+
let(:config_hash) do
|
5
|
+
{
|
6
|
+
url: CONFIG['url'],
|
7
|
+
api_key: CONFIG['api_key'],
|
8
|
+
secret_key: CONFIG['secret_key']
|
9
|
+
}
|
10
|
+
end
|
11
|
+
|
12
|
+
let(:client) { StackerBee::Client.new(config_hash) }
|
13
|
+
|
14
|
+
let(:vm) { "36f9c08b-f17a-4d0e-ac9b-d45ce2d34fcd" }
|
15
|
+
|
16
|
+
subject(:console_access) { client.console_access(vm: vm) }
|
17
|
+
|
18
|
+
it "returns html for console access" do
|
19
|
+
expect(console_access).to match %r{<html>.*<frame src=.*</html>}
|
20
|
+
end
|
21
|
+
end
|
@@ -8,9 +8,11 @@ describe "A response to a request sent to the CloudStack API", :vcr do
|
|
8
8
|
url: url,
|
9
9
|
api_key: CONFIG["api_key"],
|
10
10
|
secret_key: CONFIG["secret_key"],
|
11
|
-
apis_path: File.join(File.dirname(__FILE__), '../fixtures/4.2.json')
|
11
|
+
apis_path: File.join(File.dirname(__FILE__), '../fixtures/4.2.json'),
|
12
|
+
middlewares: middlewares
|
12
13
|
}
|
13
14
|
end
|
15
|
+
let(:middlewares) { proc { } }
|
14
16
|
|
15
17
|
let(:client) do
|
16
18
|
StackerBee::Client.new(config_hash)
|
@@ -55,7 +57,7 @@ describe "A response to a request sent to the CloudStack API", :vcr do
|
|
55
57
|
end
|
56
58
|
end
|
57
59
|
|
58
|
-
context "a nil request parameter"
|
60
|
+
context "a nil request parameter" do
|
59
61
|
let(:params) { { name: nil } }
|
60
62
|
subject do
|
61
63
|
client.list_accounts(params)
|
@@ -77,6 +79,15 @@ describe "A response to a request sent to the CloudStack API", :vcr do
|
|
77
79
|
end
|
78
80
|
end
|
79
81
|
|
82
|
+
context "a request that triggers an error" do
|
83
|
+
subject { client.list_accounts(domain_id: 666) }
|
84
|
+
|
85
|
+
let(:message) { "Domain id=666 doesn't exist" }
|
86
|
+
it "properly signs the request" do
|
87
|
+
expect { subject }.to raise_error StackerBee::ClientError, message
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
80
91
|
context "a request parameter with an Array", :regression do
|
81
92
|
let(:params) { { page: 1, pagesize: 1, details: [:events, :stats] } }
|
82
93
|
subject do
|
@@ -112,4 +123,48 @@ describe "A response to a request sent to the CloudStack API", :vcr do
|
|
112
123
|
tag.should_not be_nil
|
113
124
|
end
|
114
125
|
end
|
126
|
+
|
127
|
+
describe "middleware" do
|
128
|
+
let(:middlewares) do
|
129
|
+
lambda do |builder|
|
130
|
+
builder.use middleware_class
|
131
|
+
end
|
132
|
+
end
|
133
|
+
|
134
|
+
context "a middleware that matches the content type" do
|
135
|
+
let(:middleware_class) do
|
136
|
+
Class.new(StackerBee::Middleware::Base) do
|
137
|
+
def content_types
|
138
|
+
/javascript/
|
139
|
+
end
|
140
|
+
|
141
|
+
def after(env)
|
142
|
+
fail "Middleware Used"
|
143
|
+
end
|
144
|
+
end
|
145
|
+
end
|
146
|
+
|
147
|
+
it "uses the middleware" do
|
148
|
+
expect { client.list_accounts }.to raise_error "Middleware Used"
|
149
|
+
end
|
150
|
+
end
|
151
|
+
|
152
|
+
context "a middleware that doesn't match the content type" do
|
153
|
+
let(:middleware_class) do
|
154
|
+
Class.new(StackerBee::Middleware::Base) do
|
155
|
+
def content_types
|
156
|
+
/html/
|
157
|
+
end
|
158
|
+
|
159
|
+
def after(env)
|
160
|
+
fail "Middleware Used"
|
161
|
+
end
|
162
|
+
end
|
163
|
+
end
|
164
|
+
|
165
|
+
it "uses the middleware" do
|
166
|
+
expect { client.list_accounts }.not_to raise_error
|
167
|
+
end
|
168
|
+
end
|
169
|
+
end
|
115
170
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -37,16 +37,25 @@ require 'vcr'
|
|
37
37
|
|
38
38
|
VCR.configure do |c|
|
39
39
|
c.hook_into :webmock
|
40
|
-
c.cassette_library_dir
|
40
|
+
c.cassette_library_dir = 'spec/cassettes'
|
41
|
+
|
41
42
|
c.filter_sensitive_data('<CLOUD_STACK_URL>') do
|
42
43
|
CONFIG["url"]
|
43
44
|
end
|
45
|
+
|
46
|
+
c.filter_sensitive_data('<CLOUD_STACK_HOST>') do
|
47
|
+
uri = URI.parse(CONFIG["url"])
|
48
|
+
"#{uri.scheme}://#{uri.host}:#{uri.port}"
|
49
|
+
end
|
50
|
+
|
44
51
|
c.filter_sensitive_data('<CLOUD_STACK_API_KEY>') do
|
45
52
|
CONFIG["api_key"]
|
46
53
|
end
|
54
|
+
|
47
55
|
c.filter_sensitive_data('<CLOUD_STACK_SECRET_KEY>') do
|
48
56
|
CONFIG["secret_key"]
|
49
57
|
end
|
58
|
+
|
50
59
|
c.default_cassette_options = {
|
51
60
|
record: :new_episodes,
|
52
61
|
match_requests_on: [
|
@@ -54,5 +63,6 @@ VCR.configure do |c|
|
|
54
63
|
VCR.request_matchers.uri_without_param(:signature)
|
55
64
|
]
|
56
65
|
}
|
66
|
+
|
57
67
|
c.configure_rspec_metadata!
|
58
68
|
end
|
@@ -11,7 +11,7 @@ describe FaradayMiddleware::Graylog do
|
|
11
11
|
let(:log_data) { logger.data }
|
12
12
|
let(:logger) { DummyLogger.new }
|
13
13
|
|
14
|
-
let(:dummy_adapter) { ->(env){ Faraday::Response.new(env) } }
|
14
|
+
let(:dummy_adapter) { ->(env) { Faraday::Response.new(env) } }
|
15
15
|
let(:middleware) do
|
16
16
|
described_class.new(dummy_adapter, logger, facility: facility)
|
17
17
|
end
|
@@ -13,96 +13,65 @@ describe StackerBee::Client, ".api" do
|
|
13
13
|
end
|
14
14
|
|
15
15
|
describe StackerBee::Client, "calling endpoint" do
|
16
|
-
let(:
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
let(:client) { StackerBee::Client.new config_hash }
|
27
|
-
let(:endpoint) { :list_virtual_machines }
|
28
|
-
let(:params) { { list: :all } }
|
29
|
-
let(:connection) { double }
|
30
|
-
let(:request) { double :allow_empty_string_params= => nil }
|
31
|
-
let(:raw_response) { double }
|
32
|
-
let(:response) { double }
|
33
|
-
let(:api_path) do
|
34
|
-
File.join(File.dirname(__FILE__), '../../fixtures/simple.json')
|
16
|
+
let(:client) do
|
17
|
+
StackerBee::Client.new(
|
18
|
+
url: "http://example.com",
|
19
|
+
middlewares: ->(builder) do
|
20
|
+
builder.before middleware_class,
|
21
|
+
expected_endpoint_name: endpoint_name,
|
22
|
+
expected_params: params,
|
23
|
+
response_body: response_body
|
24
|
+
end
|
25
|
+
)
|
35
26
|
end
|
36
27
|
|
37
|
-
|
38
|
-
StackerBee::
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
28
|
+
let(:middleware_class) do
|
29
|
+
Class.new StackerBee::Middleware::Base do
|
30
|
+
def call(env)
|
31
|
+
raise unless env.request.endpoint_name == expected_endpoint_name
|
32
|
+
raise unless env.request.params == expected_params
|
33
|
+
|
34
|
+
env.response.body = response_body
|
35
|
+
end
|
36
|
+
|
37
|
+
def endpoint_name_for(*)
|
38
|
+
true
|
39
|
+
end
|
44
40
|
end
|
45
|
-
connection.stub(:get).with(request) { raw_response }
|
46
|
-
StackerBee::Response.stub(:new).with(raw_response) { response }
|
47
41
|
end
|
48
42
|
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
subject { client.list_virtual_machines(params) }
|
53
|
-
it { should eq response }
|
54
|
-
end
|
55
|
-
end
|
43
|
+
let(:endpoint_name) { :list_virtual_machines }
|
44
|
+
let(:params) { double(:params) }
|
45
|
+
let(:response_body) { double(:response_body) }
|
56
46
|
|
57
|
-
describe
|
58
|
-
|
59
|
-
|
60
|
-
let(:params) { { list: :all } }
|
61
|
-
|
62
|
-
let(:url) { "cloud-stack.com" }
|
63
|
-
let(:api_key) { "cloud-stack-api-key" }
|
64
|
-
let(:secret_key) { "cloud-stack-secret-key" }
|
65
|
-
let(:config_hash) do
|
66
|
-
{
|
67
|
-
url: url,
|
68
|
-
api_key: api_key,
|
69
|
-
secret_key: secret_key
|
70
|
-
}
|
47
|
+
describe "responding to methods" do
|
48
|
+
subject { client }
|
49
|
+
it { should respond_to endpoint_name }
|
71
50
|
end
|
72
|
-
let(:client) { StackerBee::Client.new config_hash }
|
73
|
-
let(:connection) { double }
|
74
|
-
let(:request) { double :allow_empty_string_params= => nil }
|
75
|
-
let(:raw_response) { double }
|
76
|
-
let(:response) { double }
|
77
51
|
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
request
|
82
|
-
end
|
83
|
-
connection.should_receive(:get).with(request) { raw_response }
|
84
|
-
StackerBee::Response.should_receive(:new).with(raw_response) { response }
|
52
|
+
describe "via a method call" do
|
53
|
+
subject { client.list_virtual_machines(params) }
|
54
|
+
it { should eq response_body }
|
85
55
|
end
|
86
56
|
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
subject { client.request("list_Virtual_mACHINES", params) }
|
91
|
-
it { should eq response }
|
57
|
+
describe "via #request" do
|
58
|
+
subject { client.request(endpoint_name, params) }
|
59
|
+
it { should eq response_body }
|
92
60
|
end
|
93
61
|
end
|
94
62
|
|
63
|
+
|
95
64
|
describe StackerBee::Client, "configuration" do
|
96
65
|
let(:default_url) { "default_cloud-stack.com" }
|
97
66
|
let(:default_api_key) { "default-cloud-stack-api-key" }
|
98
67
|
let(:default_secret_key) { "default-cloud-stack-secret-key" }
|
99
68
|
let(:default_config_hash) do
|
100
69
|
{
|
101
|
-
url:
|
102
|
-
api_key:
|
103
|
-
secret_key:
|
104
|
-
|
105
|
-
middlewares:
|
70
|
+
url: default_url,
|
71
|
+
api_key: default_api_key,
|
72
|
+
secret_key: default_secret_key,
|
73
|
+
faraday_middlewares: proc {},
|
74
|
+
middlewares: proc {}
|
106
75
|
}
|
107
76
|
end
|
108
77
|
let!(:default_configuration) do
|
@@ -113,19 +82,19 @@ describe StackerBee::Client, "configuration" do
|
|
113
82
|
let(:instance_secret_key) { "instance-cloud-stack-secret-key" }
|
114
83
|
let(:instance_config_hash) do
|
115
84
|
{
|
116
|
-
url:
|
117
|
-
api_key:
|
118
|
-
secret_key:
|
119
|
-
|
120
|
-
middlewares:
|
85
|
+
url: instance_url,
|
86
|
+
api_key: instance_api_key,
|
87
|
+
secret_key: instance_secret_key,
|
88
|
+
faraday_middlewares: proc {},
|
89
|
+
middlewares: proc {}
|
121
90
|
}
|
122
91
|
end
|
123
92
|
let!(:instance_configuration) do
|
124
93
|
StackerBee::Configuration.new(instance_config_hash)
|
125
94
|
end
|
126
95
|
before do
|
127
|
-
StackerBee::Configuration.stub(:new) do
|
128
|
-
fail "Unexpected Configuration instantiation"
|
96
|
+
StackerBee::Configuration.stub(:new) do |options|
|
97
|
+
fail "Unexpected Configuration instantiation: \n#{args.inspect}"
|
129
98
|
end
|
130
99
|
StackerBee::Configuration.stub(:new).with(default_config_hash) do
|
131
100
|
default_configuration
|
@@ -2,26 +2,30 @@ require "spec_helper"
|
|
2
2
|
|
3
3
|
describe StackerBee::Connection do
|
4
4
|
let(:url) { "http://test.com:1234/foo/bar/" }
|
5
|
+
let(:path) { "/foo/bar" }
|
5
6
|
let(:secret_key) { "shhh" }
|
6
|
-
let(:configuration) { double url: url, secret_key: secret_key }
|
7
7
|
let(:query_params) { [[:foo, :bar]] }
|
8
|
-
let(:
|
9
|
-
let(:
|
10
|
-
let(:
|
11
|
-
let(:
|
12
|
-
|
8
|
+
let(:response) { double(:response) }
|
9
|
+
let(:faraday) { double(:faraday, get: response) }
|
10
|
+
let(:connection) { StackerBee::Connection.new(configuration) }
|
11
|
+
let(:configuration) do
|
12
|
+
double(url: url, secret_key: secret_key, ssl_verify: nil)
|
13
|
+
end
|
14
|
+
subject(:get) { connection.get query_params, path }
|
15
|
+
|
13
16
|
before do
|
14
17
|
Faraday.stub(:new) { faraday }
|
15
18
|
end
|
16
19
|
|
17
20
|
context "successfully connecting" do
|
18
21
|
before do
|
19
|
-
faraday.should_receive(:get).with('/foo/bar
|
22
|
+
faraday.should_receive(:get).with('/foo/bar', query_params) { response }
|
20
23
|
end
|
21
24
|
it { should be response }
|
22
25
|
it "specifies url without path when creating connection" do
|
23
|
-
|
24
|
-
Faraday.should have_received(:new).with(url: "http://test.com:1234"
|
26
|
+
get
|
27
|
+
Faraday.should have_received(:new).with(url: "http://test.com:1234",
|
28
|
+
ssl: { verify: true })
|
25
29
|
end
|
26
30
|
end
|
27
31
|
|
@@ -31,7 +35,7 @@ describe StackerBee::Connection do
|
|
31
35
|
end
|
32
36
|
it "should raise helpful exception" do
|
33
37
|
klass = StackerBee::ConnectionError
|
34
|
-
expect
|
38
|
+
expect { get }.to raise_error klass, /#{url}/
|
35
39
|
end
|
36
40
|
end
|
37
41
|
|
@@ -39,7 +43,26 @@ describe StackerBee::Connection do
|
|
39
43
|
let(:url) { "wrong.com" }
|
40
44
|
it "should raise helpful exception" do
|
41
45
|
klass = StackerBee::ConnectionError
|
42
|
-
expect
|
46
|
+
expect { get }.to raise_error klass, /no protocol/
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
context "when given a path" do
|
51
|
+
let(:path) { '/baz' }
|
52
|
+
it "makes a request to the correct path" do
|
53
|
+
expect(faraday).to receive(:get).with(path, query_params)
|
54
|
+
connection.get query_params, path
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
context "when verifying an ssl connection" do
|
59
|
+
let(:configuration) do
|
60
|
+
double url: url, secret_key: secret_key, ssl_verify: false
|
61
|
+
end
|
62
|
+
it "specifies the ssl verify option when creating a connection" do
|
63
|
+
get
|
64
|
+
Faraday.should have_received(:new).with(url: "http://test.com:1234",
|
65
|
+
ssl: { verify: false })
|
43
66
|
end
|
44
67
|
end
|
45
68
|
end
|
File without changes
|
data/spec/units/stacker_bee/{graylog_faraday_middleware_spec.rb → http_middleware/graylog_spec.rb}
RENAMED
@@ -1,6 +1,6 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe StackerBee::
|
3
|
+
describe StackerBee::HTTPMiddleware::Graylog do
|
4
4
|
subject { log_data }
|
5
5
|
|
6
6
|
class DummyLogger
|
@@ -11,7 +11,7 @@ describe StackerBee::GraylogFaradayMiddleware do
|
|
11
11
|
let(:log_data) { logger.data }
|
12
12
|
let(:logger) { DummyLogger.new }
|
13
13
|
|
14
|
-
let(:dummy_adapter) { ->(env){ Faraday::Response.new(env) } }
|
14
|
+
let(:dummy_adapter) { ->(env) { Faraday::Response.new(env) } }
|
15
15
|
let(:middleware) { described_class.new(dummy_adapter, logger) }
|
16
16
|
let(:status) { 200 }
|
17
17
|
|
@@ -32,4 +32,20 @@ describe StackerBee::GraylogFaradayMiddleware do
|
|
32
32
|
end
|
33
33
|
|
34
34
|
its([:facility]) { should == "stacker-bee" }
|
35
|
+
|
36
|
+
context "without a command in the url" do
|
37
|
+
let(:env) do
|
38
|
+
{
|
39
|
+
body: "DATA",
|
40
|
+
response_headers: {},
|
41
|
+
response: {},
|
42
|
+
status: status,
|
43
|
+
url: URI.parse("http://a.b/?key=KEY&&val=val")
|
44
|
+
}
|
45
|
+
end
|
46
|
+
|
47
|
+
it "sets a custom short message" do
|
48
|
+
log_data[:short_message].should eq "StackerBee"
|
49
|
+
end
|
50
|
+
end
|
35
51
|
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe StackerBee::Middleware::Adapter do
|
4
|
+
let(:env) do
|
5
|
+
StackerBee::Middleware::Environment.new(
|
6
|
+
endpoint_name: 'listVirtualMachines',
|
7
|
+
params: params,
|
8
|
+
path: path
|
9
|
+
)
|
10
|
+
end
|
11
|
+
let(:app) { double(:app, call: response) }
|
12
|
+
let(:response) { double(:response) }
|
13
|
+
let(:path) { double(:path) }
|
14
|
+
|
15
|
+
let(:params) { { 'z' => 'z', 'a' => 'a' } }
|
16
|
+
let(:connection) { double(:connection, get: raw_response) }
|
17
|
+
let(:middleware) { described_class.new(app: app, connection: connection) }
|
18
|
+
|
19
|
+
let(:raw_response) do
|
20
|
+
double(env: { response_headers: response_headers}, body: response_body)
|
21
|
+
end
|
22
|
+
let(:response_headers) { { "content-type" => content_type } }
|
23
|
+
let(:content_type) { "text/javascript; charset=UTF-8" }
|
24
|
+
let(:response_body) { double }
|
25
|
+
|
26
|
+
describe "#call" do
|
27
|
+
before { middleware.call(env) }
|
28
|
+
|
29
|
+
it "makes a call via the connection" do
|
30
|
+
connection.should have_received(:get)
|
31
|
+
end
|
32
|
+
|
33
|
+
it "sets the environment's raw_response" do
|
34
|
+
env.raw_response.should == raw_response
|
35
|
+
end
|
36
|
+
|
37
|
+
it "sets the response's mime type" do
|
38
|
+
env.response.content_type.should == content_type
|
39
|
+
end
|
40
|
+
|
41
|
+
it "sets the response's body to the raw response's body" do
|
42
|
+
env.response.body.should == response_body
|
43
|
+
end
|
44
|
+
|
45
|
+
it "sorts the paramers" do
|
46
|
+
connection.should have_received(:get).with([["a", "a"], ["z", "z"]], path)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
describe "#endpoint_name_for" do
|
51
|
+
subject { middleware.endpoint_name_for('listVirtualMachines') }
|
52
|
+
it { should be_nil }
|
53
|
+
end
|
54
|
+
end
|