vultr 0.4.3 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (241) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/ci.yml +38 -0
  3. data/.standard.yml +1 -0
  4. data/Appraisals +8 -0
  5. data/CHANGELOG.md +9 -0
  6. data/Gemfile +6 -10
  7. data/README.md +307 -137
  8. data/Rakefile +10 -6
  9. data/bin/console +21 -0
  10. data/bin/setup +8 -0
  11. data/bin/test +6 -0
  12. data/gemfiles/faraday_1.gemfile +12 -0
  13. data/gemfiles/faraday_1.gemfile.lock +102 -0
  14. data/gemfiles/faraday_2.gemfile +11 -0
  15. data/gemfiles/faraday_2.gemfile.lock +82 -0
  16. data/lib/vultr/client.rb +111 -0
  17. data/lib/vultr/collection.rb +22 -0
  18. data/lib/vultr/error.rb +4 -0
  19. data/lib/vultr/middleware.rb +32 -0
  20. data/lib/vultr/object.rb +19 -0
  21. data/lib/vultr/objects/account.rb +4 -0
  22. data/lib/vultr/objects/application.rb +4 -0
  23. data/lib/vultr/objects/backup.rb +4 -0
  24. data/lib/vultr/objects/bare_metal.rb +4 -0
  25. data/lib/vultr/objects/block_storage.rb +4 -0
  26. data/lib/vultr/objects/domain.rb +4 -0
  27. data/lib/vultr/objects/firewall_group.rb +4 -0
  28. data/lib/vultr/objects/instance.rb +4 -0
  29. data/lib/vultr/objects/iso.rb +4 -0
  30. data/lib/vultr/objects/kubernetes_cluster.rb +4 -0
  31. data/lib/vultr/objects/load_balancer.rb +4 -0
  32. data/lib/vultr/objects/object_storage.rb +4 -0
  33. data/lib/vultr/objects/operating_system.rb +4 -0
  34. data/lib/vultr/objects/plan.rb +4 -0
  35. data/lib/vultr/objects/private_network.rb +4 -0
  36. data/lib/vultr/objects/region.rb +4 -0
  37. data/lib/vultr/objects/reserved_ip.rb +4 -0
  38. data/lib/vultr/objects/snapshot.rb +4 -0
  39. data/lib/vultr/objects/ssh_key.rb +4 -0
  40. data/lib/vultr/objects/startup_script.rb +4 -0
  41. data/lib/vultr/objects/user.rb +4 -0
  42. data/lib/vultr/resource.rb +52 -0
  43. data/lib/vultr/resources/account.rb +7 -0
  44. data/lib/vultr/resources/applications.rb +8 -0
  45. data/lib/vultr/resources/backups.rb +12 -0
  46. data/lib/vultr/resources/bare_metal.rb +79 -0
  47. data/lib/vultr/resources/block_storage.rb +32 -0
  48. data/lib/vultr/resources/dns.rb +58 -0
  49. data/lib/vultr/resources/firewall.rb +42 -0
  50. data/lib/vultr/resources/instances.rb +145 -0
  51. data/lib/vultr/resources/iso.rb +25 -0
  52. data/lib/vultr/resources/kubernetes.rb +61 -0
  53. data/lib/vultr/resources/load_balancers.rb +50 -0
  54. data/lib/vultr/resources/object_storage.rb +33 -0
  55. data/lib/vultr/resources/operating_systems.rb +8 -0
  56. data/lib/vultr/resources/plans.rb +13 -0
  57. data/lib/vultr/resources/private_networks.rb +24 -0
  58. data/lib/vultr/resources/regions.rb +12 -0
  59. data/lib/vultr/resources/reserved_ips.rb +32 -0
  60. data/lib/vultr/resources/snapshots.rb +28 -0
  61. data/lib/vultr/resources/ssh_keys.rb +24 -0
  62. data/lib/vultr/resources/startup_scripts.rb +24 -0
  63. data/lib/vultr/resources/users.rb +24 -0
  64. data/lib/vultr/version.rb +1 -8
  65. data/lib/vultr.rb +58 -887
  66. data/test/fixtures/account/info.json +11 -0
  67. data/test/fixtures/applications/list.json +29 -0
  68. data/test/fixtures/backups/list.json +18 -0
  69. data/test/fixtures/backups/retrieve.json +9 -0
  70. data/test/fixtures/bare_metals/bandwidth.json +12 -0
  71. data/test/fixtures/bare_metals/create.json +26 -0
  72. data/test/fixtures/bare_metals/list.json +36 -0
  73. data/test/fixtures/bare_metals/list_ipv4.json +18 -0
  74. data/test/fixtures/bare_metals/list_ipv6.json +17 -0
  75. data/test/fixtures/bare_metals/reinstall.json +25 -0
  76. data/test/fixtures/bare_metals/retrieve.json +26 -0
  77. data/test/fixtures/bare_metals/update.json +26 -0
  78. data/test/fixtures/bare_metals/upgrades.json +47 -0
  79. data/test/fixtures/bare_metals/user_data.json +5 -0
  80. data/test/fixtures/bare_metals/vnc.json +5 -0
  81. data/test/fixtures/block_storage/attach.json +4 -0
  82. data/test/fixtures/block_storage/create.json +13 -0
  83. data/test/fixtures/block_storage/detach.json +4 -0
  84. data/test/fixtures/block_storage/list.json +22 -0
  85. data/test/fixtures/block_storage/retrieve.json +13 -0
  86. data/test/fixtures/domains/create.json +6 -0
  87. data/test/fixtures/domains/dnssec.json +7 -0
  88. data/test/fixtures/domains/list.json +15 -0
  89. data/test/fixtures/domains/record.json +10 -0
  90. data/test/fixtures/domains/records.json +19 -0
  91. data/test/fixtures/domains/retrieve.json +6 -0
  92. data/test/fixtures/domains/soa.json +6 -0
  93. data/test/fixtures/firewall/create.json +11 -0
  94. data/test/fixtures/firewall/create_rule.json +9 -0
  95. data/test/fixtures/firewall/delete.json +1 -0
  96. data/test/fixtures/firewall/delete_rule.json +1 -0
  97. data/test/fixtures/firewall/list.json +20 -0
  98. data/test/fixtures/firewall/list_rules.json +22 -0
  99. data/test/fixtures/firewall/retrieve.json +11 -0
  100. data/test/fixtures/firewall/retrieve_rule.json +13 -0
  101. data/test/fixtures/firewall/update.json +1 -0
  102. data/test/fixtures/instances/attach_iso.json +6 -0
  103. data/test/fixtures/instances/attach_private_network.json +1 -0
  104. data/test/fixtures/instances/backup_schedule.json +10 -0
  105. data/test/fixtures/instances/bandwidth.json +12 -0
  106. data/test/fixtures/instances/create.json +36 -0
  107. data/test/fixtures/instances/create_ipv4_reverse.json +1 -0
  108. data/test/fixtures/instances/create_ipv6_reverse.json +1 -0
  109. data/test/fixtures/instances/delete.json +1 -0
  110. data/test/fixtures/instances/delete_ipv4.json +1 -0
  111. data/test/fixtures/instances/delete_ipv6.json +1 -0
  112. data/test/fixtures/instances/detach_iso.json +5 -0
  113. data/test/fixtures/instances/detach_private_network.json +1 -0
  114. data/test/fixtures/instances/halt.json +1 -0
  115. data/test/fixtures/instances/halt_instances.json +1 -0
  116. data/test/fixtures/instances/ipv4.json +9 -0
  117. data/test/fixtures/instances/ipv6_reverse.json +15 -0
  118. data/test/fixtures/instances/iso.json +6 -0
  119. data/test/fixtures/instances/list.json +44 -0
  120. data/test/fixtures/instances/list_ipv4.json +32 -0
  121. data/test/fixtures/instances/list_ipv6.json +17 -0
  122. data/test/fixtures/instances/list_private_networks.json +16 -0
  123. data/test/fixtures/instances/neighbors.json +6 -0
  124. data/test/fixtures/instances/reboot.json +1 -0
  125. data/test/fixtures/instances/reboot_instances.json +1 -0
  126. data/test/fixtures/instances/reinstall.json +35 -0
  127. data/test/fixtures/instances/restore.json +7 -0
  128. data/test/fixtures/instances/retrieve.json +35 -0
  129. data/test/fixtures/instances/set_backup_schedule.json +1 -0
  130. data/test/fixtures/instances/set_default_reverse_dns_entry.json +1 -0
  131. data/test/fixtures/instances/start.json +1 -0
  132. data/test/fixtures/instances/start_instances.json +1 -0
  133. data/test/fixtures/instances/update.json +1 -0
  134. data/test/fixtures/instances/upgrades.json +55 -0
  135. data/test/fixtures/instances/user_data.json +5 -0
  136. data/test/fixtures/isos/create.json +8 -0
  137. data/test/fixtures/isos/list.json +20 -0
  138. data/test/fixtures/isos/list_public.json +17 -0
  139. data/test/fixtures/isos/retrieve.json +11 -0
  140. data/test/fixtures/kubernetes/config.json +3 -0
  141. data/test/fixtures/kubernetes/create.json +39 -0
  142. data/test/fixtures/kubernetes/create_node_pool.json +25 -0
  143. data/test/fixtures/kubernetes/list.json +85 -0
  144. data/test/fixtures/kubernetes/list_node_pools.json +56 -0
  145. data/test/fixtures/kubernetes/list_resources.json +26 -0
  146. data/test/fixtures/kubernetes/retrieve.json +39 -0
  147. data/test/fixtures/kubernetes/retrieve_node_pool.json +25 -0
  148. data/test/fixtures/kubernetes/update_node_pool.json +19 -0
  149. data/test/fixtures/load_balancers/create.json +48 -0
  150. data/test/fixtures/load_balancers/create_forwarding_rule.json +1 -0
  151. data/test/fixtures/load_balancers/delete.json +1 -0
  152. data/test/fixtures/load_balancers/delete_forwarding_rule.json +1 -0
  153. data/test/fixtures/load_balancers/list.json +57 -0
  154. data/test/fixtures/load_balancers/list_firewall_rules.json +17 -0
  155. data/test/fixtures/load_balancers/list_forwarding_rules.json +18 -0
  156. data/test/fixtures/load_balancers/retrieve.json +48 -0
  157. data/test/fixtures/load_balancers/retrieve_firewall_rule.json +8 -0
  158. data/test/fixtures/load_balancers/retrieve_forwarding_rule.json +9 -0
  159. data/test/fixtures/load_balancers/update.json +1 -0
  160. data/test/fixtures/object_storage/create.json +14 -0
  161. data/test/fixtures/object_storage/delete.json +1 -0
  162. data/test/fixtures/object_storage/list.json +22 -0
  163. data/test/fixtures/object_storage/list_clusters.json +17 -0
  164. data/test/fixtures/object_storage/regenerate_keys.json +7 -0
  165. data/test/fixtures/object_storage/retrieve.json +13 -0
  166. data/test/fixtures/object_storage/update.json +1 -0
  167. data/test/fixtures/operating_systems/list.json +17 -0
  168. data/test/fixtures/plans/list.json +22 -0
  169. data/test/fixtures/plans/list_metal.json +24 -0
  170. data/test/fixtures/private_networks/create.json +10 -0
  171. data/test/fixtures/private_networks/delete.json +1 -0
  172. data/test/fixtures/private_networks/list.json +19 -0
  173. data/test/fixtures/private_networks/retrieve.json +10 -0
  174. data/test/fixtures/private_networks/update.json +1 -0
  175. data/test/fixtures/regions/list.json +20 -0
  176. data/test/fixtures/regions/list_availability.json +24 -0
  177. data/test/fixtures/reserved_ips/attach.json +1 -0
  178. data/test/fixtures/reserved_ips/convert.json +11 -0
  179. data/test/fixtures/reserved_ips/create.json +11 -0
  180. data/test/fixtures/reserved_ips/delete.json +1 -0
  181. data/test/fixtures/reserved_ips/detach.json +1 -0
  182. data/test/fixtures/reserved_ips/list.json +29 -0
  183. data/test/fixtures/reserved_ips/retrieve.json +11 -0
  184. data/test/fixtures/snapshots/create.json +11 -0
  185. data/test/fixtures/snapshots/create_from_url.json +11 -0
  186. data/test/fixtures/snapshots/delete.json +1 -0
  187. data/test/fixtures/snapshots/list.json +20 -0
  188. data/test/fixtures/snapshots/retrieve.json +11 -0
  189. data/test/fixtures/snapshots/update.json +1 -0
  190. data/test/fixtures/ssh_keys/create.json +8 -0
  191. data/test/fixtures/ssh_keys/delete.json +1 -0
  192. data/test/fixtures/ssh_keys/list.json +17 -0
  193. data/test/fixtures/ssh_keys/retrieve.json +8 -0
  194. data/test/fixtures/ssh_keys/update.json +1 -0
  195. data/test/fixtures/startup_scripts/create.json +10 -0
  196. data/test/fixtures/startup_scripts/delete.json +1 -0
  197. data/test/fixtures/startup_scripts/list.json +18 -0
  198. data/test/fixtures/startup_scripts/retrieve.json +10 -0
  199. data/test/fixtures/startup_scripts/update.json +1 -0
  200. data/test/fixtures/users/create.json +9 -0
  201. data/test/fixtures/users/delete.json +1 -0
  202. data/test/fixtures/users/list.json +29 -0
  203. data/test/fixtures/users/retrieve.json +20 -0
  204. data/test/fixtures/users/update.json +1 -0
  205. data/test/test_helper.rb +18 -5
  206. data/test/vultr/client_test.rb +8 -0
  207. data/test/vultr/object_test.rb +21 -0
  208. data/test/vultr/resources/account_test.rb +12 -0
  209. data/test/vultr/resources/applications_test.rb +15 -0
  210. data/test/vultr/resources/backups_test.rb +24 -0
  211. data/test/vultr/resources/bare_metal_test.rb +267 -0
  212. data/test/vultr/resources/block_storage_test.rb +85 -0
  213. data/test/vultr/resources/dns_test.rb +134 -0
  214. data/test/vultr/resources/firewall_test.rb +88 -0
  215. data/test/vultr/resources/instances_test.rb +325 -0
  216. data/test/vultr/resources/iso_test.rb +58 -0
  217. data/test/vultr/resources/kubernetes_test.rb +185 -0
  218. data/test/vultr/resources/load_balancers_test.rb +110 -0
  219. data/test/vultr/resources/object_storage_test.rb +71 -0
  220. data/test/vultr/resources/operating_systems_test.rb +15 -0
  221. data/test/vultr/resources/plans_test.rb +25 -0
  222. data/test/vultr/resources/private_networks_test.rb +50 -0
  223. data/test/vultr/resources/regions_test.rb +26 -0
  224. data/test/vultr/resources/reserved_ips_test.rb +67 -0
  225. data/test/vultr/resources/snapshots_test.rb +60 -0
  226. data/test/vultr/resources/ssh_keys_test.rb +50 -0
  227. data/test/vultr/resources/startup_scripts_test.rb +50 -0
  228. data/test/vultr/resources/users_test.rb +50 -0
  229. data/vultr.gemspec +15 -17
  230. metadata +237 -54
  231. data/.travis.yml +0 -26
  232. data/test/vultr/vultr_account_test.rb +0 -29
  233. data/test/vultr/vultr_app_test.rb +0 -26
  234. data/test/vultr/vultr_backup_test.rb +0 -22
  235. data/test/vultr/vultr_iso_test.rb +0 -27
  236. data/test/vultr/vultr_os_test.rb +0 -21
  237. data/test/vultr/vultr_plan_test.rb +0 -22
  238. data/test/vultr/vultr_region_test.rb +0 -33
  239. data/test/vultr/vultr_snapshot_test.rb +0 -30
  240. data/test/vultr/vultr_sshkey_test.rb +0 -50
  241. data/test/vultr/vultr_startupscript_test.rb +0 -53
