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.
Files changed (155) hide show
  1. checksums.yaml +5 -5
  2. data/README.md +4 -1
  3. data/lib/droplet_kit/mappings/cdn_mapping.rb +6 -0
  4. data/lib/droplet_kit/mappings/load_balancer_mapping.rb +1 -0
  5. data/lib/droplet_kit/models/cdn.rb +2 -0
  6. data/lib/droplet_kit/models/load_balancer.rb +1 -0
  7. data/lib/droplet_kit/resources/cdn_resource.rb +6 -0
  8. data/lib/droplet_kit/version.rb +1 -1
  9. metadata +4 -289
  10. data/.gitignore +0 -23
  11. data/.rspec +0 -2
  12. data/.travis.yml +0 -28
  13. data/CHANGELOG.md +0 -106
  14. data/Gemfile +0 -15
  15. data/Rakefile +0 -3
  16. data/droplet_kit.gemspec +0 -37
  17. data/spec/fixtures/account/info.json +0 -8
  18. data/spec/fixtures/actions/all.json +0 -24
  19. data/spec/fixtures/actions/find.json +0 -19
  20. data/spec/fixtures/cdns/all.json +0 -16
  21. data/spec/fixtures/cdns/create.json +0 -9
  22. data/spec/fixtures/cdns/find.json +0 -9
  23. data/spec/fixtures/cdns/update_ttl.json +0 -9
  24. data/spec/fixtures/certificates/all.json +0 -19
  25. data/spec/fixtures/certificates/find.json +0 -12
  26. data/spec/fixtures/certificates/lets_encrypt.json +0 -12
  27. data/spec/fixtures/domain_records/all.json +0 -57
  28. data/spec/fixtures/domain_records/create.json +0 -12
  29. data/spec/fixtures/domain_records/find.json +0 -12
  30. data/spec/fixtures/domain_records/update.json +0 -12
  31. data/spec/fixtures/domains/all.json +0 -12
  32. data/spec/fixtures/domains/create.json +0 -7
  33. data/spec/fixtures/domains/find.json +0 -7
  34. data/spec/fixtures/droplet_actions/change_kernel.json +0 -27
  35. data/spec/fixtures/droplet_actions/disable_backups.json +0 -27
  36. data/spec/fixtures/droplet_actions/enable_backups.json +0 -27
  37. data/spec/fixtures/droplet_actions/enable_ipv6.json +0 -27
  38. data/spec/fixtures/droplet_actions/enable_private_networking.json +0 -27
  39. data/spec/fixtures/droplet_actions/find.json +0 -19
  40. data/spec/fixtures/droplet_actions/password_reset.json +0 -27
  41. data/spec/fixtures/droplet_actions/power_cycle.json +0 -27
  42. data/spec/fixtures/droplet_actions/power_off.json +0 -27
  43. data/spec/fixtures/droplet_actions/power_on.json +0 -27
  44. data/spec/fixtures/droplet_actions/reboot.json +0 -27
  45. data/spec/fixtures/droplet_actions/rebuild.json +0 -27
  46. data/spec/fixtures/droplet_actions/rename.json +0 -27
  47. data/spec/fixtures/droplet_actions/resize.json +0 -27
  48. data/spec/fixtures/droplet_actions/restore.json +0 -27
  49. data/spec/fixtures/droplet_actions/shutdown.json +0 -27
  50. data/spec/fixtures/droplet_actions/snapshot.json +0 -27
  51. data/spec/fixtures/droplet_actions/upgrade.json +0 -27
  52. data/spec/fixtures/droplet_upgrades/all.json +0 -7
  53. data/spec/fixtures/droplets/all.json +0 -89
  54. data/spec/fixtures/droplets/all_empty.json +0 -7
  55. data/spec/fixtures/droplets/create.json +0 -84
  56. data/spec/fixtures/droplets/create_multiple.json +0 -168
  57. data/spec/fixtures/droplets/find.json +0 -84
  58. data/spec/fixtures/droplets/list_actions.json +0 -24
  59. data/spec/fixtures/droplets/list_backups.json +0 -18
  60. data/spec/fixtures/droplets/list_kernels.json +0 -17
  61. data/spec/fixtures/droplets/list_snapshots.json +0 -18
  62. data/spec/fixtures/firewalls/all.json +0 -67
  63. data/spec/fixtures/firewalls/find.json +0 -61
  64. data/spec/fixtures/floating_ip_actions/all.json +0 -41
  65. data/spec/fixtures/floating_ip_actions/assign.json +0 -27
  66. data/spec/fixtures/floating_ip_actions/find.json +0 -19
  67. data/spec/fixtures/floating_ip_actions/unassign.json +0 -27
  68. data/spec/fixtures/floating_ips/all.json +0 -186
  69. data/spec/fixtures/floating_ips/all_empty.json +0 -7
  70. data/spec/fixtures/floating_ips/create.json +0 -29
  71. data/spec/fixtures/floating_ips/create_with_droplet.json +0 -44
  72. data/spec/fixtures/floating_ips/find.json +0 -28
  73. data/spec/fixtures/image_actions/all.json +0 -36
  74. data/spec/fixtures/image_actions/convert.json +0 -27
  75. data/spec/fixtures/image_actions/find.json +0 -19
  76. data/spec/fixtures/image_actions/transfer.json +0 -27
  77. data/spec/fixtures/images/all.json +0 -31
  78. data/spec/fixtures/images/find.json +0 -16
  79. data/spec/fixtures/images/private.json +0 -31
  80. data/spec/fixtures/images/type.json +0 -31
  81. data/spec/fixtures/kubernetes/all.json +0 -70
  82. data/spec/fixtures/kubernetes/all_empty.json +0 -7
  83. data/spec/fixtures/kubernetes/cluster_node_pool.json +0 -24
  84. data/spec/fixtures/kubernetes/cluster_node_pool_create.json +0 -40
  85. data/spec/fixtures/kubernetes/cluster_node_pool_update.json +0 -31
  86. data/spec/fixtures/kubernetes/cluster_node_pools.json +0 -33
  87. data/spec/fixtures/kubernetes/clusters/create.json +0 -65
  88. data/spec/fixtures/kubernetes/clusters/find.json +0 -65
  89. data/spec/fixtures/kubernetes/clusters/kubeconfig.txt +0 -20
  90. data/spec/fixtures/kubernetes/clusters/update.json +0 -63
  91. data/spec/fixtures/kubernetes/options.json +0 -150
  92. data/spec/fixtures/load_balancers/all.json +0 -129
  93. data/spec/fixtures/load_balancers/find.json +0 -59
  94. data/spec/fixtures/projects/all.json +0 -37
  95. data/spec/fixtures/projects/all_empty.json +0 -12
  96. data/spec/fixtures/projects/find.json +0 -14
  97. data/spec/fixtures/projects/resources.json +0 -84
  98. data/spec/fixtures/regions/all.json +0 -47
  99. data/spec/fixtures/sizes/all.json +0 -37
  100. data/spec/fixtures/snapshots/all.json +0 -32
  101. data/spec/fixtures/snapshots/find.json +0 -14
  102. data/spec/fixtures/snapshots/resource_type.json +0 -20
  103. data/spec/fixtures/ssh_keys/all.json +0 -13
  104. data/spec/fixtures/ssh_keys/create.json +0 -8
  105. data/spec/fixtures/ssh_keys/find.json +0 -8
  106. data/spec/fixtures/ssh_keys/update.json +0 -8
  107. data/spec/fixtures/tags/all.json +0 -34
  108. data/spec/fixtures/tags/all_empty.json +0 -7
  109. data/spec/fixtures/tags/create.json +0 -15
  110. data/spec/fixtures/tags/find.json +0 -99
  111. data/spec/fixtures/volume_actions/all.json +0 -41
  112. data/spec/fixtures/volume_actions/attach.json +0 -34
  113. data/spec/fixtures/volume_actions/detach.json +0 -34
  114. data/spec/fixtures/volume_actions/find.json +0 -34
  115. data/spec/fixtures/volume_actions/resize.json +0 -34
  116. data/spec/fixtures/volumes/all.json +0 -41
  117. data/spec/fixtures/volumes/create.json +0 -34
  118. data/spec/fixtures/volumes/create_snapshot.json +0 -14
  119. data/spec/fixtures/volumes/find.json +0 -34
  120. data/spec/lib/droplet_kit/client_spec.rb +0 -102
  121. data/spec/lib/droplet_kit/models/base_model_spec.rb +0 -21
  122. data/spec/lib/droplet_kit/models/droplet_spec.rb +0 -32
  123. data/spec/lib/droplet_kit/paginated_resource_spec.rb +0 -85
  124. data/spec/lib/droplet_kit/resources/account_resource_spec.rb +0 -30
  125. data/spec/lib/droplet_kit/resources/action_resource_spec.rb +0 -83
  126. data/spec/lib/droplet_kit/resources/cdn_resource_spec.rb +0 -124
  127. data/spec/lib/droplet_kit/resources/certificate_resource_spec.rb +0 -119
  128. data/spec/lib/droplet_kit/resources/domain_record_resource_spec.rb +0 -99
  129. data/spec/lib/droplet_kit/resources/domain_resource_spec.rb +0 -65
  130. data/spec/lib/droplet_kit/resources/droplet_action_resource_spec.rb +0 -223
  131. data/spec/lib/droplet_kit/resources/droplet_resource_spec.rb +0 -340
  132. data/spec/lib/droplet_kit/resources/droplet_upgrade_resource_spec.rb +0 -22
  133. data/spec/lib/droplet_kit/resources/firewall_resource_spec.rb +0 -265
  134. data/spec/lib/droplet_kit/resources/floating_ip_action_resource_spec.rb +0 -137
  135. data/spec/lib/droplet_kit/resources/floating_ip_resource_spec.rb +0 -91
  136. data/spec/lib/droplet_kit/resources/image_action_resource_spec.rb +0 -149
  137. data/spec/lib/droplet_kit/resources/image_resource_spec.rb +0 -93
  138. data/spec/lib/droplet_kit/resources/kubernetes_cluster_resource_spec.rb +0 -313
  139. data/spec/lib/droplet_kit/resources/kubernetes_options_resource_spec.rb +0 -33
  140. data/spec/lib/droplet_kit/resources/load_balancer_resource_spec.rb +0 -213
  141. data/spec/lib/droplet_kit/resources/project_resource_spec.rb +0 -126
  142. data/spec/lib/droplet_kit/resources/region_resource_spec.rb +0 -27
  143. data/spec/lib/droplet_kit/resources/size_resource_spec.rb +0 -27
  144. data/spec/lib/droplet_kit/resources/snapshot_resource_spec.rb +0 -61
  145. data/spec/lib/droplet_kit/resources/ssh_key_resource_spec.rb +0 -92
  146. data/spec/lib/droplet_kit/resources/tag_resource_spec.rb +0 -135
  147. data/spec/lib/droplet_kit/resources/volume_action_resource_spec.rb +0 -157
  148. data/spec/lib/droplet_kit/resources/volume_resource_spec.rb +0 -124
  149. data/spec/spec_helper.rb +0 -19
  150. data/spec/support/fake_server.rb +0 -4
  151. data/spec/support/request_stub_helpers.rb +0 -28
  152. data/spec/support/resource_context.rb +0 -4
  153. data/spec/support/shared_examples/common_errors.rb +0 -27
  154. data/spec/support/shared_examples/paginated_endpoint.rb +0 -16
  155. data/spec/support/shared_examples/unprocessable_entity.rb +0 -11
