stacker_bee 2.1.1.pre252 → 2.1.1.pre263
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/.rubocop.yml +0 -3
- data/Rakefile +1 -1
- data/bin/stacker_bee +10 -10
- data/lib/stacker_bee/api.rb +4 -4
- data/lib/stacker_bee/client.rb +24 -24
- data/lib/stacker_bee/configuration.rb +13 -7
- data/lib/stacker_bee/connection.rb +5 -5
- data/lib/stacker_bee/http_middleware/detokenizer.rb +2 -2
- data/lib/stacker_bee/http_middleware/signed_query.rb +3 -3
- data/lib/stacker_bee/middleware/adapter.rb +1 -1
- data/lib/stacker_bee/middleware/base.rb +1 -1
- data/lib/stacker_bee/middleware/clean_response.rb +2 -2
- data/lib/stacker_bee/middleware/cloud_stack_api.rb +2 -2
- data/lib/stacker_bee/middleware/dictionary_flattener.rb +3 -3
- data/lib/stacker_bee/middleware/endpoint_normalizer.rb +2 -2
- data/lib/stacker_bee/middleware/error_message.rb +3 -3
- data/lib/stacker_bee/middleware/log_response.rb +1 -1
- data/lib/stacker_bee/middleware/raise_on_http_error.rb +1 -1
- data/lib/stacker_bee/middleware/remove_nils.rb +1 -1
- data/lib/stacker_bee/rash.rb +3 -3
- data/lib/stacker_bee/version.rb +1 -1
- data/lib/stacker_bee.rb +2 -2
- data/spec/integration/configure_middleware_spec.rb +12 -12
- data/spec/integration/console_spec.rb +4 -4
- data/spec/integration/request_spec.rb +46 -46
- data/spec/spec_helper.rb +4 -4
- data/spec/support/vcr.rb +4 -4
- data/spec/units/stacker_bee/api_spec.rb +11 -11
- data/spec/units/stacker_bee/client_spec.rb +19 -19
- data/spec/units/stacker_bee/configuration_spec.rb +28 -28
- data/spec/units/stacker_bee/connection_spec.rb +18 -18
- data/spec/units/stacker_bee/middleware/adapter_spec.rb +7 -7
- data/spec/units/stacker_bee/middleware/base_spec.rb +17 -17
- data/spec/units/stacker_bee/middleware/cloudstack_api_spec.rb +9 -9
- data/spec/units/stacker_bee/middleware/console_access_spec.rb +10 -10
- data/spec/units/stacker_bee/middleware/dictionary_flattener_spec.rb +22 -22
- data/spec/units/stacker_bee/middleware/endpoint_normalizer_spec.rb +4 -4
- data/spec/units/stacker_bee/middleware/error_message_spec.rb +6 -6
- data/spec/units/stacker_bee/middleware/format_keys_spec.rb +2 -2
- data/spec/units/stacker_bee/middleware/format_values_spec.rb +2 -2
- data/spec/units/stacker_bee/middleware/http_status_spec.rb +2 -2
- data/spec/units/stacker_bee/middleware/log_response_spec.rb +15 -15
- data/spec/units/stacker_bee/middleware/remove_empty_strings_spec.rb +4 -4
- data/spec/units/stacker_bee/middleware/remove_nils_spec.rb +1 -1
- data/spec/units/stacker_bee/rash_spec.rb +41 -41
- data/spec/units/stacker_bee/request_error_spec.rb +7 -7
- data/spec/units/stacker_bee/utilities_spec.rb +30 -30
- data/spec/units/stacker_bee_spec.rb +2 -2
- data/stacker_bee.gemspec +24 -22
- metadata +4 -4
@@ -1,15 +1,15 @@
|
|
1
|
-
require
|
2
|
-
require
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'logger'
|
3
3
|
|
4
|
-
describe
|
4
|
+
describe 'A response to a request sent to the CloudStack API', :vcr do
|
5
5
|
subject { client.list_accounts }
|
6
6
|
|
7
|
-
let(:url) { CONFIG[
|
7
|
+
let(:url) { CONFIG['url'] }
|
8
8
|
let(:config_hash) do
|
9
9
|
{
|
10
10
|
url: url,
|
11
|
-
api_key: CONFIG[
|
12
|
-
secret_key: CONFIG[
|
11
|
+
api_key: CONFIG['api_key'],
|
12
|
+
secret_key: CONFIG['secret_key'],
|
13
13
|
middlewares: middlewares
|
14
14
|
}
|
15
15
|
end
|
@@ -21,77 +21,77 @@ describe "A response to a request sent to the CloudStack API", :vcr do
|
|
21
21
|
|
22
22
|
it { should_not be_empty }
|
23
23
|
|
24
|
-
context
|
24
|
+
context 'first item' do
|
25
25
|
subject { client.list_accounts.first }
|
26
|
-
it { should include
|
27
|
-
its([
|
28
|
-
its([
|
26
|
+
it { should include 'id' }
|
27
|
+
its(['accounttype']) { should be_a Numeric }
|
28
|
+
its(['account_type']) { should be_a Numeric }
|
29
29
|
end
|
30
30
|
|
31
|
-
context
|
32
|
-
let(:url) {
|
33
|
-
it
|
31
|
+
context 'failing to connect' do
|
32
|
+
let(:url) { 'http://127.0.0.1:666/client/api' }
|
33
|
+
it 'raises a helpful exception' do
|
34
34
|
klass = StackerBee::ConnectionError
|
35
35
|
expect { subject }.to raise_error klass, /#{url}/
|
36
36
|
end
|
37
37
|
end
|
38
38
|
|
39
|
-
context
|
40
|
-
let(:url) { CONFIG[
|
41
|
-
it
|
39
|
+
context 'trailing slash in URL', :regression do
|
40
|
+
let(:url) { CONFIG['url'].gsub(/\/$/, '') + '/' }
|
41
|
+
it 'makes request with trailing slash' do
|
42
42
|
stub = stub_request(:get, /#{url}/).to_return(body: '{"foo": {}}')
|
43
43
|
subject
|
44
44
|
stub.should have_been_requested
|
45
45
|
end
|
46
46
|
end
|
47
47
|
|
48
|
-
context
|
48
|
+
context 'space character in a request parameter', :regression do
|
49
49
|
subject { client.list_accounts(params) }
|
50
|
-
let(:params) { { name:
|
50
|
+
let(:params) { { name: 'stacker bee' } }
|
51
51
|
|
52
|
-
it
|
52
|
+
it 'properly signs the request' do
|
53
53
|
expect { subject }.not_to raise_error
|
54
54
|
end
|
55
55
|
end
|
56
56
|
|
57
|
-
context
|
57
|
+
context 'a nil request parameter' do
|
58
58
|
subject { client.list_accounts(params) }
|
59
59
|
let(:params) { { name: nil } }
|
60
60
|
|
61
|
-
it
|
61
|
+
it 'properly executes the request' do
|
62
62
|
expect { subject }.not_to raise_error
|
63
63
|
end
|
64
64
|
end
|
65
65
|
|
66
|
-
context
|
66
|
+
context 'a request parameter with and empty string', :regression do
|
67
67
|
subject { client.list_accounts(params) }
|
68
68
|
let(:params) { { name: '' } }
|
69
69
|
|
70
|
-
it
|
70
|
+
it 'properly executes the request' do
|
71
71
|
expect { subject }.not_to raise_error
|
72
72
|
end
|
73
73
|
end
|
74
74
|
|
75
|
-
context
|
75
|
+
context 'a request that triggers an error' do
|
76
76
|
subject { client.list_accounts(domain_id: 666) }
|
77
77
|
|
78
78
|
let(:message) { "Domain id=666 doesn't exist" }
|
79
|
-
it
|
79
|
+
it 'properly signs the request' do
|
80
80
|
expect { subject }.to raise_error StackerBee::ClientError, message
|
81
81
|
end
|
82
82
|
end
|
83
83
|
|
84
|
-
context
|
84
|
+
context 'a request parameter with an Array', :regression do
|
85
85
|
subject { client.list_hosts(params).first.keys }
|
86
86
|
let(:params) { { page: 1, pagesize: 1, details: [:events, :stats] } }
|
87
|
-
it { should include
|
88
|
-
it { should include
|
89
|
-
it { should_not include
|
87
|
+
it { should include 'cpuused' }
|
88
|
+
it { should include 'events' }
|
89
|
+
it { should_not include 'cpuallocated' }
|
90
90
|
end
|
91
91
|
|
92
|
-
context
|
93
|
-
let(:zone_id) { client.list_zones.first[
|
94
|
-
let(:service_offering_id) { service_offerings.first[
|
92
|
+
context 'a request parameter with a map' do
|
93
|
+
let(:zone_id) { client.list_zones.first['id'] }
|
94
|
+
let(:service_offering_id) { service_offerings.first['id'] }
|
95
95
|
|
96
96
|
let(:service_offerings) do
|
97
97
|
client.list_network_offerings(
|
@@ -103,42 +103,42 @@ describe "A response to a request sent to the CloudStack API", :vcr do
|
|
103
103
|
let(:network) do
|
104
104
|
client.create_network(zone_id: zone_id,
|
105
105
|
network_offering_id: service_offering_id,
|
106
|
-
name:
|
106
|
+
name: 'John', displaytext: 'John')
|
107
107
|
end
|
108
108
|
|
109
109
|
let(:tag) do
|
110
|
-
client.create_tags(resource_type:
|
111
|
-
resource_ids: network[
|
112
|
-
tags: {
|
110
|
+
client.create_tags(resource_type: 'Network',
|
111
|
+
resource_ids: network['id'],
|
112
|
+
tags: { 'speed [lab]' => 'real fast!' })
|
113
113
|
end
|
114
114
|
|
115
|
-
it
|
115
|
+
it 'can create an object' do
|
116
116
|
tag.should_not be_nil
|
117
117
|
end
|
118
118
|
end
|
119
119
|
|
120
|
-
describe
|
120
|
+
describe 'middleware' do
|
121
121
|
let(:middlewares) do
|
122
122
|
lambda do |builder|
|
123
123
|
builder.use middleware_class
|
124
124
|
end
|
125
125
|
end
|
126
126
|
|
127
|
-
context
|
127
|
+
context 'a middleware that matches the content type' do
|
128
128
|
let(:middleware_class) do
|
129
129
|
Class.new(StackerBee::Middleware::Base) do
|
130
130
|
def content_types
|
131
131
|
/javascript/
|
132
132
|
end
|
133
133
|
|
134
|
-
def after(
|
135
|
-
fail
|
134
|
+
def after(_env)
|
135
|
+
fail 'Middleware Used'
|
136
136
|
end
|
137
137
|
end
|
138
138
|
end
|
139
139
|
|
140
|
-
it
|
141
|
-
expect { client.list_accounts }.to raise_error
|
140
|
+
it 'uses the middleware' do
|
141
|
+
expect { client.list_accounts }.to raise_error 'Middleware Used'
|
142
142
|
end
|
143
143
|
end
|
144
144
|
|
@@ -149,13 +149,13 @@ describe "A response to a request sent to the CloudStack API", :vcr do
|
|
149
149
|
/html/
|
150
150
|
end
|
151
151
|
|
152
|
-
def after(
|
153
|
-
fail
|
152
|
+
def after(_env)
|
153
|
+
fail 'Middleware Used'
|
154
154
|
end
|
155
155
|
end
|
156
156
|
end
|
157
157
|
|
158
|
-
it
|
158
|
+
it 'uses the middleware' do
|
159
159
|
expect { client.list_accounts }.not_to raise_error
|
160
160
|
end
|
161
161
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -5,12 +5,12 @@
|
|
5
5
|
#
|
6
6
|
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
|
7
7
|
|
8
|
-
require File.expand_path(
|
8
|
+
require File.expand_path('../../lib/stacker_bee', __FILE__)
|
9
9
|
|
10
10
|
require 'yaml'
|
11
11
|
|
12
|
-
default_config_file = File.expand_path(
|
13
|
-
config_file = File.expand_path(
|
12
|
+
default_config_file = File.expand_path('../../config.default.yml', __FILE__)
|
13
|
+
config_file = File.expand_path('../../config.yml', __FILE__)
|
14
14
|
|
15
15
|
CONFIG = YAML.load(File.read(default_config_file))
|
16
16
|
CONFIG.merge!(YAML.load(File.read(config_file))) if File.exist?(config_file)
|
@@ -18,7 +18,7 @@ CONFIG.merge!(YAML.load(File.read(config_file))) if File.exist?(config_file)
|
|
18
18
|
require 'webmock/rspec'
|
19
19
|
|
20
20
|
support_files = Dir[File.join(
|
21
|
-
File.expand_path(
|
21
|
+
File.expand_path('../../spec/support/**/*.rb', __FILE__)
|
22
22
|
)]
|
23
23
|
support_files.each { |f| require f }
|
24
24
|
|
data/spec/support/vcr.rb
CHANGED
@@ -5,20 +5,20 @@ VCR.configure do |c|
|
|
5
5
|
c.cassette_library_dir = 'spec/cassettes'
|
6
6
|
|
7
7
|
c.filter_sensitive_data('<CLOUD_STACK_URL>') do
|
8
|
-
CONFIG[
|
8
|
+
CONFIG['url']
|
9
9
|
end
|
10
10
|
|
11
11
|
c.filter_sensitive_data('<CLOUD_STACK_HOST>') do
|
12
|
-
uri = URI.parse(CONFIG[
|
12
|
+
uri = URI.parse(CONFIG['url'])
|
13
13
|
"#{uri.scheme}://#{uri.host}:#{uri.port}"
|
14
14
|
end
|
15
15
|
|
16
16
|
c.filter_sensitive_data('<CLOUD_STACK_API_KEY>') do
|
17
|
-
CONFIG[
|
17
|
+
CONFIG['api_key']
|
18
18
|
end
|
19
19
|
|
20
20
|
c.filter_sensitive_data('<CLOUD_STACK_SECRET_KEY>') do
|
21
|
-
CONFIG[
|
21
|
+
CONFIG['secret_key']
|
22
22
|
end
|
23
23
|
|
24
24
|
c.default_cassette_options = {
|
@@ -1,4 +1,4 @@
|
|
1
|
-
require
|
1
|
+
require 'spec_helper'
|
2
2
|
|
3
3
|
describe StackerBee::API do
|
4
4
|
subject { api }
|
@@ -10,15 +10,15 @@ describe StackerBee::API do
|
|
10
10
|
|
11
11
|
its(:api_path) { should eq api_path }
|
12
12
|
|
13
|
-
its([
|
14
|
-
its([
|
15
|
-
its([
|
16
|
-
its([
|
17
|
-
its([
|
18
|
-
its([
|
13
|
+
its(['list_virtual_machines']) { should be_a Hash }
|
14
|
+
its(['get_vm_password']) { should be_a Hash }
|
15
|
+
its(['getvmpassword']) { should be_a Hash }
|
16
|
+
its(['getVMPassword']) { should be_a Hash }
|
17
|
+
its(['getVmPassword']) { should be_a Hash }
|
18
|
+
its(['getWRONG']) { should be_nil }
|
19
19
|
|
20
|
-
it { should be_key
|
21
|
-
it { should be_key
|
22
|
-
it { should be_key
|
23
|
-
it { should be_key
|
20
|
+
it { should be_key 'get_vm_password' }
|
21
|
+
it { should be_key 'getvmpassword' }
|
22
|
+
it { should be_key 'getVMPassword' }
|
23
|
+
it { should be_key 'getVmPassword' }
|
24
24
|
end
|
@@ -1,7 +1,7 @@
|
|
1
|
-
require
|
2
|
-
require
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'ostruct'
|
3
3
|
|
4
|
-
describe StackerBee::Client,
|
4
|
+
describe StackerBee::Client, '.api' do
|
5
5
|
subject { described_class }
|
6
6
|
let(:api) { double }
|
7
7
|
before do
|
@@ -12,10 +12,10 @@ describe StackerBee::Client, ".api" do
|
|
12
12
|
its(:api) { should eq api }
|
13
13
|
end
|
14
14
|
|
15
|
-
describe StackerBee::Client,
|
15
|
+
describe StackerBee::Client, 'calling endpoint' do
|
16
16
|
let(:client) do
|
17
17
|
described_class.new(
|
18
|
-
url:
|
18
|
+
url: 'http://example.com',
|
19
19
|
middlewares: lambda do |builder|
|
20
20
|
builder.before middleware_class,
|
21
21
|
expected_endpoint_name: endpoint_name,
|
@@ -44,28 +44,28 @@ describe StackerBee::Client, "calling endpoint" do
|
|
44
44
|
let(:params) { double(:params) }
|
45
45
|
let(:response_body) { double(:response_body) }
|
46
46
|
|
47
|
-
describe
|
47
|
+
describe 'responding to methods' do
|
48
48
|
subject { client }
|
49
49
|
it { should respond_to endpoint_name }
|
50
50
|
end
|
51
51
|
|
52
|
-
describe
|
52
|
+
describe 'via a method call' do
|
53
53
|
subject { client.list_virtual_machines(params) }
|
54
54
|
it { should eq response_body }
|
55
55
|
end
|
56
56
|
|
57
|
-
describe
|
57
|
+
describe 'via #request' do
|
58
58
|
subject { client.request(endpoint_name, params) }
|
59
59
|
it { should eq response_body }
|
60
60
|
end
|
61
61
|
end
|
62
62
|
|
63
|
-
describe StackerBee::Client,
|
63
|
+
describe StackerBee::Client, 'configuration' do
|
64
64
|
before { described_class.configuration = default_config_hash }
|
65
65
|
|
66
|
-
let(:default_url) {
|
67
|
-
let(:default_api_key) {
|
68
|
-
let(:default_secret_key) {
|
66
|
+
let(:default_url) { 'default_cloud-stack.com' }
|
67
|
+
let(:default_api_key) { 'default-cloud-stack-api-key' }
|
68
|
+
let(:default_secret_key) { 'default-cloud-stack-secret-key' }
|
69
69
|
let(:default_config_hash) do
|
70
70
|
{
|
71
71
|
url: default_url,
|
@@ -76,9 +76,9 @@ describe StackerBee::Client, "configuration" do
|
|
76
76
|
}
|
77
77
|
end
|
78
78
|
|
79
|
-
let(:instance_url) {
|
80
|
-
let(:instance_api_key) {
|
81
|
-
let(:instance_secret_key) {
|
79
|
+
let(:instance_url) { 'instance-cloud-stack.com' }
|
80
|
+
let(:instance_api_key) { 'instance-cloud-stack-api-key' }
|
81
|
+
let(:instance_secret_key) { 'instance-cloud-stack-secret-key' }
|
82
82
|
let(:instance_config_hash) do
|
83
83
|
{
|
84
84
|
url: instance_url,
|
@@ -89,10 +89,10 @@ describe StackerBee::Client, "configuration" do
|
|
89
89
|
}
|
90
90
|
end
|
91
91
|
|
92
|
-
describe
|
92
|
+
describe '.new' do
|
93
93
|
subject { client.configuration }
|
94
94
|
|
95
|
-
context
|
95
|
+
context 'with default, class configuration' do
|
96
96
|
let(:client) { described_class.new }
|
97
97
|
|
98
98
|
its(:url) { should eq default_url }
|
@@ -100,7 +100,7 @@ describe StackerBee::Client, "configuration" do
|
|
100
100
|
its(:secret_key) { should eq default_secret_key }
|
101
101
|
end
|
102
102
|
|
103
|
-
context
|
103
|
+
context 'with instance-specific configuration' do
|
104
104
|
let(:client) { described_class.new(instance_config_hash) }
|
105
105
|
|
106
106
|
its(:url) { should eq instance_url }
|
@@ -117,7 +117,7 @@ describe StackerBee::Client, "configuration" do
|
|
117
117
|
its(:secret_key) { should eq instance_secret_key }
|
118
118
|
end
|
119
119
|
|
120
|
-
context
|
120
|
+
context 'with partial instance-specific configuration' do
|
121
121
|
let(:client) { described_class.new(partial_config_hash) }
|
122
122
|
let(:partial_config_hash) do
|
123
123
|
{ url: instance_config_hash[:url] }
|
@@ -1,110 +1,110 @@
|
|
1
|
-
require
|
1
|
+
require 'spec_helper'
|
2
2
|
|
3
3
|
describe StackerBee::Configuration do
|
4
4
|
describe "setting an attribute that doesn't exist" do
|
5
5
|
[:ssl_verify?, :url?, :other_attr].each do |attr|
|
6
|
-
it
|
6
|
+
it 'raises an error' do
|
7
7
|
expect { described_class.new(attr => true) }
|
8
8
|
.to raise_error described_class::NoAttributeError, /#{attr}/
|
9
9
|
end
|
10
10
|
end
|
11
11
|
end
|
12
12
|
|
13
|
-
describe
|
13
|
+
describe '#ssl_verify?' do
|
14
14
|
subject { configuration.ssl_verify? }
|
15
15
|
|
16
|
-
context
|
16
|
+
context 'when not set' do
|
17
17
|
let(:configuration) { described_class.new }
|
18
18
|
it { should eq true }
|
19
19
|
end
|
20
20
|
|
21
|
-
context
|
21
|
+
context 'when set to false' do
|
22
22
|
let(:configuration) { described_class.new(ssl_verify: false) }
|
23
23
|
it { should eq false }
|
24
24
|
end
|
25
25
|
|
26
|
-
context
|
26
|
+
context 'when set to true' do
|
27
27
|
let(:configuration) { described_class.new(ssl_verify: true) }
|
28
28
|
it { should eq true }
|
29
29
|
end
|
30
30
|
end
|
31
31
|
|
32
|
-
describe
|
32
|
+
describe '#url' do
|
33
33
|
subject { configuration.url }
|
34
34
|
|
35
|
-
context
|
35
|
+
context 'when not set' do
|
36
36
|
let(:configuration) { described_class.new }
|
37
37
|
it { should eq nil }
|
38
38
|
end
|
39
39
|
|
40
|
-
context
|
40
|
+
context 'when set' do
|
41
41
|
let(:configuration) { described_class.new(url: setting) }
|
42
|
-
let(:setting) {
|
42
|
+
let(:setting) { 'http://example.com' }
|
43
43
|
it { should eq setting }
|
44
44
|
end
|
45
45
|
end
|
46
46
|
|
47
|
-
describe
|
47
|
+
describe '#secret_key' do
|
48
48
|
subject { configuration.secret_key }
|
49
49
|
|
50
|
-
context
|
50
|
+
context 'when not set' do
|
51
51
|
let(:configuration) { described_class.new }
|
52
52
|
it { should eq nil }
|
53
53
|
end
|
54
54
|
|
55
|
-
context
|
55
|
+
context 'when set' do
|
56
56
|
let(:configuration) { described_class.new(secret_key: setting) }
|
57
|
-
let(:setting) {
|
57
|
+
let(:setting) { 'qwertyuiop' }
|
58
58
|
it { should eq setting }
|
59
59
|
end
|
60
60
|
end
|
61
61
|
|
62
|
-
describe
|
62
|
+
describe '#api_key' do
|
63
63
|
subject { configuration.api_key }
|
64
64
|
|
65
|
-
context
|
65
|
+
context 'when not set' do
|
66
66
|
let(:configuration) { described_class.new }
|
67
67
|
it { should eq nil }
|
68
68
|
end
|
69
69
|
|
70
|
-
context
|
70
|
+
context 'when set' do
|
71
71
|
let(:configuration) { described_class.new(api_key: setting) }
|
72
|
-
let(:setting) {
|
72
|
+
let(:setting) { 'qwertyuiop' }
|
73
73
|
it { should eq setting }
|
74
74
|
end
|
75
75
|
end
|
76
76
|
|
77
|
-
describe
|
77
|
+
describe '#middlewares' do
|
78
78
|
subject { configuration.middlewares }
|
79
79
|
|
80
|
-
context
|
80
|
+
context 'when not set' do
|
81
81
|
let(:configuration) { described_class.new }
|
82
82
|
it { should be_a Proc }
|
83
83
|
end
|
84
84
|
|
85
|
-
context
|
85
|
+
context 'when set' do
|
86
86
|
let(:configuration) { described_class.new(middlewares: setting) }
|
87
87
|
let(:setting) { proc { something } }
|
88
88
|
it { should eq setting }
|
89
89
|
end
|
90
90
|
end
|
91
91
|
|
92
|
-
describe
|
92
|
+
describe '#faraday_middlewares' do
|
93
93
|
subject { configuration.faraday_middlewares }
|
94
94
|
|
95
|
-
context
|
95
|
+
context 'when not set' do
|
96
96
|
let(:configuration) { described_class.new }
|
97
97
|
it { should be_a Proc }
|
98
98
|
end
|
99
99
|
|
100
|
-
context
|
100
|
+
context 'when set' do
|
101
101
|
let(:configuration) { described_class.new(faraday_middlewares: setting) }
|
102
102
|
let(:setting) { proc { something } }
|
103
103
|
it { should eq setting }
|
104
104
|
end
|
105
105
|
end
|
106
106
|
|
107
|
-
describe
|
107
|
+
describe '#merge' do
|
108
108
|
subject { parent.merge(child) }
|
109
109
|
|
110
110
|
let(:parent) do
|
@@ -131,7 +131,7 @@ describe StackerBee::Configuration do
|
|
131
131
|
|
132
132
|
context "when the child doesn't have an attribute set" do
|
133
133
|
let(:child) { described_class.new }
|
134
|
-
it
|
134
|
+
it 'uses the attribute of the parent' do
|
135
135
|
subject.url.should eq :parent_url
|
136
136
|
subject.api_key.should eq :parent_api_key
|
137
137
|
subject.secret_key.should eq :parent_secret_key
|
@@ -143,7 +143,7 @@ describe StackerBee::Configuration do
|
|
143
143
|
|
144
144
|
context "when the parent doesn't have an attribute set" do
|
145
145
|
let(:parent) { described_class.new }
|
146
|
-
it
|
146
|
+
it 'uses the attribute of the child' do
|
147
147
|
subject.url.should eq :child_url
|
148
148
|
subject.api_key.should eq :child_api_key
|
149
149
|
subject.secret_key.should eq :child_secret_key
|
@@ -156,7 +156,7 @@ describe StackerBee::Configuration do
|
|
156
156
|
context "when the parent and child don't have an attribut set" do
|
157
157
|
let(:child) { described_class.new }
|
158
158
|
let(:parent) { described_class.new }
|
159
|
-
it
|
159
|
+
it 'uses the defaults of the attributes of the child' do
|
160
160
|
subject.url.should eq nil
|
161
161
|
subject.api_key.should eq nil
|
162
162
|
subject.secret_key.should eq nil
|
@@ -1,12 +1,12 @@
|
|
1
|
-
require
|
1
|
+
require 'spec_helper'
|
2
2
|
|
3
3
|
describe StackerBee::Connection do
|
4
4
|
subject(:get) { connection.get(path, query_params) }
|
5
5
|
before { Faraday.stub new: faraday }
|
6
6
|
|
7
|
-
let(:url) {
|
8
|
-
let(:path) {
|
9
|
-
let(:secret_key) {
|
7
|
+
let(:url) { 'http://test.com:1234/foo/bar/' }
|
8
|
+
let(:path) { '/foo/bar' }
|
9
|
+
let(:secret_key) { 'shhh' }
|
10
10
|
let(:query_params) { [[:foo, :bar]] }
|
11
11
|
let(:response) { double(:response) }
|
12
12
|
let(:faraday) { double(:faraday, get: response) }
|
@@ -20,47 +20,47 @@ describe StackerBee::Connection do
|
|
20
20
|
)
|
21
21
|
end
|
22
22
|
|
23
|
-
context
|
23
|
+
context 'successfully connecting' do
|
24
24
|
before do
|
25
25
|
faraday.should_receive(:get).with('/foo/bar', query_params) { response }
|
26
26
|
end
|
27
27
|
it { should be response }
|
28
|
-
it
|
28
|
+
it 'specifies url without path when creating connection' do
|
29
29
|
get
|
30
|
-
Faraday.should have_received(:new).with(url:
|
30
|
+
Faraday.should have_received(:new).with(url: 'http://test.com:1234',
|
31
31
|
ssl: { verify: true })
|
32
32
|
end
|
33
33
|
end
|
34
34
|
|
35
|
-
context
|
35
|
+
context 'failing to connect' do
|
36
36
|
before do
|
37
|
-
faraday.stub(:get) { fail Faraday::Error::ConnectionFailed,
|
37
|
+
faraday.stub(:get) { fail Faraday::Error::ConnectionFailed, 'boom' }
|
38
38
|
end
|
39
|
-
it
|
39
|
+
it 'raises a helpful exception' do
|
40
40
|
expect { get }.to raise_error StackerBee::ConnectionError, /#{url}/
|
41
41
|
end
|
42
42
|
end
|
43
43
|
|
44
|
-
context
|
45
|
-
let(:url) {
|
46
|
-
it
|
44
|
+
context 'no protocol specified in URL' do
|
45
|
+
let(:url) { 'wrong.com' }
|
46
|
+
it 'raises a helpful exception' do
|
47
47
|
expect { get }.to raise_error StackerBee::ConnectionError, /no protocol/
|
48
48
|
end
|
49
49
|
end
|
50
50
|
|
51
|
-
context
|
51
|
+
context 'when given a path' do
|
52
52
|
let(:path) { '/baz' }
|
53
|
-
it
|
53
|
+
it 'makes a request to the correct path' do
|
54
54
|
expect(faraday).to receive(:get).with(query_params, path)
|
55
55
|
connection.get query_params, path
|
56
56
|
end
|
57
57
|
end
|
58
58
|
|
59
|
-
context
|
59
|
+
context 'when verifying an ssl connection' do
|
60
60
|
let(:ssl_verify) { false }
|
61
|
-
it
|
61
|
+
it 'specifies the ssl verify option when creating a connection' do
|
62
62
|
get
|
63
|
-
Faraday.should have_received(:new).with(url:
|
63
|
+
Faraday.should have_received(:new).with(url: 'http://test.com:1234',
|
64
64
|
ssl: { verify: false })
|
65
65
|
end
|
66
66
|
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
require
|
1
|
+
require 'spec_helper'
|
2
2
|
|
3
3
|
describe StackerBee::Middleware::Adapter do
|
4
4
|
let(:env) do
|
@@ -19,14 +19,14 @@ describe StackerBee::Middleware::Adapter do
|
|
19
19
|
let(:raw_response) do
|
20
20
|
double(env: { response_headers: response_headers }, body: response_body)
|
21
21
|
end
|
22
|
-
let(:response_headers) { {
|
23
|
-
let(:content_type) {
|
22
|
+
let(:response_headers) { { 'content-type' => content_type } }
|
23
|
+
let(:content_type) { 'text/javascript; charset=UTF-8' }
|
24
24
|
let(:response_body) { double }
|
25
25
|
|
26
|
-
describe
|
26
|
+
describe '#call' do
|
27
27
|
before { middleware.call(env) }
|
28
28
|
|
29
|
-
it
|
29
|
+
it 'makes a call via the connection' do
|
30
30
|
connection.should have_received(:get)
|
31
31
|
end
|
32
32
|
|
@@ -42,12 +42,12 @@ describe StackerBee::Middleware::Adapter do
|
|
42
42
|
env.response.body.should == response_body
|
43
43
|
end
|
44
44
|
|
45
|
-
it
|
45
|
+
it 'sorts the paramers' do
|
46
46
|
connection.should have_received(:get).with(path, [%w(a a), %w(z z)])
|
47
47
|
end
|
48
48
|
end
|
49
49
|
|
50
|
-
describe
|
50
|
+
describe '#endpoint_name_for' do
|
51
51
|
subject { middleware.endpoint_name_for('listVirtualMachines') }
|
52
52
|
it { should be_nil }
|
53
53
|
end
|