@@ -0,0 +1,85 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "test_helper"
4
+
5
+ class BlockStorageResourceTest < Minitest::Test
6
+ def test_list
7
+ stub = stub_request("blocks", response: stub_response(fixture: "block_storage/list"))
8
+ client = Vultr::Client.new(api_key: "fake", adapter: :test, stubs: stub)
9
+ blocks = client.block_storage.list
10
+
11
+ assert_equal Vultr::Collection, blocks.class
12
+ assert_equal Vultr::BlockStorage, blocks.data.first.class
13
+ assert_equal 1, blocks.total
14
+ assert_equal "next", blocks.next_cursor
15
+ assert_equal "prev", blocks.prev_cursor
16
+ end
17
+
18
+ def test_create
19
+ body = {region: "ewr", size_gb: 50, label: "Example Block Storage"}
20
+ stub = stub_request("blocks", method: :post, body: body, response: stub_response(fixture: "block_storage/create", status: 202))
21
+ client = Vultr::Client.new(api_key: "fake", adapter: :test, stubs: stub)
22
+ blocks = client.block_storage.create(**body)
23
+
24
+ assert_equal blocks.id, "cb676a46-66fd-4dfb-b839-443f2e6c0b60"
25
+ assert_equal blocks.date_created, Time.parse("2020-10-10T01:56:20+00:00")
26
+ assert_equal blocks.cost, 5
27
+ assert_equal blocks.status, "active"
28
+ assert_equal blocks.size_gb, 50
29
+ assert_equal blocks.region, "ewr"
30
+ assert_equal blocks.attached_to_instance, "742c9913-d088-4d67-bc61-5a10e922fbd1"
31
+ assert_equal blocks.label, "Example Block Storage"
32
+ assert_equal blocks.mount_id, "ewr-example112233"
33
+ end
34
+
35
+ def test_retrieve
36
+ block_id = "cb676a46-66fd-4dfb-b839-443f2e6c0b60"
37
+ body = {region: "ewr", size_gb: 50, label: "Example Block Storage"}
38
+ stub = stub_request("blocks/#{block_id}", body: body, response: stub_response(fixture: "block_storage/retrieve"))
39
+ client = Vultr::Client.new(api_key: "fake", adapter: :test, stubs: stub)
40
+ blocks = client.block_storage.retrieve(block_id: block_id)
41
+
42
+ assert_equal blocks.id, "cb676a46-66fd-4dfb-b839-443f2e6c0b60"
43
+ assert_equal blocks.date_created, Time.parse("2020-10-10T01:56:20+00:00")
44
+ assert_equal blocks.cost, 5
45
+ assert_equal blocks.status, "active"
46
+ assert_equal blocks.size_gb, 50
47
+ assert_equal blocks.region, "ewr"
48
+ assert_equal blocks.attached_to_instance, "742c9913-d088-4d67-bc61-5a10e922fbd1"
49
+ assert_equal blocks.label, "Example Block Storage"
50
+ assert_equal blocks.mount_id, "ewr-example112233"
51
+ end
52
+
53
+ def test_update
54
+ block_id = "cb676a46-66fd-4dfb-b839-443f2e6c0b60"
55
+ body = {size_gb: 50, label: "Example Block Storage"}
56
+ stub = stub_request("blocks/#{block_id}", method: :patch, body: body, response: {})
57
+ client = Vultr::Client.new(api_key: "fake", adapter: :test, stubs: stub)
58
+
59
+ assert client.block_storage.update(block_id: block_id, **body)
60
+ end
61
+
62
+ def test_delete
63
+ block_id = "cb676a46-66fd-4dfb-b839-443f2e6c0b60"
64
+ stub = stub_request("blocks/#{block_id}", method: :delete, response: {})
65
+ client = Vultr::Client.new(api_key: "fake", adapter: :test, stubs: stub)
66
+
67
+ assert client.block_storage.delete(block_id: block_id)
68
+ end
69
+
70
+ def test_attach
71
+ block_id = "cb676a46-66fd-4dfb-b839-443f2e6c0b60"
72
+ stub = stub_request("blocks/#{block_id}/attach", method: :post, response: stub_response(fixture: "block_storage/attach"))
73
+ client = Vultr::Client.new(api_key: "fake", adapter: :test, stubs: stub)
74
+
75
+ assert client.block_storage.attach(block_id: block_id)
76
+ end
77
+
78
+ def test_detach
79
+ block_id = "cb676a46-66fd-4dfb-b839-443f2e6c0b60"
80
+ stub = stub_request("blocks/#{block_id}/detach", method: :post, response: stub_response(fixture: "block_storage/detach"))
81
+ client = Vultr::Client.new(api_key: "fake", adapter: :test, stubs: stub)
82
+
83
+ assert client.block_storage.detach(block_id: block_id)
84
+ end
85
+ end
@@ -0,0 +1,134 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "test_helper"
4
+
5
+ class DnsResourceTest < Minitest::Test
6
+ def test_list
7
+ stub = stub_request("domains", response: stub_response(fixture: "domains/list"))
8
+ client = Vultr::Client.new(api_key: "fake", adapter: :test, stubs: stub)
9
+ dns = client.dns.list
10
+
11
+ assert_equal Vultr::Collection, dns.class
12
+ assert_equal Vultr::Domain, dns.data.first.class
13
+ assert_equal 1, dns.total
14
+ assert_equal "next", dns.next_cursor
15
+ assert_equal "prev", dns.prev_cursor
16
+ end
17
+
18
+ def test_create
19
+ body = {domain: "example.com", ip: "192.0.2.123", dns_sec: :enabled}
20
+ stub = stub_request("domains", method: :post, body: body, response: stub_response(fixture: "domains/create", status: 201))
21
+ client = Vultr::Client.new(api_key: "fake", adapter: :test, stubs: stub)
22
+ dns = client.dns.create(**body)
23
+
24
+ assert_equal "example.com", dns.domain
25
+ assert_equal Time.parse("2020-10-10T01:56:20+00:00"), dns.date_created
26
+ end
27
+
28
+ def test_retrieve
29
+ dns_domain = "example.com"
30
+ stub = stub_request("domains/#{dns_domain}", response: stub_response(fixture: "domains/retrieve"))
31
+ client = Vultr::Client.new(api_key: "fake", adapter: :test, stubs: stub)
32
+ dns = client.dns.retrieve(dns_domain: dns_domain)
33
+
34
+ assert_equal "example.com", dns.domain
35
+ assert_equal Time.parse("2020-10-10T01:56:20+00:00"), dns.date_created
36
+ end
37
+
38
+ def test_update
39
+ dns_domain = "example.com"
40
+ body = {dns_sec: "enabled"}
41
+ stub = stub_request("domains/#{dns_domain}", method: :put, body: body, response: {})
42
+ client = Vultr::Client.new(api_key: "fake", adapter: :test, stubs: stub)
43
+
44
+ assert client.dns.update(dns_domain: dns_domain, **body)
45
+ end
46
+
47
+ def test_delete
48
+ dns_domain = "example.com"
49
+ stub = stub_request("domains/#{dns_domain}", method: :delete, response: {})
50
+ client = Vultr::Client.new(api_key: "fake", adapter: :test, stubs: stub)
51
+
52
+ assert client.dns.delete(dns_domain: dns_domain)
53
+ end
54
+
55
+ def test_soa
56
+ dns_domain = "example.com"
57
+ stub = stub_request("domains/#{dns_domain}/soa", response: stub_response(fixture: "domains/soa"))
58
+ client = Vultr::Client.new(api_key: "fake", adapter: :test, stubs: stub)
59
+ soa = client.dns.soa(dns_domain: dns_domain)
60
+
61
+ assert_equal "ns1.vultr.com", soa.nsprimary
62
+ assert_equal "admin@example.com", soa.email
63
+ end
64
+
65
+ def test_update_soa
66
+ dns_domain = "example.com"
67
+ body = {nsprimary: "ns1.vultr.com", email: "admin@example.com"}
68
+ stub = stub_request("domains/#{dns_domain}/soa", method: :patch, body: body, response: {})
69
+ client = Vultr::Client.new(api_key: "fake", adapter: :test, stubs: stub)
70
+
71
+ assert client.dns.update_soa(dns_domain: dns_domain, **body)
72
+ end
73
+
74
+ def test_dnssec
75
+ dns_domain = "example.com"
76
+ stub = stub_request("domains/#{dns_domain}/dnssec", response: stub_response(fixture: "domains/dnssec"))
77
+ client = Vultr::Client.new(api_key: "fake", adapter: :test, stubs: stub)
78
+ assert client.dns.dnssec(dns_domain: dns_domain)
79
+ end
80
+
81
+ def test_list_records
82
+ dns_domain = "example.com"
83
+ stub = stub_request("domains/#{dns_domain}/records", response: stub_response(fixture: "domains/records"))
84
+ client = Vultr::Client.new(api_key: "fake", adapter: :test, stubs: stub)
85
+ dns = client.dns.list_records(dns_domain: dns_domain)
86
+
87
+ assert_equal Vultr::Collection, dns.class
88
+ assert_equal Vultr::Object, dns.data.first.class
89
+ end
90
+
91
+ def test_create_record
92
+ dns_domain = "example.com"
93
+ body = {name: "www", type: "A", data: "192.0.2.123", ttl: 300, priority: 0}
94
+ stub = stub_request("domains/#{dns_domain}/records", method: :post, body: body, response: stub_response(fixture: "domains/record", status: 201))
95
+ client = Vultr::Client.new(api_key: "fake", adapter: :test, stubs: stub)
96
+ dns = client.dns.create_record(dns_domain: dns_domain, **body)
97
+
98
+ assert dns.id
99
+ assert "www", dns.name
100
+ assert "A", dns.type
101
+ assert "192.0.2.123", dns.data
102
+ assert 300, dns.ttl
103
+ assert 0, dns.priority
104
+ end
105
+
106
+ def test_retrieve_record
107
+ dns_domain = "example.com"
108
+ record_id = "cb676a46-66fd-4dfb-b839-443f2e6c0b60"
109
+ stub = stub_request("domains/#{dns_domain}/records/#{record_id}", response: stub_response(fixture: "domains/record"))
110
+ client = Vultr::Client.new(api_key: "fake", adapter: :test, stubs: stub)
111
+ dns = client.dns.retrieve_record(dns_domain: dns_domain, record_id: record_id)
112
+
113
+ assert_equal record_id, dns.id
114
+ end
115
+
116
+ def test_update_record
117
+ dns_domain = "example.com"
118
+ record_id = "cb676a46-66fd-4dfb-b839-443f2e6c0b60"
119
+ body = {name: "CNAME", data: "foo.example.com", ttl: 300, priority: 0}
120
+ stub = stub_request("domains/#{dns_domain}/records/#{record_id}", method: :patch, body: body, response: {})
121
+ client = Vultr::Client.new(api_key: "fake", adapter: :test, stubs: stub)
122
+
123
+ assert client.dns.update_record(dns_domain: dns_domain, record_id: record_id, **body)
124
+ end
125
+
126
+ def test_delete_record
127
+ dns_domain = "example.com"
128
+ record_id = "cb676a46-66fd-4dfb-b839-443f2e6c0b60"
129
+ stub = stub_request("domains/#{dns_domain}/records/#{record_id}", method: :delete, response: {})
130
+ client = Vultr::Client.new(api_key: "fake", adapter: :test, stubs: stub)
131
+
132
+ assert client.dns.delete_record(dns_domain: dns_domain, record_id: record_id)
133
+ end
134
+ end
@@ -0,0 +1,88 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "test_helper"
4
+
5
+ class FirewallResourceTest < Minitest::Test
6
+ def test_list
7
+ stub = stub_request("firewalls", response: stub_response(fixture: "firewall/list"))
8
+ client = Vultr::Client.new(api_key: "fake", adapter: :test, stubs: stub)
9
+ firewall_group = client.firewall.list
10
+
11
+ assert_equal Vultr::Collection, firewall_group.class
12
+ assert_equal Vultr::FirewallGroup, firewall_group.data.first.class
13
+ assert_equal 1, firewall_group.total
14
+ end
15
+
16
+ def test_create
17
+ body = {description: "Example Firewall Group"}
18
+ stub = stub_request("firewalls", method: :post, body: body, response: stub_response(fixture: "firewall/create"))
19
+ client = Vultr::Client.new(api_key: "fake", adapter: :test, stubs: stub)
20
+ firewall_group = client.firewall.create(**body)
21
+
22
+ assert_equal Vultr::FirewallGroup, firewall_group.class
23
+ assert_equal "Example Firewall Group", firewall_group.description
24
+ end
25
+
26
+ def test_retrieve
27
+ id = "cb676a46-66fd-4dfb-b839-443f2e6c0b60"
28
+ stub = stub_request("firewalls/#{id}", response: stub_response(fixture: "firewall/retrieve"))
29
+ client = Vultr::Client.new(api_key: "fake", adapter: :test, stubs: stub)
30
+ firewall_group = client.firewall.retrieve(firewall_group_id: id)
31
+
32
+ assert_equal Vultr::FirewallGroup, firewall_group.class
33
+ assert_equal "Example Firewall Group", firewall_group.description
34
+ end
35
+
36
+ def test_update
37
+ id = "cb676a46-66fd-4dfb-b839-443f2e6c0b60"
38
+ body = {description: "Example Firewall Group"}
39
+ stub = stub_request("firewalls/#{id}", method: :put, body: body, response: stub_response(fixture: "firewall/update"))
40
+ client = Vultr::Client.new(api_key: "fake", adapter: :test, stubs: stub)
41
+ assert client.firewall.update(firewall_group_id: id, **body)
42
+ end
43
+
44
+ def test_delete
45
+ id = "cb676a46-66fd-4dfb-b839-443f2e6c0b60"
46
+ stub = stub_request("firewalls/#{id}", method: :delete, response: stub_response(fixture: "firewall/delete"))
47
+ client = Vultr::Client.new(api_key: "fake", adapter: :test, stubs: stub)
48
+ assert client.firewall.delete(firewall_group_id: id)
49
+ end
50
+
51
+ def test_list_rules
52
+ id = "cb676a46-66fd-4dfb-b839-443f2e6c0b60"
53
+ stub = stub_request("firewalls/#{id}/rules", response: stub_response(fixture: "firewall/list_rules"))
54
+ client = Vultr::Client.new(api_key: "fake", adapter: :test, stubs: stub)
55
+ rules = client.firewall.list_rules(firewall_group_id: id)
56
+
57
+ assert Vultr::Collection, rules.class
58
+ assert Vultr::Object, rules.data.first.class
59
+ assert 1, rules.total
60
+ end
61
+
62
+ def test_create_rule
63
+ id = "cb676a46-66fd-4dfb-b839-443f2e6c0b60"
64
+ body = {ip_type: "v4", protocol: "tcp", subnet: "192.0.2.0", subnet_size: 24}
65
+ stub = stub_request("firewalls/#{id}/rules", method: :post, body: body, response: stub_response(fixture: "firewall/create_rule"))
66
+ client = Vultr::Client.new(api_key: "fake", adapter: :test, stubs: stub)
67
+ assert client.firewall.create_rule(firewall_group_id: id, **body)
68
+ end
69
+
70
+ def test_retrieve_rule
71
+ firewall_id = "id"
72
+ rule_id = "cb676a46-66fd-4dfb-b839-443f2e6c0b60"
73
+ stub = stub_request("firewalls/#{firewall_id}/rules/#{rule_id}", response: stub_response(fixture: "firewall/retrieve_rule"))
74
+ client = Vultr::Client.new(api_key: "fake", adapter: :test, stubs: stub)
75
+ rule = client.firewall.retrieve_rule(firewall_group_id: firewall_id, firewall_rule_id: rule_id)
76
+
77
+ assert Vultr::Object, rule.class
78
+ assert "tcp", rule.protocol
79
+ end
80
+
81
+ def test_delete_forwarding_rule
82
+ firewall_id = "id"
83
+ rule_id = "cb676a46-66fd-4dfb-b839-443f2e6c0b60"
84
+ stub = stub_request("firewalls/#{firewall_id}/rules/#{rule_id}", method: :delete, response: stub_response(fixture: "firewall/delete_rule"))
85
+ client = Vultr::Client.new(api_key: "fake", adapter: :test, stubs: stub)
86
+ assert client.firewall.delete_rule(firewall_group_id: firewall_id, firewall_rule_id: rule_id)
87
+ end
88
+ end
@@ -0,0 +1,325 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "test_helper"
4
+
5
+ class InstancesResourceTest < Minitest::Test
6
+ def test_list
7
+ stub = stub_request("instances", response: stub_response(fixture: "instances/list", status: 200))
8
+ client = Vultr::Client.new(api_key: "fake", adapter: :test, stubs: stub)
9
+ instances = client.instances.list
10
+
11
+ assert_equal Vultr::Collection, instances.class
12
+ assert_equal Vultr::Instance, instances.data.first.class
13
+ assert_equal 3, instances.total
14
+ end
15
+
16
+ def test_create
17
+ body = {region: "ewr", plan: "vc2-6c-16gb", label: "Example Instance", os_id: 215, user_data: "QmFzZTY0IEV4YW1wbGUgRGF0YQ==", backups: "enabled"}
18
+ stub = stub_request("instances", method: :post, body: body, response: stub_response(fixture: "instances/create", status: 202))
19
+ client = Vultr::Client.new(api_key: "fake", adapter: :test, stubs: stub)
20
+ instance = client.instances.create(**body)
21
+
22
+ assert_equal Vultr::Instance, instance.class
23
+ assert_equal "Example Instance", instance.label
24
+ end
25
+
26
+ def test_retrieve
27
+ instance_id = "cb676a46-66fd-4dfb-b839-443f2e6c0b60"
28
+ stub = stub_request("instances/#{instance_id}", response: stub_response(fixture: "instances/retrieve"))
29
+ client = Vultr::Client.new(api_key: "fake", adapter: :test, stubs: stub)
30
+ instance = client.instances.retrieve(instance_id: instance_id)
31
+
32
+ assert_equal Vultr::Instance, instance.class
33
+ assert_equal "Example Instance", instance.label
34
+ end
35
+
36
+ def test_update
37
+ instance_id = "cb676a46-66fd-4dfb-b839-443f2e6c0b60"
38
+ body = {label: "Example Instance", tag: "Example Tag", plan: "vc2-24c-97gb"}
39
+ stub = stub_request("instances/#{instance_id}", method: :patch, body: body, response: stub_response(fixture: "instances/update", status: 202))
40
+ client = Vultr::Client.new(api_key: "fake", adapter: :test, stubs: stub)
41
+ assert client.instances.update(instance_id: instance_id, **body)
42
+ end
43
+
44
+ def test_delete
45
+ instance_id = "cb676a46-66fd-4dfb-b839-443f2e6c0b60"
46
+ stub = stub_request("instances/#{instance_id}", method: :delete, response: stub_response(fixture: "instances/delete", status: 204))
47
+ client = Vultr::Client.new(api_key: "fake", adapter: :test, stubs: stub)
48
+ assert client.instances.delete(instance_id: instance_id)
49
+ end
50
+
51
+ def test_start
52
+ instance_id = "cb676a46-66fd-4dfb-b839-443f2e6c0b60"
53
+ stub = stub_request("instances/#{instance_id}/start", method: :post, response: stub_response(fixture: "instances/start", status: 204))
54
+ client = Vultr::Client.new(api_key: "fake", adapter: :test, stubs: stub)
55
+ assert client.instances.start(instance_id: instance_id)
56
+ end
57
+
58
+ def test_reboot
59
+ instance_id = "cb676a46-66fd-4dfb-b839-443f2e6c0b60"
60
+ stub = stub_request("instances/#{instance_id}/reboot", method: :post, response: stub_response(fixture: "instances/reboot", status: 204))
61
+ client = Vultr::Client.new(api_key: "fake", adapter: :test, stubs: stub)
62
+ assert client.instances.reboot(instance_id: instance_id)
63
+ end
64
+
65
+ def test_reinstall
66
+ body = {hostname: "Example Instance"}
67
+ instance_id = "cb676a46-66fd-4dfb-b839-443f2e6c0b60"
68
+ stub = stub_request("instances/#{instance_id}/reinstall", method: :post, body: body, response: stub_response(fixture: "instances/reinstall", status: 204))
69
+ client = Vultr::Client.new(api_key: "fake", adapter: :test, stubs: stub)
70
+ instance = client.instances.reinstall(instance_id: instance_id, **body)
71
+
72
+ assert_equal Vultr::Instance, instance.class
73
+ assert_equal "Example Instance", instance.label
74
+ end
75
+
76
+ def test_restore
77
+ body = {backup_id: "cb676a46-66fd-4dfb-b839-443f2e6c0b60"}
78
+ instance_id = "cb676a46-66fd-4dfb-b839-443f2e6c0b60"
79
+ stub = stub_request("instances/#{instance_id}/restore", method: :post, body: body, response: stub_response(fixture: "instances/restore", status: 202))
80
+ client = Vultr::Client.new(api_key: "fake", adapter: :test, stubs: stub)
81
+ instance = client.instances.restore(instance_id: instance_id, **body)
82
+
83
+ assert_equal Vultr::Object, instance.class
84
+ assert_equal "backup_id", instance.restore_type
85
+ end
86
+
87
+ def test_halt
88
+ instance_id = "cb676a46-66fd-4dfb-b839-443f2e6c0b60"
89
+ stub = stub_request("instances/#{instance_id}/halt", method: :post, response: stub_response(fixture: "instances/halt", status: 204))
90
+ client = Vultr::Client.new(api_key: "fake", adapter: :test, stubs: stub)
91
+ assert client.instances.halt(instance_id: instance_id)
92
+ end
93
+
94
+ def test_bandwidth
95
+ instance_id = "cb676a46-66fd-4dfb-b839-443f2e6c0b60"
96
+ stub = stub_request("instances/#{instance_id}/bandwidth", response: stub_response(fixture: "instances/bandwidth"))
97
+ client = Vultr::Client.new(api_key: "fake", adapter: :test, stubs: stub)
98
+ instance = client.instances.bandwidth(instance_id: instance_id)
99
+
100
+ assert_equal Vultr::Object, instance.class
101
+ end
102
+
103
+ def test_neighbors
104
+ instance_id = "cb676a46-66fd-4dfb-b839-443f2e6c0b60"
105
+ stub = stub_request("instances/#{instance_id}/neighbors", response: stub_response(fixture: "instances/neighbors"))
106
+ client = Vultr::Client.new(api_key: "fake", adapter: :test, stubs: stub)
107
+ instance = client.instances.neighbors(instance_id: instance_id)
108
+
109
+ assert_equal Array, instance.class
110
+ end
111
+
112
+ def test_user_data
113
+ instance_id = "cb676a46-66fd-4dfb-b839-443f2e6c0b60"
114
+ stub = stub_request("instances/#{instance_id}/user-data", response: stub_response(fixture: "instances/user_data"))
115
+ client = Vultr::Client.new(api_key: "fake", adapter: :test, stubs: stub)
116
+ instance = client.instances.user_data(instance_id: instance_id)
117
+
118
+ assert_equal Vultr::Object, instance.class
119
+ assert_equal "QmFzZTY0IEV4YW1wbGUgRGF0YQ==", instance.data
120
+ end
121
+
122
+ def test_upgrades
123
+ instance_id = "cb676a46-66fd-4dfb-b839-443f2e6c0b60"
124
+ stub = stub_request("instances/#{instance_id}/upgrades", response: stub_response(fixture: "instances/upgrades"))
125
+ client = Vultr::Client.new(api_key: "fake", adapter: :test, stubs: stub)
126
+ instance = client.instances.upgrades(instance_id: instance_id)
127
+
128
+ assert_equal Vultr::Object, instance.class
129
+ assert_equal "Example CentOS 6 x64", instance.os.first["name"]
130
+ end
131
+
132
+ def test_list_ipv4
133
+ instance_id = "cb676a46-66fd-4dfb-b839-443f2e6c0b60"
134
+ stub = stub_request("instances/#{instance_id}/ipv4", response: stub_response(fixture: "instances/list_ipv4"))
135
+ client = Vultr::Client.new(api_key: "fake", adapter: :test, stubs: stub)
136
+ instance = client.instances.list_ipv4(instance_id: instance_id)
137
+
138
+ assert_equal Vultr::Collection, instance.class
139
+ assert_equal 3, instance.total
140
+ end
141
+
142
+ def test_create_ipv4
143
+ body = {reboot: true}
144
+ instance_id = "cb676a46-66fd-4dfb-b839-443f2e6c0b60"
145
+ stub = stub_request("instances/#{instance_id}/ipv4", method: :post, body: body, response: stub_response(fixture: "instances/ipv4", status: 202))
146
+ client = Vultr::Client.new(api_key: "fake", adapter: :test, stubs: stub)
147
+ instance = client.instances.create_ipv4(instance_id: instance_id, **body)
148
+
149
+ assert_equal Vultr::Object, instance.class
150
+ end
151
+
152
+ def test_delete_ipv4
153
+ instance_id = "cb676a46-66fd-4dfb-b839-443f2e6c0b60"
154
+ ipv4_id = "192.0.2.123"
155
+ stub = stub_request("instances/#{instance_id}/ipv4/#{ipv4_id}", method: :delete, response: stub_response(fixture: "instances/delete_ipv4", status: 204))
156
+ client = Vultr::Client.new(api_key: "fake", adapter: :test, stubs: stub)
157
+ assert client.instances.delete_ipv4(instance_id: instance_id, ipv4: ipv4_id)
158
+ end
159
+
160
+ def test_create_ipv4_reverse
161
+ body = {ip: "192.0.2.123", reverse: "foo.example.com"}
162
+ instance_id = "cb676a46-66fd-4dfb-b839-443f2e6c0b60"
163
+ stub = stub_request("instances/#{instance_id}/ipv4/reverse", method: :post, body: body, response: stub_response(fixture: "instances/create_ipv4_reverse", status: 202))
164
+ client = Vultr::Client.new(api_key: "fake", adapter: :test, stubs: stub)
165
+ assert client.instances.create_ipv4_reverse(instance_id: instance_id, **body)
166
+ end
167
+
168
+ def test_set_default_reverse_dns_entry
169
+ body = {ip: "192.0.2.123"}
170
+ instance_id = "cb676a46-66fd-4dfb-b839-443f2e6c0b60"
171
+ stub = stub_request("instances/#{instance_id}/ipv4/reverse/default", method: :post, body: body, response: stub_response(fixture: "instances/set_default_reverse_dns_entry"))
172
+ client = Vultr::Client.new(api_key: "fake", adapter: :test, stubs: stub)
173
+ assert client.instances.set_default_reverse_dns_entry(instance_id: instance_id, **body)
174
+ end
175
+
176
+ def test_list_ipv6
177
+ instance_id = "cb676a46-66fd-4dfb-b839-443f2e6c0b60"
178
+ stub = stub_request("instances/#{instance_id}/ipv6", response: stub_response(fixture: "instances/list_ipv6"))
179
+ client = Vultr::Client.new(api_key: "fake", adapter: :test, stubs: stub)
180
+ instance = client.instances.list_ipv6(instance_id: instance_id)
181
+
182
+ assert_equal Vultr::Collection, instance.class
183
+ assert_equal 1, instance.total
184
+ end
185
+
186
+ def test_ipv6_reverse
187
+ instance_id = "cb676a46-66fd-4dfb-b839-443f2e6c0b60"
188
+ stub = stub_request("instances/#{instance_id}/ipv6/reverse", response: stub_response(fixture: "instances/ipv6_reverse"))
189
+ client = Vultr::Client.new(api_key: "fake", adapter: :test, stubs: stub)
190
+ instance = client.instances.ipv6_reverse(instance_id: instance_id)
191
+
192
+ assert_equal Vultr::Collection, instance.class
193
+ assert_equal 1, instance.total
194
+ end
195
+
196
+ def test_create_ipv6_reverse
197
+ body = {ip: "2001:0db8:0005:6bb0:5400:2ff0:fee5:0002", reverse: "foo.example.com"}
198
+ instance_id = "cb676a46-66fd-4dfb-b839-443f2e6c0b60"
199
+ stub = stub_request("instances/#{instance_id}/ipv6/reverse", method: :post, body: body, response: stub_response(fixture: "instances/create_ipv6_reverse", status: 202))
200
+ client = Vultr::Client.new(api_key: "fake", adapter: :test, stubs: stub)
201
+ assert client.instances.create_ipv6_reverse(instance_id: instance_id, **body)
202
+ end
203
+
204
+ def test_delete_ipv6_reverse
205
+ instance_id = "cb676a46-66fd-4dfb-b839-443f2e6c0b60"
206
+ ipv6_id = "2001:0db8:0005:6bb0:5400:2ff0:fee5:0002"
207
+ stub = stub_request("instances/#{instance_id}/ipv6/reverse/#{ipv6_id}", method: :delete, response: stub_response(fixture: "instances/delete_ipv6", status: 204))
208
+ client = Vultr::Client.new(api_key: "fake", adapter: :test, stubs: stub)
209
+ assert client.instances.delete_ipv6_reverse(instance_id: instance_id, ipv6: ipv6_id)
210
+ end
211
+
212
+ def test_list_private_networks
213
+ instance_id = "cb676a46-66fd-4dfb-b839-443f2e6c0b60"
214
+ stub = stub_request("instances/#{instance_id}/private-networks", response: stub_response(fixture: "instances/list_private_networks"))
215
+ client = Vultr::Client.new(api_key: "fake", adapter: :test, stubs: stub)
216
+ instance = client.instances.list_private_networks(instance_id: instance_id)
217
+
218
+ assert_equal Vultr::Collection, instance.class
219
+ assert_equal 1, instance.total
220
+ end
221
+
222
+ def test_attach_private_network
223
+ body = {network_id: "cb676a46-66fd-4dfb-b839-443f2e6c0b60"}
224
+ instance_id = "cb676a46-66fd-4dfb-b839-443f2e6c0b60"
225
+ stub = stub_request("instances/#{instance_id}/private-networks/attach", method: :post, body: body, response: stub_response(fixture: "instances/attach_private_network"))
226
+ client = Vultr::Client.new(api_key: "fake", adapter: :test, stubs: stub)
227
+ assert client.instances.attach_private_network(instance_id: instance_id, **body)
228
+ end
229
+
230
+ def test_detach_private_network
231
+ body = {network_id: "cb676a46-66fd-4dfb-b839-443f2e6c0b60"}
232
+ instance_id = "cb676a46-66fd-4dfb-b839-443f2e6c0b60"
233
+ stub = stub_request("instances/#{instance_id}/private-networks/detach", method: :post, body: body, response: stub_response(fixture: "instances/detach_private_network"))
234
+ client = Vultr::Client.new(api_key: "fake", adapter: :test, stubs: stub)
235
+ assert client.instances.detach_private_network(instance_id: instance_id, **body)
236
+ end
237
+
238
+ def test_iso
239
+ instance_id = "cb676a46-66fd-4dfb-b839-443f2e6c0b60"
240
+ stub = stub_request("instances/#{instance_id}/iso", response: stub_response(fixture: "instances/iso"))
241
+ client = Vultr::Client.new(api_key: "fake", adapter: :test, stubs: stub)
242
+ instance = client.instances.iso(instance_id: instance_id)
243
+
244
+ assert_equal Vultr::Object, instance.class
245
+ end
246
+
247
+ def test_attach_iso
248
+ body = {iso_id: "cb676a46-66fd-4dfb-b839-443f2e6c0b60"}
249
+ instance_id = "cb676a46-66fd-4dfb-b839-443f2e6c0b60"
250
+ stub = stub_request("instances/#{instance_id}/iso/attach", method: :post, body: body, response: stub_response(fixture: "instances/attach_iso", status: 204))
251
+ client = Vultr::Client.new(api_key: "fake", adapter: :test, stubs: stub)
252
+ instance = client.instances.attach_iso(instance_id: instance_id, iso_id: body[:iso_id])
253
+
254
+ assert_equal Vultr::Object, instance.class
255
+ end
256
+
257
+ def test_detach_iso
258
+ body = {iso_id: "cb676a46-66fd-4dfb-b839-443f2e6c0b60"}
259
+ instance_id = "cb676a46-66fd-4dfb-b839-443f2e6c0b60"
260
+ stub = stub_request("instances/#{instance_id}/iso/detach", method: :post, body: body, response: stub_response(fixture: "instances/detach_iso"))
261
+ client = Vultr::Client.new(api_key: "fake", adapter: :test, stubs: stub)
262
+ instance = client.instances.detach_iso(instance_id: instance_id, iso_id: body[:iso_id])
263
+
264
+ assert_equal Vultr::Object, instance.class
265
+ end
266
+
267
+ def test_backup_schedule
268
+ instance_id = "cb676a46-66fd-4dfb-b839-443f2e6c0b60"
269
+ stub = stub_request("instances/#{instance_id}/backup-schedule", response: stub_response(fixture: "instances/backup_schedule"))
270
+ client = Vultr::Client.new(api_key: "fake", adapter: :test, stubs: stub)
271
+ instance = client.instances.backup_schedule(instance_id: instance_id)
272
+
273
+ assert_equal Vultr::Object, instance.class
274
+ end
275
+
276
+ def test_set_backup_schedule
277
+ body = {type: "daily", hour: 10, dow: 1, dom: 1}
278
+ instance_id = "cb676a46-66fd-4dfb-b839-443f2e6c0b60"
279
+ stub = stub_request("instances/#{instance_id}/backup-schedule", method: :post, body: body, response: stub_response(fixture: "instances/set_backup_schedule"))
280
+ client = Vultr::Client.new(api_key: "fake", adapter: :test, stubs: stub)
281
+ assert client.instances.set_backup_schedule(instance_id: instance_id, **body)
282
+ end
283
+
284
+ def test_halt_instances
285
+ body = {
286
+ instance_ids: [
287
+ "cb676a46-66fd-4dfb-b839-443f2e6c0b60",
288
+ "1d651bd2-b93c-4bb6-8b91-0546fd765f15",
289
+ "c2790719-278d-474c-8dff-cb35d6e5503f"
290
+ ]
291
+ }
292
+
293
+ stub = stub_request("instances/halt", method: :post, body: body, response: stub_response(fixture: "instances/halt_instances"))
294
+ client = Vultr::Client.new(api_key: "fake", adapter: :test, stubs: stub)
295
+ assert client.instances.halt_instances(instance_ids: body[:instance_ids], **body)
296
+ end
297
+
298
+ def test_reboot_instances
299
+ body = {
300
+ instance_ids: [
301
+ "cb676a46-66fd-4dfb-b839-443f2e6c0b60",
302
+ "1d651bd2-b93c-4bb6-8b91-0546fd765f15",
303
+ "c2790719-278d-474c-8dff-cb35d6e5503f"
304
+ ]
305
+ }
306
+
307
+ stub = stub_request("instances/reboot", method: :post, body: body, response: stub_response(fixture: "instances/reboot_instances"))
308
+ client = Vultr::Client.new(api_key: "fake", adapter: :test, stubs: stub)
309
+ assert client.instances.reboot_instances(instance_ids: body[:instance_ids], **body)
310
+ end
311
+
312
+ def test_start_instances
313
+ body = {
314
+ instance_ids: [
315
+ "cb676a46-66fd-4dfb-b839-443f2e6c0b60",
316
+ "1d651bd2-b93c-4bb6-8b91-0546fd765f15",
317
+ "c2790719-278d-474c-8dff-cb35d6e5503f"
318
+ ]
319
+ }
320
+
321
+ stub = stub_request("instances/start", method: :post, body: body, response: stub_response(fixture: "instances/start_instances"))
322
+ client = Vultr::Client.new(api_key: "fake", adapter: :test, stubs: stub)
323
+ assert client.instances.start_instances(instance_ids: body[:instance_ids], **body)
324
+ end
325
+ end