@@ -1,34 +0,0 @@
1
- {
2
- "volume": {
3
- "id": "7724db7c-e098-11e5-b522-000f53304e51",
4
- "region": {
5
- "name": "New York 1",
6
- "slug": "nyc1",
7
- "sizes": [
8
- "512mb",
9
- "1gb",
10
- "2gb",
11
- "4gb",
12
- "8gb",
13
- "16gb",
14
- "32gb",
15
- "48gb",
16
- "64gb"
17
- ],
18
- "features": [
19
- "private_networking",
20
- "backups",
21
- "ipv6",
22
- "metadata"
23
- ],
24
- "available": true
25
- },
26
- "droplet_ids": [
27
-
28
- ],
29
- "name": "Example",
30
- "description": "Block store for examples",
31
- "size_gigabytes": 10,
32
- "created_at": "2016-03-02T17:00:49Z"
33
- }
34
- }
@@ -1,14 +0,0 @@
1
- {
2
- "snapshot": {
3
- "id": "7724db7c-e098-11e5-b522-000f53304e51",
4
- "name": "Ubuntu Foo",
5
- "regions": [
6
- "nyc1"
7
- ],
8
- "created_at": "2014-07-29T14:35:40Z",
9
- "resource_type": "volume",
10
- "resource_id": "7724db7c-e098-11e5-b522-000f53304e51",
11
- "min_disk_size": 10,
12
- "size_gigabytes": 0.4
13
- }
14
- }
@@ -1,34 +0,0 @@
1
- {
2
- "volume": {
3
- "id": "7724db7c-e098-11e5-b522-000f53304e51",
4
- "region": {
5
- "name": "New York 1",
6
- "slug": "nyc1",
7
- "sizes": [
8
- "512mb",
9
- "1gb",
10
- "2gb",
11
- "4gb",
12
- "8gb",
13
- "16gb",
14
- "32gb",
15
- "48gb",
16
- "64gb"
17
- ],
18
- "features": [
19
- "private_networking",
20
- "backups",
21
- "ipv6",
22
- "metadata"
23
- ],
24
- "available": true
25
- },
26
- "droplet_ids": [
27
-
28
- ],
29
- "name": "Example",
30
- "description": "Block store for examples",
31
- "size_gigabytes": 10,
32
- "created_at": "2016-03-02T17:00:49Z"
33
- }
34
- }
@@ -1,102 +0,0 @@
1
- require 'spec_helper'
2
-
3
- RSpec.describe DropletKit::Client do
4
- subject(:client) { DropletKit::Client.new(access_token: 'bunk') }
5
-
6
- describe '#initialize' do
7
- it 'initializes with an access token' do
8
- client = DropletKit::Client.new(access_token: 'my-token')
9
- expect(client.access_token).to eq('my-token')
10
- end
11
-
12
- it 'allows string option keys for the client' do
13
- client = DropletKit::Client.new('access_token' => 'my-token')
14
- expect(client.access_token).to eq('my-token')
15
- end
16
-
17
- it 'has default open_timeout for faraday' do
18
- client = DropletKit::Client.new('access_token' => 'my-token')
19
- expect(client.open_timeout).to eq(DropletKit::Client::DEFAULT_OPEN_TIMEOUT)
20
- end
21
-
22
- it 'allows open_timeout to be set' do
23
- open_timeout = 10
24
- client = DropletKit::Client.new(
25
- 'access_token' => 'my-token',
26
- 'open_timeout' => open_timeout
27
- )
28
-
29
- expect(client.open_timeout).to eq(open_timeout)
30
- end
31
-
32
- it 'has default timeout' do
33
- client = DropletKit::Client.new('access_token' => 'my-token')
34
- expect(client.timeout).to eq(DropletKit::Client::DEFAULT_TIMEOUT)
35
- end
36
-
37
- it 'allows timeout to be set' do
38
- timeout = 10
39
- client = DropletKit::Client.new(
40
- 'access_token' => 'my-token',
41
- 'timeout' => timeout
42
- )
43
-
44
- expect(client.timeout).to eq(timeout)
45
- end
46
- end
47
-
48
- describe "#method_missing" do
49
- context "called with an existing method" do
50
- it { expect{ client.actions}.to_not raise_error }
51
- end
52
-
53
- context "called with a missing method" do
54
- it { expect{client.this_is_wrong}.to raise_error(NoMethodError) }
55
- end
56
- end
57
-
58
- describe '#connection' do
59
- module AcmeApp
60
- class CustomLogger < Faraday::Middleware
61
- end
62
- end
63
-
64
- it 'populates the authorization header correctly' do
65
- expect(client.connection.headers['Authorization']).to eq("Bearer #{client.access_token}")
66
- end
67
-
68
- it 'sets the content type' do
69
- expect(client.connection.headers['Content-Type']).to eq("application/json")
70
- end
71
-
72
- context 'with default user agent' do
73
- it 'contains the version of DropletKit and Faraday' do
74
- stub_const('DropletKit::VERSION', '1.2.3')
75
- stub_const('Faraday::VERSION', '1.2.3')
76
- expect(client.connection.headers['User-Agent']).to eq('DropletKit/1.2.3 Faraday/1.2.3')
77
- end
78
- end
79
-
80
- context 'with user provided user agent' do
81
- it 'includes their agent string as well' do
82
- client = DropletKit::Client.new(access_token: 'bunk', user_agent: 'tugboat')
83
- expect(client.connection.headers['User-Agent']).to include('tugboat')
84
- end
85
- end
86
-
87
- it 'allows access to faraday instance' do
88
- client.connection.use AcmeApp::CustomLogger
89
- expect(client.connection.builder.handlers).to include(AcmeApp::CustomLogger)
90
- end
91
-
92
- it 'has open_timeout set' do
93
- expect(client.connection.options.open_timeout).to eq(DropletKit::Client::DEFAULT_OPEN_TIMEOUT)
94
- end
95
-
96
- it 'has timeout set' do
97
- expect(client.connection.options.timeout).to eq(DropletKit::Client::DEFAULT_TIMEOUT)
98
- end
99
- end
100
-
101
- end
102
-
@@ -1,21 +0,0 @@
1
- require 'spec_helper'
2
-
3
- RSpec.describe DropletKit::BaseModel do
4
- subject(:resource) do
5
- Class.new(DropletKit::BaseModel) do |base|
6
- attribute :droplet_limit
7
- def self.name
8
- 'SomeModel'
9
- end
10
- end
11
- end
12
-
13
- describe '#inspect' do
14
- it 'returns the information about the current user' do
15
- instance = resource.new(droplet_limit: 5)
16
- expect(instance.inspect).to include("<SomeModel")
17
- expect(instance.inspect).to include("@droplet_limit=>5")
18
- expect(instance.inspect).to include("<SomeModel {:@droplet_limit=>5}>")
19
- end
20
- end
21
- end
@@ -1,32 +0,0 @@
1
- require 'spec_helper'
2
-
3
- RSpec.describe DropletKit::Droplet do
4
- let(:droplet_fixture) { api_fixture('droplets/find') }
5
- let(:droplet) { DropletKit::DropletMapping.extract_single(droplet_fixture, :read) }
6
-
7
- describe '#public_ip' do
8
- it 'returns the public IP for ipv4' do
9
- expect(droplet.public_ip).to eq('127.0.0.19')
10
- end
11
-
12
- context 'when the droplet does not have an IP yet' do
13
- it 'returns nil' do
14
- droplet.networks.v4.clear
15
- expect(droplet.public_ip).to be_nil
16
- end
17
- end
18
- end
19
-
20
- describe '#private_ip' do
21
- it 'returns the public IP for ipv4' do
22
- expect(droplet.private_ip).to eq('10.0.0.19')
23
- end
24
-
25
- context 'when the droplet does not have private networking enabled' do
26
- it 'returns nil' do
27
- droplet.networks.v4.clear
28
- expect(droplet.private_ip).to be_nil
29
- end
30
- end
31
- end
32
- end
@@ -1,85 +0,0 @@
1
- require 'spec_helper'
2
-
3
- RequestCounter = Struct.new(:count)
4
-
5
- RSpec.describe DropletKit::PaginatedResource do
6
- let(:resource) { ResourceKit::Resource.new(connection: connection) }
7
- let(:request_count) { RequestCounter.new(0) }
8
-
9
- let(:connection) { Faraday.new {|b| b.adapter :test, stubs } }
10
- let(:response_size) { 40 }
11
- let(:stubs) { stub_pager_request(response_size) }
12
- let(:action) { ResourceKit::Action.new(:find, :get, '/droplets') }
13
-
14
- before do
15
- action.query_keys :per_page, :page
16
- action.handler(200) { |r| JSON.load(r.body)['objects'] }
17
- end
18
-
19
- describe '#initialize' do
20
- it 'initializes with a action and resource' do
21
- instance = DropletKit::PaginatedResource.new(action, resource)
22
- expect(instance.action).to be(action)
23
- expect(instance.resource).to be(resource)
24
- end
25
- end
26
-
27
- describe "#total_pages" do
28
- let(:instance) { DropletKit::PaginatedResource.new(action, resource) }
29
- it "returns nil if no request made" do
30
- expect(instance.total_pages).to be_nil
31
- end
32
-
33
- it "returns correct page count after request made" do
34
- instance.take(20)
35
- expect(instance.total_pages).to eq(2)
36
- end
37
-
38
- context "when results are empty" do
39
- let(:stubs) { stub_pager_request(0) }
40
- it "returns 0" do
41
- instance.take(1)
42
- expect(instance.total_pages).to eq(0)
43
- end
44
- end
45
- end
46
-
47
- describe '#[]' do
48
- subject(:paginated) { DropletKit::PaginatedResource.new(action, resource) }
49
-
50
- it 'returns the nth element in the collection' do
51
- paginated.each_with_index do |elem, i|
52
- expect(paginated[i]).to eq(elem)
53
- end
54
- end
55
- end
56
-
57
- describe '#each' do
58
- subject(:paginated) { DropletKit::PaginatedResource.new(action, resource) }
59
-
60
- it 'iterates over every object returned from the API' do
61
- total = 0
62
- paginated.each do |object|
63
- total += 1
64
- end
65
-
66
- expect(total).to eq(40)
67
- end
68
-
69
- it 'called the API twice' do
70
- expect {|b| paginated.each {|c| c } }.to change { request_count.count }.to(2).from(0)
71
- end
72
-
73
- it 'returns the correct objects' do
74
- expect(paginated.first(3)).to eq([0,1,2])
75
- end
76
-
77
- context 'for changing size' do
78
- subject(:paginated) { DropletKit::PaginatedResource.new(action, resource, per_page: 40) }
79
-
80
- it 'only calls the API once' do
81
- expect {|b| paginated.each {|c| c } }.to change { request_count.count }.to(1).from(0)
82
- end
83
- end
84
- end
85
- end
@@ -1,30 +0,0 @@
1
- require 'spec_helper'
2
-
3
- RSpec.describe DropletKit::AccountResource do
4
- subject(:resource) { described_class.new(connection: connection) }
5
- include_context 'resources'
6
-
7
- describe '#info' do
8
- it 'returns the information about the current user' do
9
- fixture = api_fixture('account/info')
10
- parsed = JSON.load(fixture)
11
-
12
- stub_do_api('/v2/account').to_return(body: fixture)
13
- account_info = resource.info
14
-
15
- expect(account_info).to be_kind_of(DropletKit::Account)
16
-
17
- expect(account_info.droplet_limit).to eq(parsed['account']['droplet_limit'])
18
- expect(account_info.floating_ip_limit).to eq(parsed['account']['floating_ip_limit'])
19
- expect(account_info.email).to eq(parsed['account']['email'])
20
- expect(account_info.uuid).to eq(parsed['account']['uuid'])
21
- expect(account_info.email_verified).to eq(parsed['account']['email_verified'])
22
- end
23
-
24
- it_behaves_like 'resource that handles common errors' do
25
- let(:path) { '/v2/account' }
26
- let(:method) { :get }
27
- let(:action) { :info }
28
- end
29
- end
30
- end
@@ -1,83 +0,0 @@
1
- require 'spec_helper'
2
-
3
- RSpec.describe DropletKit::ActionResource do
4
- subject(:resource) { described_class.new(connection: connection) }
5
- include_context 'resources'
6
-
7
- describe '#all' do
8
- it 'returns all actions' do
9
- response = api_fixture('actions/all')
10
- stub_do_api('/v2/actions', :get).to_return(body: response)
11
- expected_actions = DropletKit::ActionMapping.extract_collection(response, :read)
12
-
13
- expect(resource.all).to eq(expected_actions)
14
- end
15
-
16
- it 'returns a list of correctly mapped actions' do
17
- response = api_fixture('actions/all')
18
- stub_do_api('/v2/actions', :get).to_return(body: response)
19
- actions = resource.all
20
-
21
- expect(actions.first).to be_kind_of(DropletKit::Action)
22
- expect(actions.first.id).to eq(1)
23
- expect(actions.first.status).to eq("in-progress")
24
- expect(actions.first.type).to eq("test")
25
- expect(actions.first.started_at).to eq("2014-07-29T14:35:26Z")
26
- expect(actions.first.completed_at).to eq(nil)
27
- expect(actions.first.resource_id).to eq(nil)
28
- expect(actions.first.resource_type).to eq("backend")
29
-
30
- expect(actions.first.region).to be_kind_of(DropletKit::Region)
31
- expect(actions.first.region.slug).to eq('nyc1')
32
- expect(actions.first.region.name).to eq('New York')
33
- expect(actions.first.region.sizes).to include('512mb')
34
- expect(actions.first.region.available).to be(true)
35
- expect(actions.first.region.features).to include("virtio", "private_networking", "backups", "ipv6", "metadata")
36
- end
37
-
38
- it_behaves_like 'a paginated index' do
39
- let(:fixture_path) { 'actions/all' }
40
- let(:api_path) { '/v2/actions' }
41
- end
42
- end
43
-
44
- describe '#find' do
45
- it 'returns an action' do
46
- response = api_fixture('actions/find')
47
- stub_do_api('/v2/actions/123', :get).to_return(body: response)
48
- expected_action = DropletKit::ActionMapping.extract_single(response, :read)
49
-
50
- expect(resource.find(id: 123)).to eq(expected_action)
51
- end
52
-
53
- it 'returns a correctly mapped action' do
54
- response = api_fixture('actions/find')
55
- stub_do_api('/v2/actions/123', :get).to_return(body: response)
56
- action = resource.find(id: 123)
57
-
58
- expect(action).to be_kind_of(DropletKit::Action)
59
- expect(action.id).to eq(2)
60
- expect(action.status).to eq("in-progress")
61
- expect(action.type).to eq("test")
62
- expect(action.started_at).to eq("2014-07-29T14:35:27Z")
63
- expect(action.completed_at).to eq(nil)
64
- expect(action.resource_id).to eq(nil)
65
- expect(action.resource_type).to eq("backend")
66
- expect(action.region_slug).to eq("nyc1")
67
-
68
- expect(action.region).to be_kind_of(DropletKit::Region)
69
- expect(action.region.slug).to eq('nyc1')
70
- expect(action.region.name).to eq('New York')
71
- expect(action.region.sizes).to include('512mb')
72
- expect(action.region.available).to be(true)
73
- expect(action.region.features).to include("virtio", "private_networking", "backups", "ipv6", "metadata")
74
- end
75
-
76
- it_behaves_like 'resource that handles common errors' do
77
- let(:path) { '/v2/actions/123' }
78
- let(:method) { :get }
79
- let(:action) { :find }
80
- let(:arguments) { { id: 123 } }
81
- end
82
- end
83
- end
@@ -1,124 +0,0 @@
1
- require 'spec_helper'
2
-
3
- RSpec.describe DropletKit::CDNResource do
4
- subject(:resource) { described_class.new(connection: connection) }
5
- include_context 'resources'
6
-
7
- let(:id) { '7724db7c-e098-11e5-b522-000f53304e51' }
8
- let(:origin) { 'my-space-cdn.nyc3.digitaloceanspaces.com' }
9
- let(:endpoint) { 'my-space-cdn.nyc3.cdn.digitaloceanspaces.com' }
10
- let(:ttl) { 3600 }
11
- let(:created_at) { '2016-03-02T17:00:49Z' }
12
-
13
- let(:path) { '/v2/cdn/endpoints' }
14
- let(:path_with_id) { "#{path}/#{id}" }
15
-
16
- RSpec::Matchers.define :match_cdn_fixture do
17
- match do |cdn|
18
- expect(cdn).to be_kind_of(DropletKit::CDN)
19
-
20
- expect(cdn.id).to eq(id)
21
- expect(cdn.origin).to eq(origin)
22
- expect(cdn.endpoint).to eq(endpoint)
23
- expect(cdn.ttl).to eq(ttl)
24
- expect(cdn.created_at).to eq(created_at)
25
- end
26
- end
27
-
28
- describe '#all' do
29
- it 'returns all of the cdns' do
30
- stub_do_api(path, :get).to_return(body: api_fixture('cdns/all'))
31
- cdns = resource.all
32
-
33
- expect(cdns).to all(be_kind_of(DropletKit::CDN))
34
- expect(cdns.first).to match_cdn_fixture
35
- end
36
-
37
- it_behaves_like 'a paginated index' do
38
- let(:fixture_path) { 'cdns/all' }
39
- let(:api_path) { '/v2/cdn/endpoints' }
40
- end
41
- end
42
-
43
- describe '#find' do
44
- it 'returns a singular cdn' do
45
- stub_do_api(path_with_id, :get).to_return(body: api_fixture('cdns/find'))
46
- cdn = resource.find(id: id)
47
-
48
- expect(cdn).to match_cdn_fixture
49
- end
50
- end
51
-
52
- describe '#create' do
53
- it 'returns the created cdn' do
54
- cdn = DropletKit::CDN.new(
55
- origin: origin,
56
- ttl: ttl
57
- )
58
-
59
- as_string = DropletKit::CDNMapping.representation_for(:create, cdn)
60
- stub_do_api(path, :post).with(body: as_string).to_return(body: api_fixture('cdns/create'), status: 201)
61
- created_cdn = resource.create(cdn)
62
-
63
- expect(created_cdn).to match_cdn_fixture
64
- end
65
-
66
- it_behaves_like 'an action that handles invalid parameters' do
67
- let(:action) { 'create' }
68
- let(:arguments) { DropletKit::CDN.new }
69
- end
70
- end
71
-
72
- describe '#update_ttl' do
73
- let(:exception) { DropletKit::FailedUpdate }
74
-
75
- it 'returns the updated cdn' do
76
- as_string = { ttl: 60 }.to_json
77
- stub_do_api(path_with_id, :put).with(body: as_string).to_return(body: api_fixture('cdns/update_ttl'))
78
- updated_cdn = resource.update_ttl(id: id, ttl: 60)
79
-
80
- expect(updated_cdn).to be_kind_of(DropletKit::CDN)
81
-
82
- expect(updated_cdn.id).to eq(id)
83
- expect(updated_cdn.ttl).to eq(60)
84
- end
85
-
86
- it "fails if ttl is invalid" do
87
- as_string = { ttl: 0 }.to_json
88
- response_body = { id: :unprocessable_entity, message: 'invalid ttl' }
89
- stub_do_api(path_with_id, :put).with(body: as_string).to_return(body: response_body.to_json, status: 422)
90
-
91
- expect { resource.update_ttl(id: id, ttl: 0) }.to raise_exception(exception).with_message(response_body[:message])
92
- end
93
- end
94
-
95
- describe '#flush_cache' do
96
- let(:cache_path) { "/v2/cdn/endpoints/#{id}/cache" }
97
- let(:exception) { DropletKit::FailedUpdate }
98
-
99
- it 'sends a delete request to cdn cache' do
100
- as_string = { files: ["*"] }.to_json
101
- request = stub_do_api(cache_path, :delete).with(body: as_string)
102
- resource.flush_cache(id: id, files: ["*"])
103
-
104
- expect(request).to have_been_made
105
- end
106
-
107
- it "fails if files are not passed in" do
108
- as_string = { files: [] }.to_json
109
- response_body = { id: :unprocessable_entity, message: 'invalid request body' }
110
- stub_do_api(cache_path, :delete).with(body: as_string).to_return(body: response_body.to_json, status: 422)
111
-
112
- expect { resource.flush_cache(id: id, files: []) }.to raise_exception(exception).with_message(response_body[:message])
113
- end
114
- end
115
-
116
- describe '#delete' do
117
- it 'sends a delete request for the cdn' do
118
- request = stub_do_api(path_with_id, :delete)
119
- resource.delete(id: id)
120
-
121
- expect(request).to have_been_made
122
- end
123
- end
124
- end