droplet_kit 2.8.0 → 2.9.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/README.md +4 -1
- data/lib/droplet_kit/mappings/cdn_mapping.rb +6 -0
- data/lib/droplet_kit/mappings/load_balancer_mapping.rb +1 -0
- data/lib/droplet_kit/models/cdn.rb +2 -0
- data/lib/droplet_kit/models/load_balancer.rb +1 -0
- data/lib/droplet_kit/resources/cdn_resource.rb +6 -0
- data/lib/droplet_kit/version.rb +1 -1
- metadata +4 -289
- data/.gitignore +0 -23
- data/.rspec +0 -2
- data/.travis.yml +0 -28
- data/CHANGELOG.md +0 -106
- data/Gemfile +0 -15
- data/Rakefile +0 -3
- data/droplet_kit.gemspec +0 -37
- data/spec/fixtures/account/info.json +0 -8
- data/spec/fixtures/actions/all.json +0 -24
- data/spec/fixtures/actions/find.json +0 -19
- data/spec/fixtures/cdns/all.json +0 -16
- data/spec/fixtures/cdns/create.json +0 -9
- data/spec/fixtures/cdns/find.json +0 -9
- data/spec/fixtures/cdns/update_ttl.json +0 -9
- data/spec/fixtures/certificates/all.json +0 -19
- data/spec/fixtures/certificates/find.json +0 -12
- data/spec/fixtures/certificates/lets_encrypt.json +0 -12
- data/spec/fixtures/domain_records/all.json +0 -57
- data/spec/fixtures/domain_records/create.json +0 -12
- data/spec/fixtures/domain_records/find.json +0 -12
- data/spec/fixtures/domain_records/update.json +0 -12
- data/spec/fixtures/domains/all.json +0 -12
- data/spec/fixtures/domains/create.json +0 -7
- data/spec/fixtures/domains/find.json +0 -7
- data/spec/fixtures/droplet_actions/change_kernel.json +0 -27
- data/spec/fixtures/droplet_actions/disable_backups.json +0 -27
- data/spec/fixtures/droplet_actions/enable_backups.json +0 -27
- data/spec/fixtures/droplet_actions/enable_ipv6.json +0 -27
- data/spec/fixtures/droplet_actions/enable_private_networking.json +0 -27
- data/spec/fixtures/droplet_actions/find.json +0 -19
- data/spec/fixtures/droplet_actions/password_reset.json +0 -27
- data/spec/fixtures/droplet_actions/power_cycle.json +0 -27
- data/spec/fixtures/droplet_actions/power_off.json +0 -27
- data/spec/fixtures/droplet_actions/power_on.json +0 -27
- data/spec/fixtures/droplet_actions/reboot.json +0 -27
- data/spec/fixtures/droplet_actions/rebuild.json +0 -27
- data/spec/fixtures/droplet_actions/rename.json +0 -27
- data/spec/fixtures/droplet_actions/resize.json +0 -27
- data/spec/fixtures/droplet_actions/restore.json +0 -27
- data/spec/fixtures/droplet_actions/shutdown.json +0 -27
- data/spec/fixtures/droplet_actions/snapshot.json +0 -27
- data/spec/fixtures/droplet_actions/upgrade.json +0 -27
- data/spec/fixtures/droplet_upgrades/all.json +0 -7
- data/spec/fixtures/droplets/all.json +0 -89
- data/spec/fixtures/droplets/all_empty.json +0 -7
- data/spec/fixtures/droplets/create.json +0 -84
- data/spec/fixtures/droplets/create_multiple.json +0 -168
- data/spec/fixtures/droplets/find.json +0 -84
- data/spec/fixtures/droplets/list_actions.json +0 -24
- data/spec/fixtures/droplets/list_backups.json +0 -18
- data/spec/fixtures/droplets/list_kernels.json +0 -17
- data/spec/fixtures/droplets/list_snapshots.json +0 -18
- data/spec/fixtures/firewalls/all.json +0 -67
- data/spec/fixtures/firewalls/find.json +0 -61
- data/spec/fixtures/floating_ip_actions/all.json +0 -41
- data/spec/fixtures/floating_ip_actions/assign.json +0 -27
- data/spec/fixtures/floating_ip_actions/find.json +0 -19
- data/spec/fixtures/floating_ip_actions/unassign.json +0 -27
- data/spec/fixtures/floating_ips/all.json +0 -186
- data/spec/fixtures/floating_ips/all_empty.json +0 -7
- data/spec/fixtures/floating_ips/create.json +0 -29
- data/spec/fixtures/floating_ips/create_with_droplet.json +0 -44
- data/spec/fixtures/floating_ips/find.json +0 -28
- data/spec/fixtures/image_actions/all.json +0 -36
- data/spec/fixtures/image_actions/convert.json +0 -27
- data/spec/fixtures/image_actions/find.json +0 -19
- data/spec/fixtures/image_actions/transfer.json +0 -27
- data/spec/fixtures/images/all.json +0 -31
- data/spec/fixtures/images/find.json +0 -16
- data/spec/fixtures/images/private.json +0 -31
- data/spec/fixtures/images/type.json +0 -31
- data/spec/fixtures/kubernetes/all.json +0 -70
- data/spec/fixtures/kubernetes/all_empty.json +0 -7
- data/spec/fixtures/kubernetes/cluster_node_pool.json +0 -24
- data/spec/fixtures/kubernetes/cluster_node_pool_create.json +0 -40
- data/spec/fixtures/kubernetes/cluster_node_pool_update.json +0 -31
- data/spec/fixtures/kubernetes/cluster_node_pools.json +0 -33
- data/spec/fixtures/kubernetes/clusters/create.json +0 -65
- data/spec/fixtures/kubernetes/clusters/find.json +0 -65
- data/spec/fixtures/kubernetes/clusters/kubeconfig.txt +0 -20
- data/spec/fixtures/kubernetes/clusters/update.json +0 -63
- data/spec/fixtures/kubernetes/options.json +0 -150
- data/spec/fixtures/load_balancers/all.json +0 -129
- data/spec/fixtures/load_balancers/find.json +0 -59
- data/spec/fixtures/projects/all.json +0 -37
- data/spec/fixtures/projects/all_empty.json +0 -12
- data/spec/fixtures/projects/find.json +0 -14
- data/spec/fixtures/projects/resources.json +0 -84
- data/spec/fixtures/regions/all.json +0 -47
- data/spec/fixtures/sizes/all.json +0 -37
- data/spec/fixtures/snapshots/all.json +0 -32
- data/spec/fixtures/snapshots/find.json +0 -14
- data/spec/fixtures/snapshots/resource_type.json +0 -20
- data/spec/fixtures/ssh_keys/all.json +0 -13
- data/spec/fixtures/ssh_keys/create.json +0 -8
- data/spec/fixtures/ssh_keys/find.json +0 -8
- data/spec/fixtures/ssh_keys/update.json +0 -8
- data/spec/fixtures/tags/all.json +0 -34
- data/spec/fixtures/tags/all_empty.json +0 -7
- data/spec/fixtures/tags/create.json +0 -15
- data/spec/fixtures/tags/find.json +0 -99
- data/spec/fixtures/volume_actions/all.json +0 -41
- data/spec/fixtures/volume_actions/attach.json +0 -34
- data/spec/fixtures/volume_actions/detach.json +0 -34
- data/spec/fixtures/volume_actions/find.json +0 -34
- data/spec/fixtures/volume_actions/resize.json +0 -34
- data/spec/fixtures/volumes/all.json +0 -41
- data/spec/fixtures/volumes/create.json +0 -34
- data/spec/fixtures/volumes/create_snapshot.json +0 -14
- data/spec/fixtures/volumes/find.json +0 -34
- data/spec/lib/droplet_kit/client_spec.rb +0 -102
- data/spec/lib/droplet_kit/models/base_model_spec.rb +0 -21
- data/spec/lib/droplet_kit/models/droplet_spec.rb +0 -32
- data/spec/lib/droplet_kit/paginated_resource_spec.rb +0 -85
- data/spec/lib/droplet_kit/resources/account_resource_spec.rb +0 -30
- data/spec/lib/droplet_kit/resources/action_resource_spec.rb +0 -83
- data/spec/lib/droplet_kit/resources/cdn_resource_spec.rb +0 -124
- data/spec/lib/droplet_kit/resources/certificate_resource_spec.rb +0 -119
- data/spec/lib/droplet_kit/resources/domain_record_resource_spec.rb +0 -99
- data/spec/lib/droplet_kit/resources/domain_resource_spec.rb +0 -65
- data/spec/lib/droplet_kit/resources/droplet_action_resource_spec.rb +0 -223
- data/spec/lib/droplet_kit/resources/droplet_resource_spec.rb +0 -340
- data/spec/lib/droplet_kit/resources/droplet_upgrade_resource_spec.rb +0 -22
- data/spec/lib/droplet_kit/resources/firewall_resource_spec.rb +0 -265
- data/spec/lib/droplet_kit/resources/floating_ip_action_resource_spec.rb +0 -137
- data/spec/lib/droplet_kit/resources/floating_ip_resource_spec.rb +0 -91
- data/spec/lib/droplet_kit/resources/image_action_resource_spec.rb +0 -149
- data/spec/lib/droplet_kit/resources/image_resource_spec.rb +0 -93
- data/spec/lib/droplet_kit/resources/kubernetes_cluster_resource_spec.rb +0 -313
- data/spec/lib/droplet_kit/resources/kubernetes_options_resource_spec.rb +0 -33
- data/spec/lib/droplet_kit/resources/load_balancer_resource_spec.rb +0 -213
- data/spec/lib/droplet_kit/resources/project_resource_spec.rb +0 -126
- data/spec/lib/droplet_kit/resources/region_resource_spec.rb +0 -27
- data/spec/lib/droplet_kit/resources/size_resource_spec.rb +0 -27
- data/spec/lib/droplet_kit/resources/snapshot_resource_spec.rb +0 -61
- data/spec/lib/droplet_kit/resources/ssh_key_resource_spec.rb +0 -92
- data/spec/lib/droplet_kit/resources/tag_resource_spec.rb +0 -135
- data/spec/lib/droplet_kit/resources/volume_action_resource_spec.rb +0 -157
- data/spec/lib/droplet_kit/resources/volume_resource_spec.rb +0 -124
- data/spec/spec_helper.rb +0 -19
- data/spec/support/fake_server.rb +0 -4
- data/spec/support/request_stub_helpers.rb +0 -28
- data/spec/support/resource_context.rb +0 -4
- data/spec/support/shared_examples/common_errors.rb +0 -27
- data/spec/support/shared_examples/paginated_endpoint.rb +0 -16
- data/spec/support/shared_examples/unprocessable_entity.rb +0 -11
@@ -1,340 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
RSpec.describe DropletKit::DropletResource do
|
4
|
-
subject(:resource) { described_class.new(connection: connection) }
|
5
|
-
include_context 'resources'
|
6
|
-
|
7
|
-
# There's a lot to check
|
8
|
-
def check_droplet(droplet, tags = [], overrides = {})
|
9
|
-
attrs = {
|
10
|
-
id: 19,
|
11
|
-
name: 'test.example.com',
|
12
|
-
memory: 1024,
|
13
|
-
vcpus: 2,
|
14
|
-
disk: 20,
|
15
|
-
locked: false,
|
16
|
-
status: 'active'
|
17
|
-
}.merge(overrides)
|
18
|
-
|
19
|
-
attrs.each do |attr, val|
|
20
|
-
expect(droplet.send(attr)).to eq attrs[attr]
|
21
|
-
end
|
22
|
-
|
23
|
-
expect(droplet.created_at).to be_present
|
24
|
-
expect(droplet.backup_ids).to include(449676382)
|
25
|
-
expect(droplet.snapshot_ids).to include(449676383)
|
26
|
-
expect(droplet.action_ids).to be_empty
|
27
|
-
expect(droplet.features).to include('ipv6')
|
28
|
-
tags.each do |tag|
|
29
|
-
expect(droplet.tags).to include(tag)
|
30
|
-
end
|
31
|
-
|
32
|
-
expect(droplet.region).to be_kind_of(DropletKit::Region)
|
33
|
-
expect(droplet.region.slug).to eq('nyc1')
|
34
|
-
expect(droplet.region.name).to eq('New York')
|
35
|
-
expect(droplet.region.sizes).to include('1024mb', '512mb')
|
36
|
-
expect(droplet.region.available).to be(true)
|
37
|
-
expect(droplet.region.features).to include("virtio", "private_networking", "backups", "ipv6")
|
38
|
-
|
39
|
-
expect(droplet.image).to be_kind_of(DropletKit::Image)
|
40
|
-
expect(droplet.image.id).to eq(119192817)
|
41
|
-
expect(droplet.image.name).to eq("Ubuntu 13.04")
|
42
|
-
expect(droplet.image.distribution).to eq("ubuntu")
|
43
|
-
expect(droplet.image.slug).to eq("ubuntu1304")
|
44
|
-
expect(droplet.image.public).to eq(true)
|
45
|
-
expect(droplet.image.regions).to include('nyc1')
|
46
|
-
|
47
|
-
expect(droplet.size_slug).to eq("1024mb")
|
48
|
-
|
49
|
-
expect(droplet.networks).to be_kind_of(DropletKit::NetworkHash)
|
50
|
-
private_v4_network = droplet.networks.v4.first
|
51
|
-
expect(private_v4_network.ip_address).to eq('10.0.0.19')
|
52
|
-
expect(private_v4_network.netmask).to eq("255.255.0.0")
|
53
|
-
expect(private_v4_network.gateway).to eq("10.0.0.1")
|
54
|
-
expect(private_v4_network.type).to eq("private")
|
55
|
-
|
56
|
-
public_v4_network = droplet.networks.v4.last
|
57
|
-
expect(public_v4_network.ip_address).to eq('127.0.0.19')
|
58
|
-
expect(public_v4_network.netmask).to eq("255.255.255.0")
|
59
|
-
expect(public_v4_network.gateway).to eq("127.0.0.20")
|
60
|
-
expect(public_v4_network.type).to eq("public")
|
61
|
-
|
62
|
-
v6_network = droplet.networks.v6.first
|
63
|
-
expect(v6_network.ip_address).to eq('2001::13')
|
64
|
-
expect(v6_network.gateway).to eq("2400:6180:0000:00D0:0000:0000:0009:7000")
|
65
|
-
expect(v6_network.cidr).to eq(124)
|
66
|
-
expect(v6_network.type).to eq("public")
|
67
|
-
|
68
|
-
expect(droplet.kernel).to be_kind_of(DropletKit::Kernel)
|
69
|
-
expect(droplet.kernel.id).to eq(485432985)
|
70
|
-
expect(droplet.kernel.name).to eq("DO-recovery-static-fsck")
|
71
|
-
expect(droplet.kernel.version).to eq("3.8.0-25-generic")
|
72
|
-
end
|
73
|
-
|
74
|
-
describe '#all' do
|
75
|
-
it 'returns all of the droplets' do
|
76
|
-
stub_do_api('/v2/droplets', :get).to_return(body: api_fixture('droplets/all'))
|
77
|
-
droplets = resource.all
|
78
|
-
expect(droplets).to all(be_kind_of(DropletKit::Droplet))
|
79
|
-
|
80
|
-
check_droplet(droplets.first, ['tag-1', 'tag-2'])
|
81
|
-
end
|
82
|
-
|
83
|
-
it 'returns an empty array of droplets' do
|
84
|
-
stub_do_api('/v2/droplets', :get).to_return(body: api_fixture('droplets/all_empty'))
|
85
|
-
droplets = resource.all.map(&:id)
|
86
|
-
expect(droplets).to be_empty
|
87
|
-
end
|
88
|
-
|
89
|
-
it_behaves_like 'a paginated index' do
|
90
|
-
let(:fixture_path) { 'droplets/all' }
|
91
|
-
let(:api_path) { '/v2/droplets' }
|
92
|
-
end
|
93
|
-
end
|
94
|
-
|
95
|
-
describe '#find' do
|
96
|
-
it 'returns a singular droplet' do
|
97
|
-
stub_do_api('/v2/droplets/20', :get).to_return(body: api_fixture('droplets/find'))
|
98
|
-
droplet = resource.find(id: 20)
|
99
|
-
expect(droplet).to be_kind_of(DropletKit::Droplet)
|
100
|
-
check_droplet(droplet, ['tag-1', 'tag-2'])
|
101
|
-
end
|
102
|
-
|
103
|
-
it_behaves_like 'resource that handles common errors' do
|
104
|
-
let(:path) { '/v2/droplets/123' }
|
105
|
-
let(:method) { :get }
|
106
|
-
let(:action) { :find }
|
107
|
-
let(:arguments) { { id: 123 } }
|
108
|
-
end
|
109
|
-
end
|
110
|
-
|
111
|
-
describe '#create' do
|
112
|
-
let(:path) { '/v2/droplets' }
|
113
|
-
|
114
|
-
context 'for a successful create' do
|
115
|
-
it 'returns the created droplet' do
|
116
|
-
droplet = DropletKit::Droplet.new(
|
117
|
-
name: 'test.example.com',
|
118
|
-
region: 'nyc1',
|
119
|
-
size: '512mb',
|
120
|
-
image: 'ubuntu-14-04-x86',
|
121
|
-
ssh_keys: [123],
|
122
|
-
backups: true,
|
123
|
-
monitoring: true,
|
124
|
-
ipv6: true,
|
125
|
-
private_networking: true,
|
126
|
-
user_data: "#cloud-config\nruncmd\n\t- echo 'Hello!'",
|
127
|
-
tags: ['one', 'two']
|
128
|
-
)
|
129
|
-
|
130
|
-
as_hash = DropletKit::DropletMapping.hash_for(:create, droplet)
|
131
|
-
expect(as_hash['name']).to eq(droplet.name)
|
132
|
-
expect(as_hash['region']).to eq(droplet.region)
|
133
|
-
expect(as_hash['size']).to eq(droplet.size)
|
134
|
-
expect(as_hash['image']).to eq(droplet.image)
|
135
|
-
expect(as_hash['ssh_keys']).to eq(droplet.ssh_keys)
|
136
|
-
expect(as_hash['backups']).to eq(droplet.backups)
|
137
|
-
expect(as_hash['monitoring']).to eq(droplet.monitoring)
|
138
|
-
expect(as_hash['ipv6']).to eq(droplet.ipv6)
|
139
|
-
expect(as_hash['private_networking']).to eq(droplet.private_networking)
|
140
|
-
expect(as_hash['user_data']).to eq(droplet.user_data)
|
141
|
-
expect(as_hash['tags']).to eq(droplet.tags)
|
142
|
-
|
143
|
-
as_string = DropletKit::DropletMapping.representation_for(:create, droplet)
|
144
|
-
stub_do_api(path, :post).with(body: as_string).to_return(body: api_fixture('droplets/create'), status: 202)
|
145
|
-
created_droplet = resource.create(droplet)
|
146
|
-
check_droplet(created_droplet)
|
147
|
-
end
|
148
|
-
|
149
|
-
it 'reuses the same object' do
|
150
|
-
droplet = DropletKit::Droplet.new(
|
151
|
-
name: 'test.example.com',
|
152
|
-
region: 'nyc1',
|
153
|
-
size: '512mb',
|
154
|
-
image: 'ubuntu-14-04-x86'
|
155
|
-
)
|
156
|
-
|
157
|
-
json = DropletKit::DropletMapping.representation_for(:create, droplet)
|
158
|
-
stub_do_api(path, :post).with(body: json).to_return(body: api_fixture('droplets/create'), status: 202)
|
159
|
-
created_droplet = resource.create(droplet)
|
160
|
-
expect(created_droplet).to be droplet
|
161
|
-
end
|
162
|
-
end
|
163
|
-
|
164
|
-
it_behaves_like 'an action that handles invalid parameters' do
|
165
|
-
let(:action) { 'create' }
|
166
|
-
let(:arguments) { DropletKit::Droplet.new }
|
167
|
-
end
|
168
|
-
end
|
169
|
-
|
170
|
-
describe '#create_multiple' do
|
171
|
-
let(:path) { '/v2/droplets' }
|
172
|
-
|
173
|
-
context 'for a successful multiple create' do
|
174
|
-
it 'returns the created droplets' do
|
175
|
-
droplet = DropletKit::Droplet.new(
|
176
|
-
names: ['test-01.example.com', 'test-02.example.com'],
|
177
|
-
region: 'nyc1',
|
178
|
-
size: '512mb',
|
179
|
-
image: 'ubuntu-14-04-x86',
|
180
|
-
ssh_keys: [123],
|
181
|
-
backups: true,
|
182
|
-
ipv6: true,
|
183
|
-
private_networking: true,
|
184
|
-
user_data: "#cloud-config\nruncmd\n\t- echo 'Hello!'",
|
185
|
-
tags: ['one', 'two']
|
186
|
-
)
|
187
|
-
|
188
|
-
as_hash = DropletKit::DropletMapping.hash_for(:create, droplet)
|
189
|
-
expect(as_hash['names']).to eq(droplet.names)
|
190
|
-
expect(as_hash['region']).to eq(droplet.region)
|
191
|
-
expect(as_hash['size']).to eq(droplet.size)
|
192
|
-
expect(as_hash['image']).to eq(droplet.image)
|
193
|
-
expect(as_hash['ssh_keys']).to eq(droplet.ssh_keys)
|
194
|
-
expect(as_hash['backups']).to eq(droplet.backups)
|
195
|
-
expect(as_hash['ipv6']).to eq(droplet.ipv6)
|
196
|
-
expect(as_hash['private_networking']).to eq(droplet.private_networking)
|
197
|
-
expect(as_hash['user_data']).to eq(droplet.user_data)
|
198
|
-
expect(as_hash['tags']).to eq(droplet.tags)
|
199
|
-
|
200
|
-
as_string = DropletKit::DropletMapping.representation_for(:create, droplet)
|
201
|
-
stub_do_api(path, :post).with(body: as_string).to_return(body: api_fixture('droplets/create_multiple'), status: 202)
|
202
|
-
|
203
|
-
created_droplets = resource.create_multiple(droplet)
|
204
|
-
check_droplet(created_droplets[0], [], name: 'test-01.example.com')
|
205
|
-
check_droplet(created_droplets[1], [], id: 20, name: 'test-02.example.com')
|
206
|
-
end
|
207
|
-
|
208
|
-
it 'reuses the same object' do
|
209
|
-
droplet = DropletKit::Droplet.new(
|
210
|
-
names: ['test-01.example.com', 'test-02.example.com'],
|
211
|
-
region: 'nyc1',
|
212
|
-
size: '512mb',
|
213
|
-
image: 'ubuntu-14-04-x86'
|
214
|
-
)
|
215
|
-
|
216
|
-
json = DropletKit::DropletMapping.representation_for(:create, droplet)
|
217
|
-
stub_do_api(path, :post).with(body: json).to_return(body: api_fixture('droplets/create_multiple'), status: 202)
|
218
|
-
created_droplets = resource.create_multiple(droplet)
|
219
|
-
check_droplet(created_droplets[0], [], name: 'test-01.example.com')
|
220
|
-
check_droplet(created_droplets[1], [], id: 20, name: 'test-02.example.com')
|
221
|
-
end
|
222
|
-
end
|
223
|
-
|
224
|
-
it_behaves_like 'an action that handles invalid parameters' do
|
225
|
-
let(:action) { 'create' }
|
226
|
-
let(:arguments) { DropletKit::Droplet.new }
|
227
|
-
end
|
228
|
-
end
|
229
|
-
|
230
|
-
describe '#kernels' do
|
231
|
-
it 'returns a list of kernels for a droplet' do
|
232
|
-
stub_do_api('/v2/droplets/1066/kernels', :get).to_return(body: api_fixture('droplets/list_kernels'))
|
233
|
-
kernels = resource.kernels(id: 1066).take(20)
|
234
|
-
|
235
|
-
expect(kernels).to all(be_kind_of(DropletKit::Kernel))
|
236
|
-
expect(kernels[0].id).to eq(61833229)
|
237
|
-
expect(kernels[0].name).to eq('Ubuntu 14.04 x32 vmlinuz-3.13.0-24-generic')
|
238
|
-
expect(kernels[0].version).to eq('3.13.0-24-generic')
|
239
|
-
|
240
|
-
expect(kernels[1].id).to eq(485432972)
|
241
|
-
expect(kernels[1].name).to eq('Ubuntu 14.04 x64 vmlinuz-3.13.0-24-generic (1221)')
|
242
|
-
expect(kernels[1].version).to eq('3.13.0-24-generic')
|
243
|
-
end
|
244
|
-
|
245
|
-
it 'returns a paginated resource' do
|
246
|
-
stub_do_api('/v2/droplets/1066/kernels', :get).to_return(body: api_fixture('droplets/list_kernels'))
|
247
|
-
kernels = resource.kernels(id: 1066, page: 1, per_page: 1)
|
248
|
-
expect(kernels).to be_kind_of(DropletKit::PaginatedResource)
|
249
|
-
end
|
250
|
-
end
|
251
|
-
|
252
|
-
describe '#snapshots' do
|
253
|
-
it 'returns a list of image snapshots for a droplet' do
|
254
|
-
stub_do_api('/v2/droplets/1066/snapshots', :get).to_return(body: api_fixture('droplets/list_snapshots'))
|
255
|
-
snapshots = resource.snapshots(id: 1066).take(20)
|
256
|
-
|
257
|
-
expect(snapshots).to all(be_kind_of(DropletKit::Image))
|
258
|
-
expect(snapshots[0].id).to eq(449676387)
|
259
|
-
expect(snapshots[0].name).to eq("Ubuntu 13.04")
|
260
|
-
expect(snapshots[0].distribution).to eq("ubuntu")
|
261
|
-
expect(snapshots[0].slug).to eq(nil)
|
262
|
-
expect(snapshots[0].public).to eq(false)
|
263
|
-
expect(snapshots[0].regions).to eq(["nyc1"])
|
264
|
-
end
|
265
|
-
|
266
|
-
it 'returns a paginated resource' do
|
267
|
-
stub_do_api('/v2/droplets/1066/snapshots', :get).to_return(body: api_fixture('droplets/list_snapshots'))
|
268
|
-
snapshots = resource.snapshots(id: 1066, page: 1, per_page: 1)
|
269
|
-
expect(snapshots).to be_kind_of(DropletKit::PaginatedResource)
|
270
|
-
end
|
271
|
-
end
|
272
|
-
|
273
|
-
describe '#backups' do
|
274
|
-
it 'returns a list of backups for a droplet' do
|
275
|
-
stub_do_api('/v2/droplets/1066/backups', :get).to_return(body: api_fixture('droplets/list_backups'))
|
276
|
-
backups = resource.backups(id: 1066).take(20)
|
277
|
-
|
278
|
-
expect(backups).to all(be_kind_of(DropletKit::Image))
|
279
|
-
expect(backups[0].id).to eq(449676388)
|
280
|
-
expect(backups[0].name).to eq("Ubuntu 13.04")
|
281
|
-
expect(backups[0].distribution).to eq("ubuntu")
|
282
|
-
expect(backups[0].slug).to eq(nil)
|
283
|
-
expect(backups[0].public).to eq(false)
|
284
|
-
expect(backups[0].regions).to eq(["nyc1"])
|
285
|
-
end
|
286
|
-
|
287
|
-
it 'returns a paginated resource' do
|
288
|
-
stub_do_api('/v2/droplets/1066/backups', :get).to_return(body: api_fixture('droplets/list_backups'))
|
289
|
-
backups = resource.backups(id: 1066, page: 1, per_page: 1)
|
290
|
-
expect(backups).to be_kind_of(DropletKit::PaginatedResource)
|
291
|
-
end
|
292
|
-
end
|
293
|
-
|
294
|
-
describe '#actions' do
|
295
|
-
it 'returns a list of actions for the droplet' do
|
296
|
-
stub_do_api('/v2/droplets/1066/actions', :get).to_return(body: api_fixture('droplets/list_actions'))
|
297
|
-
actions = resource.actions(id: 1066).take(20)
|
298
|
-
|
299
|
-
expect(actions).to all(be_kind_of(DropletKit::Action))
|
300
|
-
|
301
|
-
expect(actions[0].id).to eq(19)
|
302
|
-
expect(actions[0].status).to eq("in-progress")
|
303
|
-
expect(actions[0].type).to eq("create")
|
304
|
-
expect(actions[0].started_at).to eq("2014-07-29T14:35:39Z")
|
305
|
-
expect(actions[0].completed_at).to eq(nil)
|
306
|
-
expect(actions[0].resource_id).to eq(24)
|
307
|
-
expect(actions[0].resource_type).to eq("droplet")
|
308
|
-
expect(actions[0].region).to be_kind_of(DropletKit::Region)
|
309
|
-
expect(actions[0].region.slug).to eq('nyc1')
|
310
|
-
expect(actions[0].region.name).to eq('New York')
|
311
|
-
expect(actions[0].region.sizes).to include('512mb')
|
312
|
-
expect(actions[0].region.available).to be(true)
|
313
|
-
expect(actions[0].region.features).to include("virtio", "private_networking", "backups", "ipv6", "metadata")
|
314
|
-
end
|
315
|
-
|
316
|
-
it 'returns a paginated resource' do
|
317
|
-
stub_do_api('/v2/droplets/1066/actions', :get).to_return(body: api_fixture('droplets/list_actions'))
|
318
|
-
actions = resource.actions(id: 1066, page: 1, per_page: 1)
|
319
|
-
expect(actions).to be_kind_of(DropletKit::PaginatedResource)
|
320
|
-
end
|
321
|
-
end
|
322
|
-
|
323
|
-
describe '#delete' do
|
324
|
-
it 'sends a delete request for the droplet' do
|
325
|
-
request = stub_do_api('/v2/droplets/1066', :delete)
|
326
|
-
resource.delete(id: 1066)
|
327
|
-
|
328
|
-
expect(request).to have_been_made
|
329
|
-
end
|
330
|
-
end
|
331
|
-
|
332
|
-
describe '#delete_tagged' do
|
333
|
-
it 'sends a delete request for the tagged droplet' do
|
334
|
-
request = stub_do_api('/v2/droplets?tag_name=testing-1', :delete)
|
335
|
-
resource.delete_for_tag(tag_name: 'testing-1')
|
336
|
-
|
337
|
-
expect(request).to have_been_made
|
338
|
-
end
|
339
|
-
end
|
340
|
-
end
|
@@ -1,22 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
RSpec.describe DropletKit::DropletUpgradeResource do
|
4
|
-
subject(:resource) { described_class.new(connection: connection) }
|
5
|
-
include_context 'resources'
|
6
|
-
|
7
|
-
describe '#all' do
|
8
|
-
it 'returns a collection of Droplet upgrades' do
|
9
|
-
body = api_fixture('droplet_upgrades/all')
|
10
|
-
stub_do_api('/v2/droplet_upgrades').to_return(body: body)
|
11
|
-
expected = DropletKit::DropletUpgradeMapping.extract_collection(body, :read)
|
12
|
-
|
13
|
-
expect(resource.all).to eq(expected)
|
14
|
-
end
|
15
|
-
|
16
|
-
it_behaves_like 'resource that handles common errors' do
|
17
|
-
let(:path) { '/v2/droplet_upgrades' }
|
18
|
-
let(:method) { :get }
|
19
|
-
let(:action) { :all }
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end
|
@@ -1,265 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
RSpec.describe DropletKit::FirewallResource do
|
4
|
-
include_context 'resources'
|
5
|
-
|
6
|
-
let(:firewall_fixture_path) { 'firewalls/find' }
|
7
|
-
let(:base_path) { '/v2/firewalls' }
|
8
|
-
let(:firewall_id) { '11d87802-df17-4f8f-a691-58e408570c12' }
|
9
|
-
let(:firewall) do
|
10
|
-
DropletKit::Firewall.new(
|
11
|
-
name: 'firewall',
|
12
|
-
inbound_rules: [
|
13
|
-
DropletKit::FirewallInboundRule.new(
|
14
|
-
protocol: 'icmp',
|
15
|
-
ports: '0',
|
16
|
-
sources: {
|
17
|
-
tags: ['backend'],
|
18
|
-
load_balancer_uids: ['d2d3920a-9d45-41b0-b018-d15e18ec60a4']
|
19
|
-
}
|
20
|
-
),
|
21
|
-
DropletKit::FirewallInboundRule.new(
|
22
|
-
protocol: 'tcp',
|
23
|
-
ports: '8000-9000',
|
24
|
-
sources: {
|
25
|
-
addresses: ['0.0.0.0/0']
|
26
|
-
}
|
27
|
-
)
|
28
|
-
],
|
29
|
-
outbound_rules: [
|
30
|
-
DropletKit::FirewallOutboundRule.new(
|
31
|
-
protocol: 'icmp',
|
32
|
-
ports: '0',
|
33
|
-
destinations: {
|
34
|
-
tags: ['backend']
|
35
|
-
}
|
36
|
-
),
|
37
|
-
DropletKit::FirewallOutboundRule.new(
|
38
|
-
protocol: 'tcp',
|
39
|
-
ports: '8000-9000',
|
40
|
-
destinations: {
|
41
|
-
addresses: ['127.0.0.0']
|
42
|
-
}
|
43
|
-
)
|
44
|
-
],
|
45
|
-
droplet_ids: [123],
|
46
|
-
tags: ['backend'])
|
47
|
-
end
|
48
|
-
|
49
|
-
subject(:resource) { described_class.new(connection: connection) }
|
50
|
-
|
51
|
-
RSpec::Matchers.define :match_firewall_fixture do
|
52
|
-
match do |firewall|
|
53
|
-
expect(firewall.id).to eq('11d87802-df17-4f8f-a691-58e408570c12')
|
54
|
-
expect(firewall.name).to eq('firewall')
|
55
|
-
expect(firewall.status).to eq('succeeded')
|
56
|
-
expect(firewall.created_at).to eq('2017-05-30T16:25:21Z')
|
57
|
-
expect(firewall.inbound_rules.count).to eq(2)
|
58
|
-
expect(firewall.inbound_rules.first.attributes)
|
59
|
-
.to match(a_hash_including(protocol: 'icmp', ports: '0',
|
60
|
-
sources: { 'load_balancer_uids' => ['d2d3920a-9d45-41b0-b018-d15e18ec60a4'],
|
61
|
-
'tags' => ['backend'] }))
|
62
|
-
expect(firewall.inbound_rules.last.attributes)
|
63
|
-
.to match(a_hash_including(protocol: 'tcp', ports: '8000-9000',
|
64
|
-
sources: { 'addresses' => ['0.0.0.0/0'] }))
|
65
|
-
expect(firewall.outbound_rules.count).to eq(2)
|
66
|
-
expect(firewall.outbound_rules.first.attributes)
|
67
|
-
.to match(a_hash_including(protocol: 'icmp', ports: '0',
|
68
|
-
destinations: { 'tags' => ['backend'] }))
|
69
|
-
expect(firewall.outbound_rules.last.attributes)
|
70
|
-
.to match(a_hash_including(protocol: 'tcp', ports: '8000-9000',
|
71
|
-
destinations: { 'addresses' => ['127.0.0.0'],
|
72
|
-
'droplet_ids' => [345] }))
|
73
|
-
expect(firewall.droplet_ids).to match_array([123])
|
74
|
-
expect(firewall.tags).to match_array(['backend'])
|
75
|
-
expect(firewall.pending_changes).to be_empty
|
76
|
-
end
|
77
|
-
end
|
78
|
-
|
79
|
-
describe '#find' do
|
80
|
-
it 'returns firewall' do
|
81
|
-
stub_do_api(File.join(base_path, firewall_id), :get).to_return(body: api_fixture(firewall_fixture_path))
|
82
|
-
firewall = resource.find(id: firewall_id)
|
83
|
-
|
84
|
-
expect(firewall).to match_firewall_fixture
|
85
|
-
end
|
86
|
-
end
|
87
|
-
|
88
|
-
describe '#create' do
|
89
|
-
let(:path) { base_path }
|
90
|
-
|
91
|
-
it 'returns created firewall' do
|
92
|
-
json_body = DropletKit::FirewallMapping.representation_for(:create, firewall)
|
93
|
-
stub_do_api(path, :post).with(body: json_body).to_return(body: api_fixture(firewall_fixture_path), status: 202)
|
94
|
-
|
95
|
-
expect(resource.create(firewall)).to match_firewall_fixture
|
96
|
-
end
|
97
|
-
|
98
|
-
it_behaves_like 'an action that handles invalid parameters' do
|
99
|
-
let(:action) { 'create' }
|
100
|
-
let(:arguments) { DropletKit::Firewall.new }
|
101
|
-
end
|
102
|
-
end
|
103
|
-
|
104
|
-
describe '#update' do
|
105
|
-
let(:path) { base_path }
|
106
|
-
|
107
|
-
it 'returns updated firewall' do
|
108
|
-
json_body = DropletKit::FirewallMapping.representation_for(:update, firewall)
|
109
|
-
stub_do_api(File.join(base_path, firewall_id), :put).with(body: json_body).to_return(body: api_fixture(firewall_fixture_path), status: 200)
|
110
|
-
|
111
|
-
expect(resource.update(firewall, id: firewall_id)).to match_firewall_fixture
|
112
|
-
end
|
113
|
-
|
114
|
-
it_behaves_like 'an action that handles invalid parameters' do
|
115
|
-
let(:verb) { :put }
|
116
|
-
let(:exception) { DropletKit::FailedUpdate }
|
117
|
-
let(:action) { 'update' }
|
118
|
-
let(:arguments) { DropletKit::Firewall.new }
|
119
|
-
end
|
120
|
-
end
|
121
|
-
|
122
|
-
describe '#all' do
|
123
|
-
let(:firewalls_fixture_path) { 'firewalls/all' }
|
124
|
-
|
125
|
-
it 'returns all firewalls' do
|
126
|
-
stub_do_api(base_path, :get).to_return(body: api_fixture(firewalls_fixture_path))
|
127
|
-
firewalls = resource.all
|
128
|
-
|
129
|
-
expect(firewalls).to all(be_kind_of(DropletKit::Firewall))
|
130
|
-
expect(firewalls.first).to match_firewall_fixture
|
131
|
-
end
|
132
|
-
|
133
|
-
it_behaves_like 'a paginated index' do
|
134
|
-
let(:fixture_path) { firewalls_fixture_path }
|
135
|
-
let(:api_path) { base_path }
|
136
|
-
end
|
137
|
-
end
|
138
|
-
|
139
|
-
describe '#all_by_droplet' do
|
140
|
-
let(:droplet_id) { 123 }
|
141
|
-
let(:all_by_droplet_path) { "/v2/droplets/#{droplet_id}/firewalls" }
|
142
|
-
let(:firewalls_fixture_path) { 'firewalls/all' }
|
143
|
-
|
144
|
-
it 'returns all firewalls for a provided droplet' do
|
145
|
-
stub_do_api(all_by_droplet_path, :get).to_return(body: api_fixture(firewalls_fixture_path))
|
146
|
-
firewalls = resource.all_by_droplet(droplet_id: droplet_id)
|
147
|
-
|
148
|
-
expect(firewalls).to all(be_kind_of(DropletKit::Firewall))
|
149
|
-
expect(firewalls.first).to match_firewall_fixture
|
150
|
-
end
|
151
|
-
|
152
|
-
it_behaves_like 'a paginated index' do
|
153
|
-
let(:fixture_path) { firewalls_fixture_path }
|
154
|
-
let(:action) { :all_by_droplet }
|
155
|
-
let(:parameters) { { droplet_id: droplet_id } }
|
156
|
-
let(:api_path) { all_by_droplet_path }
|
157
|
-
end
|
158
|
-
end
|
159
|
-
|
160
|
-
describe '#delete' do
|
161
|
-
it 'sends request to delete given firewall' do
|
162
|
-
request = stub_do_api(File.join(base_path, firewall_id), :delete)
|
163
|
-
resource.delete(id: firewall_id)
|
164
|
-
|
165
|
-
expect(request).to have_been_made
|
166
|
-
end
|
167
|
-
end
|
168
|
-
|
169
|
-
context 'droplets' do
|
170
|
-
let(:droplet_id_1) { 1 }
|
171
|
-
let(:droplet_id_2) { 2 }
|
172
|
-
|
173
|
-
describe '#add_droplets' do
|
174
|
-
it 'sends request to add droplets for a given firewall' do
|
175
|
-
request = stub_do_api(File.join(base_path, firewall_id, 'droplets'), :post).with(body: { droplet_ids: [droplet_id_1, droplet_id_2] }.to_json)
|
176
|
-
resource.add_droplets([droplet_id_1, droplet_id_2], id: firewall_id)
|
177
|
-
|
178
|
-
expect(request).to have_been_made
|
179
|
-
end
|
180
|
-
end
|
181
|
-
|
182
|
-
describe '#remove_droplets' do
|
183
|
-
it 'sends request to remove droplets from a given firewall' do
|
184
|
-
request = stub_do_api(File.join(base_path, firewall_id, 'droplets'), :delete).with(body: { droplet_ids: [droplet_id_1, droplet_id_2]}.to_json)
|
185
|
-
resource.remove_droplets([droplet_id_1, droplet_id_2], id: firewall_id)
|
186
|
-
|
187
|
-
expect(request).to have_been_made
|
188
|
-
end
|
189
|
-
end
|
190
|
-
end
|
191
|
-
|
192
|
-
context 'tags' do
|
193
|
-
let(:frontend_tag) { 'frontend' }
|
194
|
-
let(:backend_tag) { 'backend' }
|
195
|
-
|
196
|
-
describe '#add_tags' do
|
197
|
-
it 'sends request to add tags for a given firewall' do
|
198
|
-
request = stub_do_api(File.join(base_path, firewall_id, 'tags'), :post).with(body: { tags: [frontend_tag, backend_tag] }.to_json)
|
199
|
-
resource.add_tags([frontend_tag, backend_tag], id: firewall_id)
|
200
|
-
|
201
|
-
expect(request).to have_been_made
|
202
|
-
end
|
203
|
-
end
|
204
|
-
|
205
|
-
describe '#remove_tags' do
|
206
|
-
it 'sends request to remove tags from a given firewall' do
|
207
|
-
request = stub_do_api(File.join(base_path, firewall_id, 'tags'), :delete).with(body: { tags: [frontend_tag, backend_tag]}.to_json)
|
208
|
-
resource.remove_tags([frontend_tag, backend_tag], id: firewall_id)
|
209
|
-
|
210
|
-
expect(request).to have_been_made
|
211
|
-
end
|
212
|
-
end
|
213
|
-
end
|
214
|
-
|
215
|
-
context 'rules' do
|
216
|
-
let(:inbound_rule) do
|
217
|
-
DropletKit::FirewallInboundRule.new(
|
218
|
-
protocol: 'tcp',
|
219
|
-
ports: '22',
|
220
|
-
sources: {
|
221
|
-
addresses: ['127.0.0.0'],
|
222
|
-
tags: ['frontend', 'backend']
|
223
|
-
}
|
224
|
-
)
|
225
|
-
end
|
226
|
-
|
227
|
-
let(:outbound_rule) do
|
228
|
-
DropletKit::FirewallOutboundRule.new(
|
229
|
-
protocol: 'tcp',
|
230
|
-
ports: '8080',
|
231
|
-
destinations: {
|
232
|
-
droplet_ids: [123, 456],
|
233
|
-
load_balancer_uids: ['lb-uuid']
|
234
|
-
}
|
235
|
-
)
|
236
|
-
end
|
237
|
-
|
238
|
-
let(:rules) do
|
239
|
-
DropletKit::FirewallRule.new(
|
240
|
-
inbound_rules: [inbound_rule],
|
241
|
-
outbound_rules: [outbound_rule]
|
242
|
-
)
|
243
|
-
end
|
244
|
-
|
245
|
-
describe '#add_rules' do
|
246
|
-
it 'sends request to add rules for a given firewall' do
|
247
|
-
json_body = DropletKit::FirewallRuleMapping.representation_for(:create, rules)
|
248
|
-
request = stub_do_api(File.join(base_path, firewall_id, 'rules'), :post).with(body: json_body)
|
249
|
-
resource.add_rules(inbound_rules: [inbound_rule], outbound_rules: [outbound_rule], id: firewall_id)
|
250
|
-
|
251
|
-
expect(request).to have_been_made
|
252
|
-
end
|
253
|
-
end
|
254
|
-
|
255
|
-
describe '#remove_rules' do
|
256
|
-
it 'sends request to remove rules from a given firewall' do
|
257
|
-
json_body = DropletKit::FirewallRuleMapping.representation_for(:update, rules)
|
258
|
-
request = stub_do_api(File.join(base_path, firewall_id, 'rules'), :delete).with(body: json_body)
|
259
|
-
resource.remove_rules(inbound_rules: [inbound_rule], outbound_rules: [outbound_rule], id: firewall_id)
|
260
|
-
|
261
|
-
expect(request).to have_been_made
|
262
|
-
end
|
263
|
-
end
|
264
|
-
end
|
265
|
-
end
|