Skip to content

Commit

Permalink
Resource tests for Kubernetes & Block Storage (#32)
Browse files Browse the repository at this point in the history
* Add bare metal tests (#1)

* test(bare_metal): test list

* test(bare_metal): test create

* fix(bare_metal): correcting typo from doc

* test(bare_metal): test #retrieve

* test(bare_metals): #update

* test(bare_metals): delete

* test(bare_metals): start

* test(bare_metals): reboot

* test(bare_metals): reinstall

* test(bare_metals): halt

* test(bare_metals): bandwidth

* test(bare_metal): cleaning up assertions

* test(bare_metals): user_data

* test(bare_metals): upgrades

* test(bare_metals): vnc

* test(bare_metals): list_ipv4

* test(bare_metals): list_ipv6

* test(bare_metals): halt_instances

* test(bare_metals): reboot_instances

* test(bare_metals): start_instances

* fix(bare_metal): addressing styling errors

* Kubernetes resource tests (#2)

* test(kubernetes): assertions for #list

* test(kubernetes): assertions for #create

* test(kubernetes): assertions for #retrieve

* test(kubernetes): assertions for #update

* test(kubernetes): assertions for #delete

* test(kubernetes): assertions for #config

* test(kubernetes): assertions for #list_resources

* test(kubernetes): assertions for #list_node_pools

* test(kubernetes): assertions for #retrieve_node_pool

* test(kubernetes): assertions for #create_node_pool

* test(kubernetes): assertions for #update_node_pool

* test(kubernetes): assertions for #delete_node_pool

* test(kubernetes): assertions for #delete_node_pool_instance

* test(kubernetes): assertions for #recycle_node_pool_instance

* fix(kubernetes): address style errors

* fix(kubernetes): adding pagination to #list_node_pools

* test(block_storage): covers all actions for resource

* fix(block_storage): correcting style errors

* fix(blocks): remove patch file
  • Loading branch information
gordysc authored Sep 6, 2021
1 parent 2ce3cd4 commit 9e92cce
Show file tree
Hide file tree
Showing 18 changed files with 650 additions and 8 deletions.
8 changes: 4 additions & 4 deletions lib/vultr/resources/block_storage.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ def delete(block_id:)
delete_request("blocks/#{block_id}")
end

def attach(block_id:, **params)
post_request("blocks/#{block_id}/attach", body: params)
def attach(block_id:)
post_request("blocks/#{block_id}/attach", body: {})
end

def detach(block_id:, **params)
post_request("blocks/#{block_id}/detach", body: params)
def detach(block_id:)
post_request("blocks/#{block_id}/detach", body: {})
end
end
end
7 changes: 3 additions & 4 deletions lib/vultr/resources/kubernetes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,8 @@ def config(vke_id:)
Object.new get_request("kubernetes/clusters/#{vke_id}/config").body
end

def list_resources(vke_id:, **params)
response = get_request("kubernetes/clusters/#{vke_id}/resources", params: params)
Collection.from_response(response, key: "resources", type: Object)
def list_resources(vke_id:)
Object.new get_request("kubernetes/clusters/#{vke_id}/resources").body.dig("resources")
end

def list_node_pools(vke_id:, **params)
Expand Down Expand Up @@ -56,7 +55,7 @@ def delete_node_pool_instance(vke_id:, nodepool_id:, node_id:)
end

def recycle_node_pool_instance(vke_id:, nodepool_id:, node_id:)
post_request("kubernetes/clusters/#{vke_id}/node-pools/#{nodepool_id}/nodes/#{node_id}/recycle")
post_request("kubernetes/clusters/#{vke_id}/node-pools/#{nodepool_id}/nodes/#{node_id}/recycle", body: {})
end
end
end
4 changes: 4 additions & 0 deletions test/fixtures/block_storage/attach.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"instance_id": "cb676a46-66fd-4dfb-b839-443f2e6c0b60",
"live": true
}
13 changes: 13 additions & 0 deletions test/fixtures/block_storage/create.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"block": {
"id": "cb676a46-66fd-4dfb-b839-443f2e6c0b60",
"date_created": "2020-10-10T01:56:20+00:00",
"cost": 5,
"status": "active",
"size_gb": 50,
"region": "ewr",
"attached_to_instance": "742c9913-d088-4d67-bc61-5a10e922fbd1",
"label": "Example Block Storage",
"mount_id": "ewr-example112233"
}
}
4 changes: 4 additions & 0 deletions test/fixtures/block_storage/detach.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"instance_id": "cb676a46-66fd-4dfb-b839-443f2e6c0b60",
"live": true
}
22 changes: 22 additions & 0 deletions test/fixtures/block_storage/list.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"blocks": [
{
"id": "cb676a46-66fd-4dfb-b839-443f2e6c0b60",
"date_created": "2020-10-10T01:56:20+00:00",
"cost": 5,
"status": "pending",
"size_gb": 50,
"region": "ewr",
"attached_to_instance": "742c9913-d088-4d67-bc61-5a10e922fbd1",
"label": "Example Block Storage",
"mount_id": "ewr-example112233"
}
],
"meta": {
"total": 1,
"links": {
"next": "next",
"prev": "prev"
}
}
}
13 changes: 13 additions & 0 deletions test/fixtures/block_storage/retrieve.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"block": {
"id": "cb676a46-66fd-4dfb-b839-443f2e6c0b60",
"date_created": "2020-10-10T01:56:20+00:00",
"cost": 5,
"status": "active",
"size_gb": 50,
"region": "ewr",
"attached_to_instance": "742c9913-d088-4d67-bc61-5a10e922fbd1",
"label": "Example Block Storage",
"mount_id": "ewr-example112233"
}
}
3 changes: 3 additions & 0 deletions test/fixtures/kubernetes/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"kube_config": "kube_config"
}
39 changes: 39 additions & 0 deletions test/fixtures/kubernetes/create.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
{
"vke_cluster": {
"id": "455dcd32-e621-48ee-a10e-0cb5f754e13e",
"label": "vke",
"date_created": "2021-07-07T22:57:01+00:00",
"cluster_subnet": "10.244.0.0/16",
"service_subnet": "10.96.0.0/12",
"ip": "0.0.0.0",
"endpoint": "455dcd32-e621-48ee-a10e-0cb5f754e13e.vultr-k8s.com",
"version": "v1.20.0+1",
"region": "lax",
"status": "pending",
"node_pools": [
{
"id": "11e4443a-f92a-46d6-94c8-61c1a1a7514e",
"date_created": "2021-07-07T22:57:01+00:00",
"date_updated": "2021-07-07T22:58:44+00:00",
"label": "my-label-48770259",
"plan_id": "vc2-1c-2gb",
"status": "pending",
"count": 2,
"nodes": [
{
"id": "43eda5c8-67f7-4c63-88bc-2f568b48b2b0",
"label": "my-label-48770259-6ac60e6313dd1",
"date_created": "2021-07-07T22:57:01+00:00",
"status": "pending"
},
{
"id": "15a7893d-d584-45d5-a74c-d9f46866aa3c",
"label": "my-label-48770259-6ac60e6313ddc",
"date_created": "2021-07-07T22:57:01+00:00",
"status": "pending"
}
]
}
]
}
}
25 changes: 25 additions & 0 deletions test/fixtures/kubernetes/create_node_pool.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"node_pool": {
"id": "4130764b-5276-4552-546f-32513239732b",
"date_created": "2021-07-07T23:29:18+00:00",
"date_updated": "2021-07-08T23:29:18+00:00",
"label": "nodepool-48770716",
"plan_id": "vc2-1c-2gb",
"status": "pending",
"count": 2,
"nodes": [
{
"id": "2f863151-d784-4184-804e-31e4e60945bd",
"label": "nodepool-48770716-6c360e638ce61",
"date_created": "2021-07-07T23:29:18+00:00",
"status": "pending"
},
{
"id": "73a459dc-293f-4c2b-92f7-61be459a033b",
"label": "nodepool-48770716-6c360e638ce6c",
"date_created": "2021-07-07T23:29:18+00:00",
"status": "pending"
}
]
}
}
85 changes: 85 additions & 0 deletions test/fixtures/kubernetes/list.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
{
"vke_clusters": [
{
"id": "c907e832-3080-48a6-a54d-7379e645c0b7",
"label": "my-vke",
"date_created": "2021-07-02T12:12:43+00:00",
"cluster_subnet": "10.244.0.0/16",
"service_subnet": "10.96.0.0/12",
"ip": "8.9.30.155",
"endpoint": "c907e832-3080-48a6-a54d-7379e645c0b7.vultr-k8s.com",
"version": "v1.20.0+1",
"region": "ewr",
"status": "active",
"node_pools": [
{
"id": "74de1914-63ea-4a78-9da5-b7220063c701",
"date_created": "2021-07-02T12:12:44+00:00",
"date_updated": "2021-07-03T12:12:44+00:00",
"label": "nodepool-48597451",
"plan_id": "vc2-1c-2gb",
"status": "active",
"count": 2,
"nodes": [
{
"id": "cafd4673-2a62-49c4-a045-44d05ecc0a7b",
"label": "nodepool-48597451-6a960df02bc1b",
"date_created": "2021-07-02T12:12:44+00:00",
"status": "active"
},
{
"id": "5fc5ae88-f73e-46b5-9fa1-ac5ed8dcd33c",
"label": "nodepool-48597451-6a960df02bc25",
"date_created": "2021-07-02T12:12:44+00:00",
"status": "active"
}
]
}
]
},
{
"id": "455dcd32-e621-48ee-a10e-0cb5f754e13e",
"label": "vke",
"date_created": "2021-07-07T22:57:01+00:00",
"cluster_subnet": "10.244.0.0/16",
"service_subnet": "10.96.0.0/12",
"ip": "207.246.109.187",
"endpoint": "455dcd32-e621-48ee-a10e-0cb5f754e13e.vultr-k8s.com",
"version": "v1.20.0+1",
"region": "lax",
"status": "active",
"node_pools": [
{
"id": "11e4443a-f92a-46d6-94c8-61c1a1a7514e",
"date_created": "2021-07-07T22:57:01+00:00",
"date_updated": "2021-07-08T12:12:44+00:00",
"label": "my-label-48770259",
"plan_id": "vc2-1c-2gb",
"status": "active",
"count": 2,
"nodes": [
{
"id": "43eda5c8-67f7-4c63-88bc-2f568b48b2b0",
"label": "my-label-48770259-6ac60e6313dd1",
"date_created": "2021-07-07T22:57:01+00:00",
"status": "active"
},
{
"id": "15a7893d-d584-45d5-a74c-d9f46866aa3c",
"label": "my-label-48770259-6ac60e6313ddc",
"date_created": "2021-07-07T22:57:01+00:00",
"status": "active"
}
]
}
]
}
],
"meta": {
"total": 2,
"links": {
"next": "next",
"prev": "prev"
}
}
}
56 changes: 56 additions & 0 deletions test/fixtures/kubernetes/list_node_pools.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
{
"node_pools": [
{
"id": "e97bdee9-2781-4f31-be03-60fc75f399ae",
"date_created": "2021-07-07T23:27:08+00:00",
"date_updated": "2021-07-08T12:12:44+00:00",
"label": "my-label-48770703",
"plan_id": "vc2-1c-2gb",
"status": "active",
"count": 2,
"nodes": [
{
"id": "f2e11430-76e5-4dc6-a1c9-ef5682c21ddf",
"label": "my-label-48770703-44060e6384c45",
"date_created": "2021-07-07T23:27:08+00:00",
"status": "active"
},
{
"id": "c0a160eb-a7bc-4377-a6fb-52a9531167ca",
"label": "my-label-48770703-44060e6384c50",
"date_created": "2021-07-07T23:27:08+00:00",
"status": "active"
}
]
},
{
"id": "4130764b-5276-4552-546f-32513239732b",
"date_created": "2021-07-07T23:29:18+00:00",
"label": "nodepool-48770716",
"plan_id": "vc2-1c-2gb",
"status": "active",
"count": 2,
"nodes": [
{
"id": "2f863151-d784-4184-804e-31e4e60945bd",
"label": "nodepool-48770716-6c360e638ce61",
"date_created": "2021-07-07T23:29:18+00:00",
"status": "active"
},
{
"id": "73a459dc-293f-4c2b-92f7-61be459a033b",
"label": "nodepool-48770716-6c360e638ce6c",
"date_created": "2021-07-07T23:29:18+00:00",
"status": "active"
}
]
}
],
"meta": {
"total": 2,
"links": {
"next": "next",
"prev": "prev"
}
}
}
26 changes: 26 additions & 0 deletions test/fixtures/kubernetes/list_resources.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"resources": {
"block_storage": [
{
"id": "29479a12-6edd-48cf-a883-24eccafab094",
"label": "29479a12-6edd-48cf-a883-24eccafab094",
"date_created": "2021-07-29T16:41:07+00:00",
"status": "active"
},
{
"id": "0fa3097e-aef9-475e-958a-56f697ed3998",
"label": "0fa3097e-aef9-475e-958a-56f697ed3998",
"date_created": "2021-08-04T15:34:50+00:00",
"status": "pending"
}
],
"load_balancer": [
{
"id": "369ed902-2ec4-4a22-b959-cb1709394c3a",
"label": "369ed902-2ec4-4a22-b959-cb1709394c3a",
"date_created": "2021-07-29T16:46:12+00:00",
"status": "active"
}
]
}
}
39 changes: 39 additions & 0 deletions test/fixtures/kubernetes/retrieve.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
{
"vke_cluster": {
"id": "455dcd32-e621-48ee-a10e-0cb5f754e13e",
"label": "vke",
"date_created": "2021-07-07T22:57:01+00:00",
"cluster_subnet": "10.244.0.0/16",
"service_subnet": "10.96.0.0/12",
"ip": "207.246.109.187",
"endpoint": "455dcd32-e621-48ee-a10e-0cb5f754e13e.vultr-k8s.com",
"version": "v1.20.0+1",
"region": "lax",
"status": "active",
"node_pools": [
{
"id": "11e4443a-f92a-46d6-94c8-61c1a1a7514e",
"date_created": "2021-07-07T22:57:01+00:00",
"date_updated": "2021-07-08T12:12:44+00:00",
"label": "my-label-48770259",
"plan_id": "vc2-1c-2gb",
"status": "active",
"count": 2,
"nodes": [
{
"id": "43eda5c8-67f7-4c63-88bc-2f568b48b2b0",
"label": "my-label-48770259-6ac60e6313dd1",
"date_created": "2021-07-07T22:57:01+00:00",
"status": "active"
},
{
"id": "15a7893d-d584-45d5-a74c-d9f46866aa3c",
"label": "my-label-48770259-6ac60e6313ddc",
"date_created": "2021-07-07T22:57:01+00:00",
"status": "active"
}
]
}
]
}
}
Loading

0 comments on commit 9e92cce

Please sign in to comment.