From 03b2c582ccf2eebe2c10ca883b327859cfd87da8 Mon Sep 17 00:00:00 2001 From: Marques Johansson Date: Sun, 9 Sep 2018 13:16:59 -0400 Subject: [PATCH] use setup functions in tests to avoid magic number requirements during testing Closes #32 --- Makefile | 12 +- README.md | 5 +- client_test.go | 14 - env.sample | 2 - fixtures/TestGetInstance.yaml | 254 ++++++++++++++- fixtures/TestGetVolume.yaml | 160 +++++++++- fixtures/TestListInstanceConfigs.yaml | 255 ++++++++++++++- fixtures/TestListInstanceDisks.yaml | 170 +++++++++- fixtures/TestListInstanceVolumes.yaml | 166 +++++++++- .../TestListInstanceVolumes_instance.yaml | 301 +++++++++++++++++ fixtures/TestListInstances.yaml | 257 ++++++++++++++- fixtures/TestUpdateInstanceConfig.yaml | 302 ++++++++++++++++++ instance_snapshots_test.go | 2 +- instances_test.go | 94 ++++-- volumes_test.go | 13 +- 15 files changed, 1871 insertions(+), 136 deletions(-) create mode 100644 fixtures/TestListInstanceVolumes_instance.yaml create mode 100644 fixtures/TestUpdateInstanceConfig.yaml diff --git a/Makefile b/Makefile index bd911532c..cbed613e1 100644 --- a/Makefile +++ b/Makefile @@ -2,14 +2,9 @@ include .env .PHONY: vendor example refresh-fixtures clean-fixtures -LINODE_FIXTURE_INSTANCE:=76859403 -LINODE_FIXTURE_VOLUME:=6574839201 - .PHONY: test test: vendor - @LINODE_TEST_INSTANCE=$(LINODE_FIXTURE_INSTANCE) \ - LINODE_TEST_VOLUME=$(LINODE_FIXTURE_VOLUME) \ - LINODE_FIXTURE_MODE="play" \ + @LINODE_FIXTURE_MODE="play" \ LINODE_TOKEN="awesometokenawesometokenawesometoken" \ go test $(ARGS) @@ -31,19 +26,16 @@ refresh-fixtures: clean-fixtures fixtures fixtures: @echo "* Running fixtures" @LINODE_TOKEN=$(LINODE_TOKEN) \ - LINODE_TEST_INSTANCE=$(LINODE_TEST_INSTANCE) \ - LINODE_TEST_VOLUME=$(LINODE_TEST_VOLUME) \ LINODE_FIXTURE_MODE="record" go test $(ARGS) @echo "* Santizing fixtures" @for yaml in fixtures/*yaml; do \ sed -E -i "" -e "s/$(LINODE_TOKEN)/awesometokenawesometokenawesometoken/g" \ - -e "s/$(LINODE_TEST_INSTANCE)/$(LINODE_FIXTURE_INSTANCE)/g" \ -e 's/20[0-9]{2}-[01][0-9]-[0-3][0-9]T[0-2][0-9]:[0-9]{2}:[0-9]{2}/2018-01-02T03:04:05/g' \ -e 's/nb-[0-9]{1,3}-[0-9]{1,3}-[0-9]{1,3}-[0-9]{1,3}\./nb-10-20-30-40./g' \ -e 's/192\.168\.((1?[0-9][0-9]?|2[0-4][0-9]|25[0-5])\.)(1?[0-9][0-9]?|2[0-4][0-9]|25[0-5])/192.168.030.040/g' \ -e '/^192\.168/!s/((1?[0-9][0-9]?|2[0-4][0-9]|25[0-5])\.){3}(1?[0-9][0-9]?|2[0-4][0-9]|25[0-5])/010.020.030.040/g' \ -e 's/(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))/1234::5678/g' \ - -e "s/$(LINODE_TEST_VOLUME)/$(LINODE_FIXTURE_VOLUME)/g" $$yaml; \ + $$yaml; \ done .PHONY: godoc diff --git a/README.md b/README.md index dfdd322ea..2a83dcda6 100644 --- a/README.md +++ b/README.md @@ -156,9 +156,8 @@ When performing a `POST` or `PUT` request, multiple field related errors will be Run `make test` to run the unit tests. This is the same as running `go test` except that `make test` will execute the tests while playing back API response fixtures that were recorded during a previous development build. -`go test` can be used without the fixtures, so long as `LINODE_TEST_INSTANCE` and `LINODE_TEST_VOLUME` are set -to an instance ID and volume ID that exists on your account. The Linode instance must have a backup and a snapshot to -match the test expectations. Copy `env.sample` to `.env` and configure your persistent test settings, including an API token. +`go test` can be used without the fixtures. Copy `env.sample` to `.env` and configure your persistent test +settings, including an API token. `go test -short` can be used to run live API tests that do not require an account token. diff --git a/client_test.go b/client_test.go index 0c6ff619f..1a227d97b 100644 --- a/client_test.go +++ b/client_test.go @@ -16,9 +16,6 @@ var testingMode = recorder.ModeDisabled var debugAPI = false var validTestAPIKey = "NOTANAPIKEY" -var TestInstanceID int -var TestVolumeID int - func init() { if apiToken, ok := os.LookupEnv("LINODE_TOKEN"); ok { validTestAPIKey = apiToken @@ -42,17 +39,6 @@ func init() { testingMode = recorder.ModeReplaying } } - - if apiTestInstance, ok := os.LookupEnv("LINODE_TEST_INSTANCE"); ok { - TestInstanceID, _ = strconv.Atoi(apiTestInstance) - log.Printf("[INFO] LINODE_TEST_INSTANCE %d will be examined for tests", TestInstanceID) - } - - if apiTestVolume, ok := os.LookupEnv("LINODE_TEST_VOLUME"); ok { - TestVolumeID, _ = strconv.Atoi(apiTestVolume) - log.Printf("[INFO] LINODE_TEST_VOLUME %d will be examined for tests", TestVolumeID) - } - } // testRecorder returns a go-vcr recorder and an associated function that the caller must defer diff --git a/env.sample b/env.sample index 01d23cf49..b1c9d1803 100644 --- a/env.sample +++ b/env.sample @@ -1,4 +1,2 @@ LINODE_TOKEN= LINODE_DEBUG=0 -LINODE_TEST_INSTANCE= -LINODE_TEST_VOLUME= diff --git a/fixtures/TestGetInstance.yaml b/fixtures/TestGetInstance.yaml index 1c064510c..d91ba2add 100644 --- a/fixtures/TestGetInstance.yaml +++ b/fixtures/TestGetInstance.yaml @@ -1,6 +1,159 @@ --- version: 1 interactions: +- request: + body: '{"region":"us-west","type":"g6-nanode-1","label":"linodego-test-instance","booted":false}' + form: {} + headers: + Accept: + - application/json + Authorization: + - Bearer awesometokenawesometokenawesometoken + Content-Type: + - application/json + User-Agent: + - linodego 0.4.0 https://github.com/linode/linodego + url: https://api.linode.com/v4/linode/instances + method: POST + response: + body: '{"region": "us-west", "alerts": {"network_in": 10, "io": 10000, "cpu": + 90, "transfer_quota": 80, "network_out": 10}, "created": "2018-01-02T03:04:05", + "label": "linodego-test-instance", "updated": "2018-01-02T03:04:05", "watchdog_enabled": + true, "image": null, "id": 10157452, "group": "", "ipv4": ["010.020.030.040"], + "status": "provisioning", "hypervisor": "kvm", "ipv6": "1234::5678/64", + "type": "g6-nanode-1", "backups": {"enabled": false, "schedule": {"day": null, + "window": null}}, "specs": {"vcpus": 1, "disk": 25600, "memory": 1024, "transfer": + 1000}}' + headers: + Access-Control-Allow-Credentials: + - "true" + Access-Control-Allow-Headers: + - Authorization, Origin, X-Requested-With, Content-Type, Accept, X-Filter + Access-Control-Allow-Methods: + - HEAD, GET, OPTIONS, POST, PUT, DELETE + Access-Control-Allow-Origin: + - '*' + Access-Control-Expose-Headers: + - X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Status + Cache-Control: + - private, max-age=60, s-maxage=60 + Connection: + - keep-alive + Content-Length: + - "576" + Content-Security-Policy: + - default-src 'none' + Content-Type: + - application/json + Date: + - Sat, 08 Sep 2018 20:05:47 GMT + Retry-After: + - "118" + Server: + - nginx + Strict-Transport-Security: + - max-age=31536000 + Vary: + - Authorization, X-Filter + X-Accepted-Oauth-Scopes: + - linodes:read_write + X-Content-Type-Options: + - nosniff + - nosniff + X-Frame-Options: + - DENY + - DENY + X-Oauth-Scopes: + - '*' + X-Ratelimit-Limit: + - "400" + X-Ratelimit-Remaining: + - "399" + X-Ratelimit-Reset: + - "1536437266" + X-Spec-Version: + - 4.0.4 + X-Xss-Protection: + - 1; mode=block + status: 200 OK + code: 200 + duration: "" +- request: + body: '{"label":"linodego-test-config","devices":{}}' + form: {} + headers: + Accept: + - application/json + Authorization: + - Bearer awesometokenawesometokenawesometoken + Content-Type: + - application/json + User-Agent: + - linodego 0.4.0 https://github.com/linode/linodego + url: https://api.linode.com/v4/linode/instances/10157452/configs + method: POST + response: + body: '{"virt_mode": "paravirt", "devices": {"sdg": null, "sda": null, "sdd": + null, "sdb": null, "sde": null, "sdc": null, "sdh": null, "sdf": null}, "memory_limit": + 0, "comments": "", "updated": "2018-01-02T03:04:05", "run_level": "default", + "label": "linodego-test-config", "id": 11404308, "created": "2018-01-02T03:04:05", + "initrd": null, "root_device": "/dev/sda", "helpers": {"distro": true, "modules_dep": + true, "network": true, "devtmpfs_automount": true, "updatedb_disabled": true}, + "kernel": "linode/latest-64bit"}' + headers: + Access-Control-Allow-Credentials: + - "true" + Access-Control-Allow-Headers: + - Authorization, Origin, X-Requested-With, Content-Type, Accept, X-Filter + Access-Control-Allow-Methods: + - HEAD, GET, OPTIONS, POST, PUT, DELETE + Access-Control-Allow-Origin: + - '*' + Access-Control-Expose-Headers: + - X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Status + Cache-Control: + - private, max-age=60, s-maxage=60 + Connection: + - keep-alive + Content-Length: + - "516" + Content-Security-Policy: + - default-src 'none' + Content-Type: + - application/json + Date: + - Sat, 08 Sep 2018 20:05:47 GMT + Retry-After: + - "119" + Server: + - nginx + Strict-Transport-Security: + - max-age=31536000 + Vary: + - Authorization, X-Filter + X-Accepted-Oauth-Scopes: + - linodes:read_write + X-Content-Type-Options: + - nosniff + - nosniff + X-Frame-Options: + - DENY + - DENY + X-Oauth-Scopes: + - '*' + X-Ratelimit-Limit: + - "400" + X-Ratelimit-Remaining: + - "399" + X-Ratelimit-Reset: + - "1536437267" + X-Spec-Version: + - 4.0.4 + X-Xss-Protection: + - 1; mode=block + status: 200 OK + code: 200 + duration: "" - request: body: "" form: {} @@ -12,18 +165,17 @@ interactions: Content-Type: - application/json User-Agent: - - linodego 0.0.1 https://github.com/linode/linodego - url: https://api.linode.com/v4/linode/instances/76859403 + - linodego 0.4.0 https://github.com/linode/linodego + url: https://api.linode.com/v4/linode/instances/10157452 method: GET response: - body: '{"watchdog_enabled": true, "ipv6": "1234::5678/64", - "hypervisor": "kvm", "ipv4": ["010.020.030.040", "192.168.030.040"], "status": "running", - "label": "test-linode", "backups": {"schedule": {"window": "W16", "day": "Monday"}, - "enabled": true}, "updated": "2018-01-02T03:04:05", "image": "linode/ubuntu18.04", - "created": "2018-01-02T03:04:05", "id": 76859403, "type": "g6-standard-1", "region": - "us-east", "group": "", "specs": {"vcpus": 1, "disk": 51200, "memory": 2048, - "transfer": 2000}, "alerts": {"cpu": 90, "io": 10000, "network_out": 10, "network_in": - 10, "transfer_quota": 80}}' + body: '{"group": "", "backups": {"schedule": {"window": null, "day": null}, "enabled": + false}, "region": "us-west", "created": "2018-01-02T03:04:05", "label": "linodego-test-instance", + "id": 10157452, "status": "provisioning", "image": null, "specs": {"transfer": + 1000, "vcpus": 1, "disk": 25600, "memory": 1024}, "updated": "2018-01-02T03:04:05", + "ipv6": "1234::5678/64", "hypervisor": "kvm", "type": "g6-nanode-1", + "alerts": {"cpu": 90, "network_in": 10, "io": 10000, "transfer_quota": 80, "network_out": + 10}, "ipv4": ["010.020.030.040"], "watchdog_enabled": true}' headers: Access-Control-Allow-Credentials: - "true" @@ -41,15 +193,15 @@ interactions: Connection: - keep-alive Content-Length: - - "599" + - "576" Content-Security-Policy: - default-src 'none' Content-Type: - application/json Date: - - Tue, 03 Jul 2018 01:38:49 GMT + - Sat, 08 Sep 2018 20:05:48 GMT Retry-After: - - "28" + - "15" Server: - nginx Strict-Transport-Security: @@ -70,11 +222,81 @@ interactions: X-Ratelimit-Limit: - "400" X-Ratelimit-Remaining: - - "395" + - "398" + X-Ratelimit-Reset: + - "1536437164" + X-Spec-Version: + - 4.0.4 + X-Xss-Protection: + - 1; mode=block + status: 200 OK + code: 200 + duration: "" +- request: + body: "" + form: {} + headers: + Accept: + - application/json + Authorization: + - Bearer awesometokenawesometokenawesometoken + Content-Type: + - application/json + User-Agent: + - linodego 0.4.0 https://github.com/linode/linodego + url: https://api.linode.com/v4/linode/instances/10157452 + method: DELETE + response: + body: '{}' + headers: + Access-Control-Allow-Credentials: + - "true" + Access-Control-Allow-Headers: + - Authorization, Origin, X-Requested-With, Content-Type, Accept, X-Filter + Access-Control-Allow-Methods: + - HEAD, GET, OPTIONS, POST, PUT, DELETE + Access-Control-Allow-Origin: + - '*' + Access-Control-Expose-Headers: + - X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Status + Cache-Control: + - private, max-age=60, s-maxage=60 + Connection: + - keep-alive + Content-Length: + - "2" + Content-Security-Policy: + - default-src 'none' + Content-Type: + - application/json + Date: + - Sat, 08 Sep 2018 20:05:48 GMT + Retry-After: + - "119" + Server: + - nginx + Strict-Transport-Security: + - max-age=31536000 + Vary: + - Authorization, X-Filter + X-Accepted-Oauth-Scopes: + - linodes:read_write + X-Content-Type-Options: + - nosniff + - nosniff + X-Frame-Options: + - DENY + - DENY + X-Oauth-Scopes: + - '*' + X-Ratelimit-Limit: + - "400" + X-Ratelimit-Remaining: + - "399" X-Ratelimit-Reset: - - "1530581958" + - "1536437268" X-Spec-Version: - - 4.0.2 + - 4.0.4 X-Xss-Protection: - 1; mode=block status: 200 OK diff --git a/fixtures/TestGetVolume.yaml b/fixtures/TestGetVolume.yaml index 0359aeb73..8481bd1bb 100644 --- a/fixtures/TestGetVolume.yaml +++ b/fixtures/TestGetVolume.yaml @@ -1,6 +1,78 @@ --- version: 1 interactions: +- request: + body: '{"label":"linodego-test-volume","region":"us-west"}' + form: {} + headers: + Accept: + - application/json + Authorization: + - Bearer awesometokenawesometokenawesometoken + Content-Type: + - application/json + User-Agent: + - linodego 0.4.0 https://github.com/linode/linodego + url: https://api.linode.com/v4/volumes + method: POST + response: + body: '{"updated": "2018-01-02T03:04:05", "filesystem_path": "/dev/disk/by-id/scsi-0Linode_Volume_linodego-test-volume", + "created": "2018-01-02T03:04:05", "id": 12771, "label": "linodego-test-volume", + "status": "creating", "region": "us-west", "linode_id": null, "size": 20}' + headers: + Access-Control-Allow-Credentials: + - "true" + Access-Control-Allow-Headers: + - Authorization, Origin, X-Requested-With, Content-Type, Accept, X-Filter + Access-Control-Allow-Methods: + - HEAD, GET, OPTIONS, POST, PUT, DELETE + Access-Control-Allow-Origin: + - '*' + Access-Control-Expose-Headers: + - X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Status + Cache-Control: + - private, max-age=60, s-maxage=60 + Connection: + - keep-alive + Content-Length: + - "267" + Content-Security-Policy: + - default-src 'none' + Content-Type: + - application/json + Date: + - Sat, 08 Sep 2018 22:25:51 GMT + Retry-After: + - "119" + Server: + - nginx + Strict-Transport-Security: + - max-age=31536000 + Vary: + - Authorization, X-Filter + X-Accepted-Oauth-Scopes: + - volumes:read_write + X-Content-Type-Options: + - nosniff + - nosniff + X-Frame-Options: + - DENY + - DENY + X-Oauth-Scopes: + - '*' + X-Ratelimit-Limit: + - "400" + X-Ratelimit-Remaining: + - "399" + X-Ratelimit-Reset: + - "1536445671" + X-Spec-Version: + - 4.0.4 + X-Xss-Protection: + - 1; mode=block + status: 200 OK + code: 200 + duration: "" - request: body: "" form: {} @@ -12,13 +84,13 @@ interactions: Content-Type: - application/json User-Agent: - - linodego 0.0.1 https://github.com/linode/linodego - url: https://api.linode.com/v4/volumes/6574839201 + - linodego 0.4.0 https://github.com/linode/linodego + url: https://api.linode.com/v4/volumes/12771 method: GET response: - body: '{"updated": "2018-01-02T03:04:05", "linode_id": null, "created": "2018-01-02T03:04:05", - "size": 11, "filesystem_path": "/dev/disk/by-id/scsi-0Linode_Volume_test-volume", - "status": "active", "region": "us-east", "label": "test-volume", "id": 6574839201}' + body: '{"label": "linodego-test-volume", "filesystem_path": "/dev/disk/by-id/scsi-0Linode_Volume_linodego-test-volume", + "size": 20, "status": "creating", "updated": "2018-01-02T03:04:05", "created": + "2018-01-02T03:04:05", "linode_id": null, "region": "us-west", "id": 12771}' headers: Access-Control-Allow-Credentials: - "true" @@ -36,13 +108,13 @@ interactions: Connection: - keep-alive Content-Length: - - "246" + - "267" Content-Security-Policy: - default-src 'none' Content-Type: - application/json Date: - - Fri, 13 Jul 2018 04:53:18 GMT + - Sat, 08 Sep 2018 22:25:52 GMT Retry-After: - "119" Server: @@ -67,9 +139,79 @@ interactions: X-Ratelimit-Remaining: - "399" X-Ratelimit-Reset: - - "1531457718" + - "1536445672" + X-Spec-Version: + - 4.0.4 + X-Xss-Protection: + - 1; mode=block + status: 200 OK + code: 200 + duration: "" +- request: + body: "" + form: {} + headers: + Accept: + - application/json + Authorization: + - Bearer awesometokenawesometokenawesometoken + Content-Type: + - application/json + User-Agent: + - linodego 0.4.0 https://github.com/linode/linodego + url: https://api.linode.com/v4/volumes/12771 + method: DELETE + response: + body: '{}' + headers: + Access-Control-Allow-Credentials: + - "true" + Access-Control-Allow-Headers: + - Authorization, Origin, X-Requested-With, Content-Type, Accept, X-Filter + Access-Control-Allow-Methods: + - HEAD, GET, OPTIONS, POST, PUT, DELETE + Access-Control-Allow-Origin: + - '*' + Access-Control-Expose-Headers: + - X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Status + Cache-Control: + - private, max-age=60, s-maxage=60 + Connection: + - keep-alive + Content-Length: + - "2" + Content-Security-Policy: + - default-src 'none' + Content-Type: + - application/json + Date: + - Sat, 08 Sep 2018 22:25:52 GMT + Retry-After: + - "119" + Server: + - nginx + Strict-Transport-Security: + - max-age=31536000 + Vary: + - Authorization, X-Filter + X-Accepted-Oauth-Scopes: + - volumes:read_write + X-Content-Type-Options: + - nosniff + - nosniff + X-Frame-Options: + - DENY + - DENY + X-Oauth-Scopes: + - '*' + X-Ratelimit-Limit: + - "400" + X-Ratelimit-Remaining: + - "399" + X-Ratelimit-Reset: + - "1536445672" X-Spec-Version: - - 4.0.3 + - 4.0.4 X-Xss-Protection: - 1; mode=block status: 200 OK diff --git a/fixtures/TestListInstanceConfigs.yaml b/fixtures/TestListInstanceConfigs.yaml index bf616d2c1..d92c11dc6 100644 --- a/fixtures/TestListInstanceConfigs.yaml +++ b/fixtures/TestListInstanceConfigs.yaml @@ -1,6 +1,159 @@ --- version: 1 interactions: +- request: + body: '{"region":"us-west","type":"g6-nanode-1","label":"linodego-test-instance","booted":false}' + form: {} + headers: + Accept: + - application/json + Authorization: + - Bearer awesometokenawesometokenawesometoken + Content-Type: + - application/json + User-Agent: + - linodego 0.4.0 https://github.com/linode/linodego + url: https://api.linode.com/v4/linode/instances + method: POST + response: + body: '{"backups": {"enabled": false, "schedule": {"day": null, "window": null}}, + "updated": "2018-01-02T03:04:05", "region": "us-west", "hypervisor": "kvm", + "label": "linodego-test-instance", "created": "2018-01-02T03:04:05", "image": + null, "alerts": {"network_in": 10, "cpu": 90, "network_out": 10, "transfer_quota": + 80, "io": 10000}, "group": "", "specs": {"vcpus": 1, "transfer": 1000, "disk": + 25600, "memory": 1024}, "ipv6": "1234::5678/64", "type": + "g6-nanode-1", "id": 10174066, "status": "provisioning", "watchdog_enabled": + true, "ipv4": ["010.020.030.040"]}' + headers: + Access-Control-Allow-Credentials: + - "true" + Access-Control-Allow-Headers: + - Authorization, Origin, X-Requested-With, Content-Type, Accept, X-Filter + Access-Control-Allow-Methods: + - HEAD, GET, OPTIONS, POST, PUT, DELETE + Access-Control-Allow-Origin: + - '*' + Access-Control-Expose-Headers: + - X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Status + Cache-Control: + - private, max-age=60, s-maxage=60 + Connection: + - keep-alive + Content-Length: + - "578" + Content-Security-Policy: + - default-src 'none' + Content-Type: + - application/json + Date: + - Sun, 09 Sep 2018 17:11:24 GMT + Retry-After: + - "41" + Server: + - nginx + Strict-Transport-Security: + - max-age=31536000 + Vary: + - Authorization, X-Filter + X-Accepted-Oauth-Scopes: + - linodes:read_write + X-Content-Type-Options: + - nosniff + - nosniff + X-Frame-Options: + - DENY + - DENY + X-Oauth-Scopes: + - '*' + X-Ratelimit-Limit: + - "400" + X-Ratelimit-Remaining: + - "398" + X-Ratelimit-Reset: + - "1536513126" + X-Spec-Version: + - 4.0.4 + X-Xss-Protection: + - 1; mode=block + status: 200 OK + code: 200 + duration: "" +- request: + body: '{"label":"linodego-test-config","devices":{}}' + form: {} + headers: + Accept: + - application/json + Authorization: + - Bearer awesometokenawesometokenawesometoken + Content-Type: + - application/json + User-Agent: + - linodego 0.4.0 https://github.com/linode/linodego + url: https://api.linode.com/v4/linode/instances/10174066/configs + method: POST + response: + body: '{"helpers": {"distro": true, "network": true, "devtmpfs_automount": true, + "updatedb_disabled": true, "modules_dep": true}, "virt_mode": "paravirt", "created": + "2018-01-02T03:04:05", "label": "linodego-test-config", "id": 11421183, "devices": + {"sdc": null, "sdd": null, "sda": null, "sdf": null, "sdb": null, "sde": null, + "sdg": null, "sdh": null}, "run_level": "default", "updated": "2018-01-02T03:04:05", + "memory_limit": 0, "kernel": "linode/latest-64bit", "comments": "", "initrd": + null, "root_device": "/dev/sda"}' + headers: + Access-Control-Allow-Credentials: + - "true" + Access-Control-Allow-Headers: + - Authorization, Origin, X-Requested-With, Content-Type, Accept, X-Filter + Access-Control-Allow-Methods: + - HEAD, GET, OPTIONS, POST, PUT, DELETE + Access-Control-Allow-Origin: + - '*' + Access-Control-Expose-Headers: + - X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Status + Cache-Control: + - private, max-age=60, s-maxage=60 + Connection: + - keep-alive + Content-Length: + - "516" + Content-Security-Policy: + - default-src 'none' + Content-Type: + - application/json + Date: + - Sun, 09 Sep 2018 17:11:24 GMT + Retry-After: + - "40" + Server: + - nginx + Strict-Transport-Security: + - max-age=31536000 + Vary: + - Authorization, X-Filter + X-Accepted-Oauth-Scopes: + - linodes:read_write + X-Content-Type-Options: + - nosniff + - nosniff + X-Frame-Options: + - DENY + - DENY + X-Oauth-Scopes: + - '*' + X-Ratelimit-Limit: + - "400" + X-Ratelimit-Remaining: + - "398" + X-Ratelimit-Reset: + - "1536513125" + X-Spec-Version: + - 4.0.4 + X-Xss-Protection: + - 1; mode=block + status: 200 OK + code: 200 + duration: "" - request: body: "" form: {} @@ -12,19 +165,17 @@ interactions: Content-Type: - application/json User-Agent: - - linodego 0.0.1 https://github.com/linode/linodego - url: https://api.linode.com/v4/linode/instances/76859403/configs + - linodego 0.4.0 https://github.com/linode/linodego + url: https://api.linode.com/v4/linode/instances/10174066/configs method: GET response: - body: '{"pages": 1, "page": 1, "data": [{"updated": "2018-01-02T03:04:05", "root_device": - "/dev/sda", "helpers": {"updatedb_disabled": true, "distro": true, "network": - true, "modules_dep": true, "devtmpfs_automount": true}, "virt_mode": "paravirt", - "id": 9958462, "memory_limit": 0, "label": "My Ubuntu 18.04 LTS Disk Profile", - "run_level": "default", "kernel": "linode/grub2", "devices": {"sda": {"disk_id": - 18974977, "volume_id": null}, "sdd": null, "sdg": null, "sdh": null, "sdf": - null, "sde": null, "sdc": {"disk_id": null, "volume_id": 6574839201}, "sdb": {"disk_id": - 18974978, "volume_id": null}}, "comments": "", "initrd": null, "created": "2018-01-02T03:04:05"}], - "results": 1}' + body: '{"data": [{"helpers": {"distro": true, "devtmpfs_automount": true, "updatedb_disabled": + true, "network": true, "modules_dep": true}, "memory_limit": 0, "label": "linodego-test-config", + "comments": "", "updated": "2018-01-02T03:04:05", "run_level": "default", "id": + 11421183, "initrd": null, "root_device": "/dev/sda", "virt_mode": "paravirt", + "devices": {"sdg": null, "sde": null, "sdc": null, "sdh": null, "sda": null, + "sdf": null, "sdb": null, "sdd": null}, "kernel": "linode/latest-64bit", "created": + "2018-01-02T03:04:05"}], "pages": 1, "page": 1, "results": 1}' headers: Access-Control-Allow-Credentials: - "true" @@ -42,15 +193,15 @@ interactions: Connection: - keep-alive Content-Length: - - "673" + - "565" Content-Security-Policy: - default-src 'none' Content-Type: - application/json Date: - - Tue, 03 Jul 2018 01:38:49 GMT + - Sun, 09 Sep 2018 17:11:24 GMT Retry-After: - - "29" + - "119" Server: - nginx Strict-Transport-Security: @@ -71,11 +222,81 @@ interactions: X-Ratelimit-Limit: - "400" X-Ratelimit-Remaining: - - "395" + - "399" + X-Ratelimit-Reset: + - "1536513204" + X-Spec-Version: + - 4.0.4 + X-Xss-Protection: + - 1; mode=block + status: 200 OK + code: 200 + duration: "" +- request: + body: "" + form: {} + headers: + Accept: + - application/json + Authorization: + - Bearer awesometokenawesometokenawesometoken + Content-Type: + - application/json + User-Agent: + - linodego 0.4.0 https://github.com/linode/linodego + url: https://api.linode.com/v4/linode/instances/10174066 + method: DELETE + response: + body: '{}' + headers: + Access-Control-Allow-Credentials: + - "true" + Access-Control-Allow-Headers: + - Authorization, Origin, X-Requested-With, Content-Type, Accept, X-Filter + Access-Control-Allow-Methods: + - HEAD, GET, OPTIONS, POST, PUT, DELETE + Access-Control-Allow-Origin: + - '*' + Access-Control-Expose-Headers: + - X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Status + Cache-Control: + - private, max-age=60, s-maxage=60 + Connection: + - keep-alive + Content-Length: + - "2" + Content-Security-Policy: + - default-src 'none' + Content-Type: + - application/json + Date: + - Sun, 09 Sep 2018 17:11:24 GMT + Retry-After: + - "119" + Server: + - nginx + Strict-Transport-Security: + - max-age=31536000 + Vary: + - Authorization, X-Filter + X-Accepted-Oauth-Scopes: + - linodes:read_write + X-Content-Type-Options: + - nosniff + - nosniff + X-Frame-Options: + - DENY + - DENY + X-Oauth-Scopes: + - '*' + X-Ratelimit-Limit: + - "400" + X-Ratelimit-Remaining: + - "399" X-Ratelimit-Reset: - - "1530581959" + - "1536513204" X-Spec-Version: - - 4.0.2 + - 4.0.4 X-Xss-Protection: - 1; mode=block status: 200 OK diff --git a/fixtures/TestListInstanceDisks.yaml b/fixtures/TestListInstanceDisks.yaml index 37fba63c5..aaec90c34 100644 --- a/fixtures/TestListInstanceDisks.yaml +++ b/fixtures/TestListInstanceDisks.yaml @@ -1,6 +1,82 @@ --- version: 1 interactions: +- request: + body: '{"region":"us-west","type":"g6-nanode-1","label":"linodego-test-instance","root_pass":"R34lBAdP455","image":"linode/debian9","booted":false}' + form: {} + headers: + Accept: + - application/json + Authorization: + - Bearer awesometokenawesometokenawesometoken + Content-Type: + - application/json + User-Agent: + - linodego 0.4.0 https://github.com/linode/linodego + url: https://api.linode.com/v4/linode/instances + method: POST + response: + body: '{"group": "", "specs": {"transfer": 1000, "memory": 1024, "disk": 25600, + "vcpus": 1}, "created": "2018-01-02T03:04:05", "region": "us-west", "hypervisor": + "kvm", "label": "linodego-test-instance", "image": "linode/debian9", "alerts": + {"network_out": 10, "transfer_quota": 80, "io": 10000, "cpu": 90, "network_in": + 10}, "status": "provisioning", "updated": "2018-01-02T03:04:05", "ipv6": "1234::5678/64", + "backups": {"enabled": false, "schedule": {"day": null, "window": null}}, "type": + "g6-nanode-1", "ipv4": ["010.020.030.040"], "watchdog_enabled": true, "id": 10158886}' + headers: + Access-Control-Allow-Credentials: + - "true" + Access-Control-Allow-Headers: + - Authorization, Origin, X-Requested-With, Content-Type, Accept, X-Filter + Access-Control-Allow-Methods: + - HEAD, GET, OPTIONS, POST, PUT, DELETE + Access-Control-Allow-Origin: + - '*' + Access-Control-Expose-Headers: + - X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Status + Cache-Control: + - private, max-age=60, s-maxage=60 + Connection: + - keep-alive + Content-Length: + - "589" + Content-Security-Policy: + - default-src 'none' + Content-Type: + - application/json + Date: + - Sat, 08 Sep 2018 22:09:52 GMT + Retry-After: + - "119" + Server: + - nginx + Strict-Transport-Security: + - max-age=31536000 + Vary: + - Authorization, X-Filter + X-Accepted-Oauth-Scopes: + - linodes:read_write + X-Content-Type-Options: + - nosniff + - nosniff + X-Frame-Options: + - DENY + - DENY + X-Oauth-Scopes: + - '*' + X-Ratelimit-Limit: + - "400" + X-Ratelimit-Remaining: + - "399" + X-Ratelimit-Reset: + - "1536444712" + X-Spec-Version: + - 4.0.4 + X-Xss-Protection: + - 1; mode=block + status: 200 OK + code: 200 + duration: "" - request: body: "" form: {} @@ -12,15 +88,15 @@ interactions: Content-Type: - application/json User-Agent: - - linodego 0.0.1 https://github.com/linode/linodego - url: https://api.linode.com/v4/linode/instances/76859403/disks + - linodego 0.4.0 https://github.com/linode/linodego + url: https://api.linode.com/v4/linode/instances/10158886/disks method: GET response: - body: '{"data": [{"updated": "2018-01-02T03:04:05", "created": "2018-01-02T03:04:05", - "size": 50688, "status": "ready", "filesystem": "ext4", "id": 18974977, "label": - "Ubuntu 18.04 LTS Disk"}, {"updated": "2018-01-02T03:04:05", "created": "2018-01-02T03:04:05", - "size": 512, "status": "ready", "filesystem": "swap", "id": 18974978, "label": - "512 MB Swap Image"}], "page": 1, "pages": 1, "results": 2}' + body: '{"pages": 1, "results": 2, "data": [{"id": 21758686, "status": "not ready", + "label": "Debian 9 Disk", "created": "2018-01-02T03:04:05", "size": 25088, "filesystem": + "ext4", "updated": "2018-01-02T03:04:05"}, {"id": 21758687, "status": "not ready", + "label": "512 MB Swap Image", "created": "2018-01-02T03:04:05", "size": 512, + "filesystem": "swap", "updated": "2018-01-02T03:04:05"}], "page": 1}' headers: Access-Control-Allow-Credentials: - "true" @@ -44,9 +120,9 @@ interactions: Content-Type: - application/json Date: - - Tue, 03 Jul 2018 01:38:49 GMT + - Sat, 08 Sep 2018 22:09:53 GMT Retry-After: - - "28" + - "119" Server: - nginx Strict-Transport-Security: @@ -67,11 +143,81 @@ interactions: X-Ratelimit-Limit: - "400" X-Ratelimit-Remaining: - - "393" + - "399" + X-Ratelimit-Reset: + - "1536444713" + X-Spec-Version: + - 4.0.4 + X-Xss-Protection: + - 1; mode=block + status: 200 OK + code: 200 + duration: "" +- request: + body: "" + form: {} + headers: + Accept: + - application/json + Authorization: + - Bearer awesometokenawesometokenawesometoken + Content-Type: + - application/json + User-Agent: + - linodego 0.4.0 https://github.com/linode/linodego + url: https://api.linode.com/v4/linode/instances/10158886 + method: DELETE + response: + body: '{}' + headers: + Access-Control-Allow-Credentials: + - "true" + Access-Control-Allow-Headers: + - Authorization, Origin, X-Requested-With, Content-Type, Accept, X-Filter + Access-Control-Allow-Methods: + - HEAD, GET, OPTIONS, POST, PUT, DELETE + Access-Control-Allow-Origin: + - '*' + Access-Control-Expose-Headers: + - X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Status + Cache-Control: + - private, max-age=60, s-maxage=60 + Connection: + - keep-alive + Content-Length: + - "2" + Content-Security-Policy: + - default-src 'none' + Content-Type: + - application/json + Date: + - Sat, 08 Sep 2018 22:09:53 GMT + Retry-After: + - "119" + Server: + - nginx + Strict-Transport-Security: + - max-age=31536000 + Vary: + - Authorization, X-Filter + X-Accepted-Oauth-Scopes: + - linodes:read_write + X-Content-Type-Options: + - nosniff + - nosniff + X-Frame-Options: + - DENY + - DENY + X-Oauth-Scopes: + - '*' + X-Ratelimit-Limit: + - "400" + X-Ratelimit-Remaining: + - "399" X-Ratelimit-Reset: - - "1530581958" + - "1536444713" X-Spec-Version: - - 4.0.2 + - 4.0.4 X-Xss-Protection: - 1; mode=block status: 200 OK diff --git a/fixtures/TestListInstanceVolumes.yaml b/fixtures/TestListInstanceVolumes.yaml index 2e34185f4..99fc6d055 100644 --- a/fixtures/TestListInstanceVolumes.yaml +++ b/fixtures/TestListInstanceVolumes.yaml @@ -1,6 +1,78 @@ --- version: 1 interactions: +- request: + body: '{"label":"linodego-test-volume","region":"us-west"}' + form: {} + headers: + Accept: + - application/json + Authorization: + - Bearer awesometokenawesometokenawesometoken + Content-Type: + - application/json + User-Agent: + - linodego 0.4.0 https://github.com/linode/linodego + url: https://api.linode.com/v4/volumes + method: POST + response: + body: '{"filesystem_path": "/dev/disk/by-id/scsi-0Linode_Volume_linodego-test-volume", + "linode_id": null, "region": "us-west", "status": "creating", "label": "linodego-test-volume", + "id": 12787, "created": "2018-01-02T03:04:05", "size": 20, "updated": "2018-01-02T03:04:05"}' + headers: + Access-Control-Allow-Credentials: + - "true" + Access-Control-Allow-Headers: + - Authorization, Origin, X-Requested-With, Content-Type, Accept, X-Filter + Access-Control-Allow-Methods: + - HEAD, GET, OPTIONS, POST, PUT, DELETE + Access-Control-Allow-Origin: + - '*' + Access-Control-Expose-Headers: + - X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Status + Cache-Control: + - private, max-age=60, s-maxage=60 + Connection: + - keep-alive + Content-Length: + - "267" + Content-Security-Policy: + - default-src 'none' + Content-Type: + - application/json + Date: + - Sun, 09 Sep 2018 17:12:41 GMT + Retry-After: + - "119" + Server: + - nginx + Strict-Transport-Security: + - max-age=31536000 + Vary: + - Authorization, X-Filter + X-Accepted-Oauth-Scopes: + - volumes:read_write + X-Content-Type-Options: + - nosniff + - nosniff + X-Frame-Options: + - DENY + - DENY + X-Oauth-Scopes: + - '*' + X-Ratelimit-Limit: + - "400" + X-Ratelimit-Remaining: + - "399" + X-Ratelimit-Reset: + - "1536513281" + X-Spec-Version: + - 4.0.4 + X-Xss-Protection: + - 1; mode=block + status: 200 OK + code: 200 + duration: "" - request: body: "" form: {} @@ -12,14 +84,14 @@ interactions: Content-Type: - application/json User-Agent: - - linodego 0.0.1 https://github.com/linode/linodego - url: https://api.linode.com/v4/linode/instances/76859403/volumes + - linodego 0.4.0 https://github.com/linode/linodego + url: https://api.linode.com/v4/linode/instances/10174075/volumes method: GET response: - body: '{"results": 1, "data": [{"created": "2018-01-02T03:04:05", "id": 6574839201, - "linode_id": 76859403, "label": "test-volume", "filesystem_path": "/dev/disk/by-id/scsi-0Linode_Volume_test-volume", - "region": "us-east", "status": "active", "size": 10, "updated": "2018-01-02T03:04:05"}], - "pages": 1, "page": 1}' + body: '{"pages": 1, "results": 1, "data": [{"id": 12787, "status": "active", "label": + "linodego-test-volume", "updated": "2018-01-02T03:04:05", "created": "2018-01-02T03:04:05", + "filesystem_path": "/dev/disk/by-id/scsi-0Linode_Volume_linodego-test-volume", + "size": 20, "linode_id": 10174075, "region": "us-west"}], "page": 1}' headers: Access-Control-Allow-Credentials: - "true" @@ -37,15 +109,15 @@ interactions: Connection: - keep-alive Content-Length: - - "298" + - "318" Content-Security-Policy: - default-src 'none' Content-Type: - application/json Date: - - Tue, 03 Jul 2018 01:38:50 GMT + - Sun, 09 Sep 2018 17:12:42 GMT Retry-After: - - "27" + - "119" Server: - nginx Strict-Transport-Security: @@ -66,11 +138,81 @@ interactions: X-Ratelimit-Limit: - "400" X-Ratelimit-Remaining: - - "394" + - "399" + X-Ratelimit-Reset: + - "1536513282" + X-Spec-Version: + - 4.0.4 + X-Xss-Protection: + - 1; mode=block + status: 200 OK + code: 200 + duration: "" +- request: + body: "" + form: {} + headers: + Accept: + - application/json + Authorization: + - Bearer awesometokenawesometokenawesometoken + Content-Type: + - application/json + User-Agent: + - linodego 0.4.0 https://github.com/linode/linodego + url: https://api.linode.com/v4/volumes/12787 + method: DELETE + response: + body: '{}' + headers: + Access-Control-Allow-Credentials: + - "true" + Access-Control-Allow-Headers: + - Authorization, Origin, X-Requested-With, Content-Type, Accept, X-Filter + Access-Control-Allow-Methods: + - HEAD, GET, OPTIONS, POST, PUT, DELETE + Access-Control-Allow-Origin: + - '*' + Access-Control-Expose-Headers: + - X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Status + Cache-Control: + - private, max-age=60, s-maxage=60 + Connection: + - keep-alive + Content-Length: + - "2" + Content-Security-Policy: + - default-src 'none' + Content-Type: + - application/json + Date: + - Sun, 09 Sep 2018 17:12:42 GMT + Retry-After: + - "119" + Server: + - nginx + Strict-Transport-Security: + - max-age=31536000 + Vary: + - Authorization, X-Filter + X-Accepted-Oauth-Scopes: + - volumes:read_write + X-Content-Type-Options: + - nosniff + - nosniff + X-Frame-Options: + - DENY + - DENY + X-Oauth-Scopes: + - '*' + X-Ratelimit-Limit: + - "400" + X-Ratelimit-Remaining: + - "399" X-Ratelimit-Reset: - - "1530581958" + - "1536513282" X-Spec-Version: - - 4.0.2 + - 4.0.4 X-Xss-Protection: - 1; mode=block status: 200 OK diff --git a/fixtures/TestListInstanceVolumes_instance.yaml b/fixtures/TestListInstanceVolumes_instance.yaml new file mode 100644 index 000000000..90f93478f --- /dev/null +++ b/fixtures/TestListInstanceVolumes_instance.yaml @@ -0,0 +1,301 @@ +--- +version: 1 +interactions: +- request: + body: '{"region":"us-west","type":"g6-nanode-1","label":"linodego-test-instance","booted":false}' + form: {} + headers: + Accept: + - application/json + Authorization: + - Bearer awesometokenawesometokenawesometoken + Content-Type: + - application/json + User-Agent: + - linodego 0.4.0 https://github.com/linode/linodego + url: https://api.linode.com/v4/linode/instances + method: POST + response: + body: '{"group": "", "specs": {"transfer": 1000, "memory": 1024, "disk": 25600, + "vcpus": 1}, "created": "2018-01-02T03:04:05", "region": "us-west", "hypervisor": + "kvm", "label": "linodego-test-instance", "image": null, "alerts": {"network_out": + 10, "transfer_quota": 80, "io": 10000, "cpu": 90, "network_in": 10}, "status": + "provisioning", "updated": "2018-01-02T03:04:05", "ipv6": "1234::5678/64", + "backups": {"enabled": false, "schedule": {"day": null, "window": null}}, "type": + "g6-nanode-1", "ipv4": ["010.020.030.040"], "watchdog_enabled": true, "id": 10174075}' + headers: + Access-Control-Allow-Credentials: + - "true" + Access-Control-Allow-Headers: + - Authorization, Origin, X-Requested-With, Content-Type, Accept, X-Filter + Access-Control-Allow-Methods: + - HEAD, GET, OPTIONS, POST, PUT, DELETE + Access-Control-Allow-Origin: + - '*' + Access-Control-Expose-Headers: + - X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Status + Cache-Control: + - private, max-age=60, s-maxage=60 + Connection: + - keep-alive + Content-Length: + - "578" + Content-Security-Policy: + - default-src 'none' + Content-Type: + - application/json + Date: + - Sun, 09 Sep 2018 17:12:40 GMT + Retry-After: + - "119" + Server: + - nginx + Strict-Transport-Security: + - max-age=31536000 + Vary: + - Authorization, X-Filter + X-Accepted-Oauth-Scopes: + - linodes:read_write + X-Content-Type-Options: + - nosniff + - nosniff + X-Frame-Options: + - DENY + - DENY + X-Oauth-Scopes: + - '*' + X-Ratelimit-Limit: + - "400" + X-Ratelimit-Remaining: + - "399" + X-Ratelimit-Reset: + - "1536513280" + X-Spec-Version: + - 4.0.4 + X-Xss-Protection: + - 1; mode=block + status: 200 OK + code: 200 + duration: "" +- request: + body: '{"label":"linodego-test-config","devices":{}}' + form: {} + headers: + Accept: + - application/json + Authorization: + - Bearer awesometokenawesometokenawesometoken + Content-Type: + - application/json + User-Agent: + - linodego 0.4.0 https://github.com/linode/linodego + url: https://api.linode.com/v4/linode/instances/10174075/configs + method: POST + response: + body: '{"virt_mode": "paravirt", "devices": {"sdg": null, "sda": null, "sdd": + null, "sdb": null, "sde": null, "sdc": null, "sdh": null, "sdf": null}, "memory_limit": + 0, "comments": "", "updated": "2018-01-02T03:04:05", "run_level": "default", + "label": "linodego-test-config", "id": 11421192, "created": "2018-01-02T03:04:05", + "initrd": null, "root_device": "/dev/sda", "helpers": {"distro": true, "modules_dep": + true, "network": true, "devtmpfs_automount": true, "updatedb_disabled": true}, + "kernel": "linode/latest-64bit"}' + headers: + Access-Control-Allow-Credentials: + - "true" + Access-Control-Allow-Headers: + - Authorization, Origin, X-Requested-With, Content-Type, Accept, X-Filter + Access-Control-Allow-Methods: + - HEAD, GET, OPTIONS, POST, PUT, DELETE + Access-Control-Allow-Origin: + - '*' + Access-Control-Expose-Headers: + - X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Status + Cache-Control: + - private, max-age=60, s-maxage=60 + Connection: + - keep-alive + Content-Length: + - "516" + Content-Security-Policy: + - default-src 'none' + Content-Type: + - application/json + Date: + - Sun, 09 Sep 2018 17:12:41 GMT + Retry-After: + - "119" + Server: + - nginx + Strict-Transport-Security: + - max-age=31536000 + Vary: + - Authorization, X-Filter + X-Accepted-Oauth-Scopes: + - linodes:read_write + X-Content-Type-Options: + - nosniff + - nosniff + X-Frame-Options: + - DENY + - DENY + X-Oauth-Scopes: + - '*' + X-Ratelimit-Limit: + - "400" + X-Ratelimit-Remaining: + - "399" + X-Ratelimit-Reset: + - "1536513281" + X-Spec-Version: + - 4.0.4 + X-Xss-Protection: + - 1; mode=block + status: 200 OK + code: 200 + duration: "" +- request: + body: '{"label":"volume-test","comments":"","devices":{"sda":{"volume_id":12787}},"memory_limit":0,"init_rd":null}' + form: {} + headers: + Accept: + - application/json + Authorization: + - Bearer awesometokenawesometokenawesometoken + Content-Type: + - application/json + User-Agent: + - linodego 0.4.0 https://github.com/linode/linodego + url: https://api.linode.com/v4/linode/instances/10174075/configs/11421192 + method: PUT + response: + body: '{"root_device": "/dev/sda", "updated": "2018-01-02T03:04:05", "virt_mode": + "paravirt", "initrd": null, "label": "volume-test", "created": "2018-01-02T03:04:05", + "comments": "", "memory_limit": 0, "kernel": "linode/latest-64bit", "run_level": + "default", "devices": {"sdb": null, "sdg": null, "sdh": null, "sda": {"disk_id": + null, "volume_id": 12787}, "sdd": null, "sde": null, "sdf": null, "sdc": null}, + "helpers": {"distro": true, "modules_dep": true, "devtmpfs_automount": true, + "network": true, "updatedb_disabled": true}, "id": 11421192}' + headers: + Access-Control-Allow-Credentials: + - "true" + Access-Control-Allow-Headers: + - Authorization, Origin, X-Requested-With, Content-Type, Accept, X-Filter + Access-Control-Allow-Methods: + - HEAD, GET, OPTIONS, POST, PUT, DELETE + Access-Control-Allow-Origin: + - '*' + Access-Control-Expose-Headers: + - X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Status + Cache-Control: + - private, max-age=60, s-maxage=60 + Connection: + - keep-alive + Content-Length: + - "540" + Content-Security-Policy: + - default-src 'none' + Content-Type: + - application/json + Date: + - Sun, 09 Sep 2018 17:12:42 GMT + Retry-After: + - "118" + Server: + - nginx + Strict-Transport-Security: + - max-age=31536000 + Vary: + - Authorization, X-Filter + X-Accepted-Oauth-Scopes: + - linodes:read_write + X-Content-Type-Options: + - nosniff + - nosniff + X-Frame-Options: + - DENY + - DENY + X-Oauth-Scopes: + - '*' + X-Ratelimit-Limit: + - "400" + X-Ratelimit-Remaining: + - "399" + X-Ratelimit-Reset: + - "1536513281" + X-Spec-Version: + - 4.0.4 + X-Xss-Protection: + - 1; mode=block + status: 200 OK + code: 200 + duration: "" +- request: + body: "" + form: {} + headers: + Accept: + - application/json + Authorization: + - Bearer awesometokenawesometokenawesometoken + Content-Type: + - application/json + User-Agent: + - linodego 0.4.0 https://github.com/linode/linodego + url: https://api.linode.com/v4/linode/instances/10174075 + method: DELETE + response: + body: '{}' + headers: + Access-Control-Allow-Credentials: + - "true" + Access-Control-Allow-Headers: + - Authorization, Origin, X-Requested-With, Content-Type, Accept, X-Filter + Access-Control-Allow-Methods: + - HEAD, GET, OPTIONS, POST, PUT, DELETE + Access-Control-Allow-Origin: + - '*' + Access-Control-Expose-Headers: + - X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Status + Cache-Control: + - private, max-age=60, s-maxage=60 + Connection: + - keep-alive + Content-Length: + - "2" + Content-Security-Policy: + - default-src 'none' + Content-Type: + - application/json + Date: + - Sun, 09 Sep 2018 17:12:42 GMT + Retry-After: + - "117" + Server: + - nginx + Strict-Transport-Security: + - max-age=31536000 + Vary: + - Authorization, X-Filter + X-Accepted-Oauth-Scopes: + - linodes:read_write + X-Content-Type-Options: + - nosniff + - nosniff + X-Frame-Options: + - DENY + - DENY + X-Oauth-Scopes: + - '*' + X-Ratelimit-Limit: + - "400" + X-Ratelimit-Remaining: + - "398" + X-Ratelimit-Reset: + - "1536513280" + X-Spec-Version: + - 4.0.4 + X-Xss-Protection: + - 1; mode=block + status: 200 OK + code: 200 + duration: "" diff --git a/fixtures/TestListInstances.yaml b/fixtures/TestListInstances.yaml index eb57035b4..3fa3a5908 100644 --- a/fixtures/TestListInstances.yaml +++ b/fixtures/TestListInstances.yaml @@ -2,7 +2,7 @@ version: 1 interactions: - request: - body: "" + body: '{"region":"us-west","type":"g6-nanode-1","label":"linodego-test-instance","booted":false}' form: {} headers: Accept: @@ -12,19 +12,172 @@ interactions: Content-Type: - application/json User-Agent: - - linodego 0.0.1 https://github.com/linode/linodego + - linodego 0.4.0 https://github.com/linode/linodego url: https://api.linode.com/v4/linode/instances + method: POST + response: + body: '{"status": "provisioning", "group": "", "watchdog_enabled": true, "hypervisor": + "kvm", "specs": {"memory": 1024, "transfer": 1000, "disk": 25600, "vcpus": 1}, + "ipv4": ["010.020.030.040"], "label": "linodego-test-instance", "updated": "2018-01-02T03:04:05", + "id": 10157365, "type": "g6-nanode-1", "image": null, "created": "2018-01-02T03:04:05", + "backups": {"schedule": {"window": null, "day": null}, "enabled": false}, "alerts": + {"network_in": 10, "network_out": 10, "cpu": 90, "transfer_quota": 80, "io": + 10000}, "ipv6": "1234::5678/64", "region": "us-west"}' + headers: + Access-Control-Allow-Credentials: + - "true" + Access-Control-Allow-Headers: + - Authorization, Origin, X-Requested-With, Content-Type, Accept, X-Filter + Access-Control-Allow-Methods: + - HEAD, GET, OPTIONS, POST, PUT, DELETE + Access-Control-Allow-Origin: + - '*' + Access-Control-Expose-Headers: + - X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Status + Cache-Control: + - private, max-age=60, s-maxage=60 + Connection: + - keep-alive + Content-Length: + - "576" + Content-Security-Policy: + - default-src 'none' + Content-Type: + - application/json + Date: + - Sat, 08 Sep 2018 20:04:03 GMT + Retry-After: + - "116" + Server: + - nginx + Strict-Transport-Security: + - max-age=31536000 + Vary: + - Authorization, X-Filter + X-Accepted-Oauth-Scopes: + - linodes:read_write + X-Content-Type-Options: + - nosniff + - nosniff + X-Frame-Options: + - DENY + - DENY + X-Oauth-Scopes: + - '*' + X-Ratelimit-Limit: + - "400" + X-Ratelimit-Remaining: + - "399" + X-Ratelimit-Reset: + - "1536437160" + X-Spec-Version: + - 4.0.4 + X-Xss-Protection: + - 1; mode=block + status: 200 OK + code: 200 + duration: "" +- request: + body: '{"label":"linodego-test-config","devices":{}}' + form: {} + headers: + Accept: + - application/json + Authorization: + - Bearer awesometokenawesometokenawesometoken + Content-Type: + - application/json + User-Agent: + - linodego 0.4.0 https://github.com/linode/linodego + url: https://api.linode.com/v4/linode/instances/10157365/configs + method: POST + response: + body: '{"helpers": {"distro": true, "devtmpfs_automount": true, "updatedb_disabled": + true, "network": true, "modules_dep": true}, "memory_limit": 0, "label": "linodego-test-config", + "comments": "", "updated": "2018-01-02T03:04:05", "run_level": "default", "id": + 11404221, "initrd": null, "root_device": "/dev/sda", "virt_mode": "paravirt", + "devices": {"sdg": null, "sde": null, "sdc": null, "sdh": null, "sda": null, + "sdf": null, "sdb": null, "sdd": null}, "kernel": "linode/latest-64bit", "created": + "2018-01-02T03:04:05"}' + headers: + Access-Control-Allow-Credentials: + - "true" + Access-Control-Allow-Headers: + - Authorization, Origin, X-Requested-With, Content-Type, Accept, X-Filter + Access-Control-Allow-Methods: + - HEAD, GET, OPTIONS, POST, PUT, DELETE + Access-Control-Allow-Origin: + - '*' + Access-Control-Expose-Headers: + - X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Status + Cache-Control: + - private, max-age=60, s-maxage=60 + Connection: + - keep-alive + Content-Length: + - "516" + Content-Security-Policy: + - default-src 'none' + Content-Type: + - application/json + Date: + - Sat, 08 Sep 2018 20:04:03 GMT + Retry-After: + - "119" + Server: + - nginx + Strict-Transport-Security: + - max-age=31536000 + Vary: + - Authorization, X-Filter + X-Accepted-Oauth-Scopes: + - linodes:read_write + X-Content-Type-Options: + - nosniff + - nosniff + X-Frame-Options: + - DENY + - DENY + X-Oauth-Scopes: + - '*' + X-Ratelimit-Limit: + - "400" + X-Ratelimit-Remaining: + - "399" + X-Ratelimit-Reset: + - "1536437163" + X-Spec-Version: + - 4.0.4 + X-Xss-Protection: + - 1; mode=block + status: 200 OK + code: 200 + duration: "" +- request: + body: "" + form: {} + headers: + Accept: + - application/json + Authorization: + - Bearer awesometokenawesometokenawesometoken + Content-Type: + - application/json + User-Agent: + - linodego 0.4.0 https://github.com/linode/linodego + X-Filter: + - '{"id": 10157365}' + url: https://api.linode.com/v4/linode/instances?page=1 method: GET response: - body: '{"data": [{"region": "us-east", "alerts": {"network_in": 10, "network_out": - 10, "io": 10000, "cpu": 90, "transfer_quota": 80}, "specs": {"disk": 51200, - "transfer": 2000, "vcpus": 1, "memory": 2048}, "image": "linode/ubuntu18.04", - "created": "2018-01-02T03:04:05", "ipv6": "1234::5678/64", - "hypervisor": "kvm", "ipv4": ["010.020.030.040", "192.168.030.040"], "updated": - "2018-01-02T03:04:05", "watchdog_enabled": true, "group": "", "id": 76859403, - "status": "running", "backups": {"schedule": {"day": "Monday", "window": "W16"}, - "enabled": true}, "label": "test-linode", "type": "g6-standard-1"}], "page": - 1, "pages": 1, "results": 1}' + body: '{"data": [{"backups": {"enabled": false, "schedule": {"window": null, "day": + null}}, "ipv6": "1234::5678/64", "status": "provisioning", + "group": "", "type": "g6-nanode-1", "hypervisor": "kvm", "specs": {"vcpus": + 1, "disk": 25600, "transfer": 1000, "memory": 1024}, "region": "us-west", "label": + "linodego-test-instance", "ipv4": ["010.020.030.040"], "id": 10157365, "created": + "2018-01-02T03:04:05", "updated": "2018-01-02T03:04:05", "alerts": {"cpu": 90, + "network_out": 10, "transfer_quota": 80, "network_in": 10, "io": 10000}, "image": + null, "watchdog_enabled": true}], "results": 1, "page": 1, "pages": 1}' headers: Access-Control-Allow-Credentials: - "true" @@ -42,15 +195,15 @@ interactions: Connection: - keep-alive Content-Length: - - "648" + - "625" Content-Security-Policy: - default-src 'none' Content-Type: - application/json Date: - - Tue, 03 Jul 2018 01:38:48 GMT + - Sat, 08 Sep 2018 20:04:04 GMT Retry-After: - - "29" + - "118" Server: - nginx Strict-Transport-Security: @@ -71,11 +224,81 @@ interactions: X-Ratelimit-Limit: - "400" X-Ratelimit-Remaining: - - "394" + - "399" + X-Ratelimit-Reset: + - "1536437163" + X-Spec-Version: + - 4.0.4 + X-Xss-Protection: + - 1; mode=block + status: 200 OK + code: 200 + duration: "" +- request: + body: "" + form: {} + headers: + Accept: + - application/json + Authorization: + - Bearer awesometokenawesometokenawesometoken + Content-Type: + - application/json + User-Agent: + - linodego 0.4.0 https://github.com/linode/linodego + url: https://api.linode.com/v4/linode/instances/10157365 + method: DELETE + response: + body: '{}' + headers: + Access-Control-Allow-Credentials: + - "true" + Access-Control-Allow-Headers: + - Authorization, Origin, X-Requested-With, Content-Type, Accept, X-Filter + Access-Control-Allow-Methods: + - HEAD, GET, OPTIONS, POST, PUT, DELETE + Access-Control-Allow-Origin: + - '*' + Access-Control-Expose-Headers: + - X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Status + Cache-Control: + - private, max-age=60, s-maxage=60 + Connection: + - keep-alive + Content-Length: + - "2" + Content-Security-Policy: + - default-src 'none' + Content-Type: + - application/json + Date: + - Sat, 08 Sep 2018 20:04:04 GMT + Retry-After: + - "119" + Server: + - nginx + Strict-Transport-Security: + - max-age=31536000 + Vary: + - Authorization, X-Filter + X-Accepted-Oauth-Scopes: + - linodes:read_write + X-Content-Type-Options: + - nosniff + - nosniff + X-Frame-Options: + - DENY + - DENY + X-Oauth-Scopes: + - '*' + X-Ratelimit-Limit: + - "400" + X-Ratelimit-Remaining: + - "399" X-Ratelimit-Reset: - - "1530581958" + - "1536437164" X-Spec-Version: - - 4.0.2 + - 4.0.4 X-Xss-Protection: - 1; mode=block status: 200 OK diff --git a/fixtures/TestUpdateInstanceConfig.yaml b/fixtures/TestUpdateInstanceConfig.yaml new file mode 100644 index 000000000..eba0bc39d --- /dev/null +++ b/fixtures/TestUpdateInstanceConfig.yaml @@ -0,0 +1,302 @@ +--- +version: 1 +interactions: +- request: + body: '{"region":"us-west","type":"g6-nanode-1","label":"linodego-test-instance","booted":false}' + form: {} + headers: + Accept: + - application/json + Authorization: + - Bearer awesometokenawesometokenawesometoken + Content-Type: + - application/json + User-Agent: + - linodego 0.4.0 https://github.com/linode/linodego + url: https://api.linode.com/v4/linode/instances + method: POST + response: + body: '{"region": "us-west", "alerts": {"network_in": 10, "io": 10000, "cpu": + 90, "transfer_quota": 80, "network_out": 10}, "created": "2018-01-02T03:04:05", + "label": "linodego-test-instance", "updated": "2018-01-02T03:04:05", "watchdog_enabled": + true, "image": null, "id": 10174070, "group": "", "ipv4": ["010.020.030.040"], + "status": "provisioning", "hypervisor": "kvm", "ipv6": "1234::5678/64", + "type": "g6-nanode-1", "backups": {"enabled": false, "schedule": {"day": null, + "window": null}}, "specs": {"vcpus": 1, "disk": 25600, "memory": 1024, "transfer": + 1000}}' + headers: + Access-Control-Allow-Credentials: + - "true" + Access-Control-Allow-Headers: + - Authorization, Origin, X-Requested-With, Content-Type, Accept, X-Filter + Access-Control-Allow-Methods: + - HEAD, GET, OPTIONS, POST, PUT, DELETE + Access-Control-Allow-Origin: + - '*' + Access-Control-Expose-Headers: + - X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Status + Cache-Control: + - private, max-age=60, s-maxage=60 + Connection: + - keep-alive + Content-Length: + - "577" + Content-Security-Policy: + - default-src 'none' + Content-Type: + - application/json + Date: + - Sun, 09 Sep 2018 17:12:08 GMT + Retry-After: + - "75" + Server: + - nginx + Strict-Transport-Security: + - max-age=31536000 + Vary: + - Authorization, X-Filter + X-Accepted-Oauth-Scopes: + - linodes:read_write + X-Content-Type-Options: + - nosniff + - nosniff + X-Frame-Options: + - DENY + - DENY + X-Oauth-Scopes: + - '*' + X-Ratelimit-Limit: + - "400" + X-Ratelimit-Remaining: + - "398" + X-Ratelimit-Reset: + - "1536513204" + X-Spec-Version: + - 4.0.4 + X-Xss-Protection: + - 1; mode=block + status: 200 OK + code: 200 + duration: "" +- request: + body: '{"label":"linodego-test-config","devices":{}}' + form: {} + headers: + Accept: + - application/json + Authorization: + - Bearer awesometokenawesometokenawesometoken + Content-Type: + - application/json + User-Agent: + - linodego 0.4.0 https://github.com/linode/linodego + url: https://api.linode.com/v4/linode/instances/10174070/configs + method: POST + response: + body: '{"helpers": {"distro": true, "network": true, "devtmpfs_automount": true, + "updatedb_disabled": true, "modules_dep": true}, "virt_mode": "paravirt", "created": + "2018-01-02T03:04:05", "label": "linodego-test-config", "id": 11421187, "devices": + {"sdc": null, "sdd": null, "sda": null, "sdf": null, "sdb": null, "sde": null, + "sdg": null, "sdh": null}, "run_level": "default", "updated": "2018-01-02T03:04:05", + "memory_limit": 0, "kernel": "linode/latest-64bit", "comments": "", "initrd": + null, "root_device": "/dev/sda"}' + headers: + Access-Control-Allow-Credentials: + - "true" + Access-Control-Allow-Headers: + - Authorization, Origin, X-Requested-With, Content-Type, Accept, X-Filter + Access-Control-Allow-Methods: + - HEAD, GET, OPTIONS, POST, PUT, DELETE + Access-Control-Allow-Origin: + - '*' + Access-Control-Expose-Headers: + - X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Status + Cache-Control: + - private, max-age=60, s-maxage=60 + Connection: + - keep-alive + Content-Length: + - "516" + Content-Security-Policy: + - default-src 'none' + Content-Type: + - application/json + Date: + - Sun, 09 Sep 2018 17:12:08 GMT + Retry-After: + - "119" + Server: + - nginx + Strict-Transport-Security: + - max-age=31536000 + Vary: + - Authorization, X-Filter + X-Accepted-Oauth-Scopes: + - linodes:read_write + X-Content-Type-Options: + - nosniff + - nosniff + X-Frame-Options: + - DENY + - DENY + X-Oauth-Scopes: + - '*' + X-Ratelimit-Limit: + - "400" + X-Ratelimit-Remaining: + - "399" + X-Ratelimit-Reset: + - "1536513248" + X-Spec-Version: + - 4.0.4 + X-Xss-Protection: + - 1; mode=block + status: 200 OK + code: 200 + duration: "" +- request: + body: '{"label":"bar","comments":"","devices":{},"memory_limit":0,"init_rd":null,"root_device":"/dev/root"}' + form: {} + headers: + Accept: + - application/json + Authorization: + - Bearer awesometokenawesometokenawesometoken + Content-Type: + - application/json + User-Agent: + - linodego 0.4.0 https://github.com/linode/linodego + url: https://api.linode.com/v4/linode/instances/10174070/configs/11421187 + method: PUT + response: + body: '{"root_device": "/dev/root", "updated": "2018-01-02T03:04:05", "virt_mode": + "paravirt", "initrd": null, "label": "bar", "created": "2018-01-02T03:04:05", + "comments": "", "memory_limit": 0, "kernel": "linode/latest-64bit", "run_level": + "default", "devices": {"sdb": null, "sdg": null, "sdh": null, "sda": null, "sdd": + null, "sde": null, "sdf": null, "sdc": null}, "helpers": {"distro": true, "modules_dep": + true, "devtmpfs_automount": true, "network": true, "updatedb_disabled": true}, + "id": 11421187}' + headers: + Access-Control-Allow-Credentials: + - "true" + Access-Control-Allow-Headers: + - Authorization, Origin, X-Requested-With, Content-Type, Accept, X-Filter + Access-Control-Allow-Methods: + - HEAD, GET, OPTIONS, POST, PUT, DELETE + Access-Control-Allow-Origin: + - '*' + Access-Control-Expose-Headers: + - X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Status + Cache-Control: + - private, max-age=60, s-maxage=60 + Connection: + - keep-alive + Content-Length: + - "500" + Content-Security-Policy: + - default-src 'none' + Content-Type: + - application/json + Date: + - Sun, 09 Sep 2018 17:12:08 GMT + Retry-After: + - "18" + Server: + - nginx + Strict-Transport-Security: + - max-age=31536000 + Vary: + - Authorization, X-Filter + X-Accepted-Oauth-Scopes: + - linodes:read_write + X-Content-Type-Options: + - nosniff + - nosniff + X-Frame-Options: + - DENY + - DENY + X-Oauth-Scopes: + - '*' + X-Ratelimit-Limit: + - "400" + X-Ratelimit-Remaining: + - "398" + X-Ratelimit-Reset: + - "1536513147" + X-Spec-Version: + - 4.0.4 + X-Xss-Protection: + - 1; mode=block + status: 200 OK + code: 200 + duration: "" +- request: + body: "" + form: {} + headers: + Accept: + - application/json + Authorization: + - Bearer awesometokenawesometokenawesometoken + Content-Type: + - application/json + User-Agent: + - linodego 0.4.0 https://github.com/linode/linodego + url: https://api.linode.com/v4/linode/instances/10174070 + method: DELETE + response: + body: '{}' + headers: + Access-Control-Allow-Credentials: + - "true" + Access-Control-Allow-Headers: + - Authorization, Origin, X-Requested-With, Content-Type, Accept, X-Filter + Access-Control-Allow-Methods: + - HEAD, GET, OPTIONS, POST, PUT, DELETE + Access-Control-Allow-Origin: + - '*' + Access-Control-Expose-Headers: + - X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Status + Cache-Control: + - private, max-age=60, s-maxage=60 + Connection: + - keep-alive + Content-Length: + - "2" + Content-Security-Policy: + - default-src 'none' + Content-Type: + - application/json + Date: + - Sun, 09 Sep 2018 17:12:08 GMT + Retry-After: + - "16" + Server: + - nginx + Strict-Transport-Security: + - max-age=31536000 + Vary: + - Authorization, X-Filter + X-Accepted-Oauth-Scopes: + - linodes:read_write + X-Content-Type-Options: + - nosniff + - nosniff + X-Frame-Options: + - DENY + - DENY + X-Oauth-Scopes: + - '*' + X-Ratelimit-Limit: + - "400" + X-Ratelimit-Remaining: + - "398" + X-Ratelimit-Reset: + - "1536513145" + X-Spec-Version: + - 4.0.4 + X-Xss-Protection: + - 1; mode=block + status: 200 OK + code: 200 + duration: "" diff --git a/instance_snapshots_test.go b/instance_snapshots_test.go index d8a2f1372..b642750c8 100644 --- a/instance_snapshots_test.go +++ b/instance_snapshots_test.go @@ -65,7 +65,7 @@ func TestListInstanceBackups(t *testing.T) { func setupInstanceBackup(t *testing.T, fixturesYaml string) (*linodego.Client, *linodego.Instance, *linodego.InstanceSnapshot, func(), error) { t.Helper() - client, instance, fixtureTeardown, err := setupInstanceWithoutDisks(t, fixturesYaml) + client, instance, _, fixtureTeardown, err := setupInstanceWithoutDisks(t, fixturesYaml) if err != nil { t.Errorf("Error creating instance, got error %v", err) } diff --git a/instances_test.go b/instances_test.go index df19ee140..1eb2157a9 100644 --- a/instances_test.go +++ b/instances_test.go @@ -2,6 +2,7 @@ package linodego_test import ( "context" + "strconv" "testing" "github.com/linode/linodego" @@ -11,31 +12,40 @@ func TestListInstances(t *testing.T) { if testing.Short() { t.Skip("Skipping test in short mode.") } - client, teardown := createTestClient(t, "fixtures/TestListInstances") + client, instance, _, teardown, err := setupInstanceWithoutDisks(t, "fixtures/TestListInstances") defer teardown() - linodes, err := client.ListInstances(context.Background(), nil) + listOpts := linodego.NewListOptions(1, "{\"id\": "+strconv.Itoa(instance.ID)+"}") + linodes, err := client.ListInstances(context.Background(), listOpts) if err != nil { t.Errorf("Error listing instances, expected struct, got error %v", err) } - if len(linodes) == 0 { + if len(linodes) != 1 { t.Errorf("Expected a list of instances, but got %v", linodes) } + + if linodes[0].ID != instance.ID { + t.Errorf("Expected list of instances to include test instance, but got %v", linodes) + } } func TestGetInstance(t *testing.T) { if testing.Short() { t.Skip("Skipping test in short mode.") } - client, teardown := createTestClient(t, "fixtures/TestGetInstance") + client, instance, _, teardown, err := setupInstanceWithoutDisks(t, "fixtures/TestGetInstance") defer teardown() - instance, err := client.GetInstance(context.Background(), TestInstanceID) + instanceGot, err := client.GetInstance(context.Background(), instance.ID) if err != nil { - t.Errorf("Error getting instance TestInstanceID, expected *LinodeInstance, got error %v", err) + t.Errorf("Error getting instance: %s", err) } + if instanceGot.ID != instance.ID { + t.Errorf("Expected instance ID %d to match %d", instanceGot.ID, instance.ID) + } + if instance.Specs.Disk <= 0 { - t.Errorf("Error in instance TestInstanceID spec for disk size, %v", instance.Specs) + t.Errorf("Error parsing instance spec for disk size: %v", instance.Specs) } } @@ -43,10 +53,10 @@ func TestListInstanceDisks(t *testing.T) { if testing.Short() { t.Skip("Skipping test in short mode.") } - client, teardown := createTestClient(t, "fixtures/TestListInstanceDisks") + client, instance, teardown, err := setupInstance(t, "fixtures/TestListInstanceDisks") defer teardown() - disks, err := client.ListInstanceDisks(context.Background(), TestInstanceID, nil) + disks, err := client.ListInstanceDisks(context.Background(), instance.ID, nil) if err != nil { t.Errorf("Error listing instance disks, expected struct, got error %v", err) } @@ -59,26 +69,71 @@ func TestListInstanceConfigs(t *testing.T) { if testing.Short() { t.Skip("Skipping test in short mode.") } - client, teardown := createTestClient(t, "fixtures/TestListInstanceConfigs") + client, instance, config, teardown, err := setupInstanceWithoutDisks(t, "fixtures/TestListInstanceConfigs") defer teardown() - configs, err := client.ListInstanceConfigs(context.Background(), TestInstanceID, nil) + configs, err := client.ListInstanceConfigs(context.Background(), instance.ID, nil) if err != nil { t.Errorf("Error listing instance configs, expected struct, got error %v", err) } if len(configs) == 0 { t.Errorf("Expected a list of instance configs, but got %v", configs) } + if configs[0].ID != config.ID { + t.Errorf("Expected config id %d, got %d", configs[0].ID, config.ID) + } +} + +func TestUpdateInstanceConfig(t *testing.T) { + if testing.Short() { + t.Skip("Skipping test in short mode.") + } + client, instance, config, teardown, err := setupInstanceWithoutDisks(t, "fixtures/TestUpdateInstanceConfig") + defer teardown() + + updateConfigOpts := linodego.InstanceConfigUpdateOptions{ + Label: "bar", + Devices: linodego.InstanceConfigDeviceMap{}, + RootDevice: "/dev/root", + } + + _, err = client.UpdateInstanceConfig(context.Background(), instance.ID, config.ID, updateConfigOpts) + if err != nil { + t.Error(err) + } } func TestListInstanceVolumes(t *testing.T) { if testing.Short() { t.Skip("Skipping test in short mode.") } - client, teardown := createTestClient(t, "fixtures/TestListInstanceVolumes") + + client, instance, config, teardown, err := setupInstanceWithoutDisks(t, "fixtures/TestListInstanceVolumes_instance") defer teardown() + if err != nil { + t.Error(err) + } + + clientVol, volume, teardown, err := setupVolume(t, "fixtures/TestListInstanceVolumes") + defer teardown() + if err != nil { + t.Error(err) + } - volumes, err := client.ListInstanceVolumes(context.Background(), TestInstanceID, nil) + configOpts := linodego.InstanceConfigUpdateOptions{ + Label: "volume-test", + Devices: linodego.InstanceConfigDeviceMap{ + SDA: &linodego.InstanceConfigDevice{ + VolumeID: volume.ID, + }, + }, + } + _, err = client.UpdateInstanceConfig(context.Background(), instance.ID, config.ID, configOpts) + if err != nil { + t.Error(err) + } + + volumes, err := clientVol.ListInstanceVolumes(context.Background(), instance.ID, nil) if err != nil { t.Errorf("Error listing instance volumes, expected struct, got error %v", err) } @@ -90,11 +145,14 @@ func TestListInstanceVolumes(t *testing.T) { func setupInstance(t *testing.T, fixturesYaml string) (*linodego.Client, *linodego.Instance, func(), error) { t.Helper() client, fixtureTeardown := createTestClient(t, fixturesYaml) + falseBool := false createOpts := linodego.InstanceCreateOptions{ Label: "linodego-test-instance", RootPass: "R34lBAdP455", Region: "us-west", Type: "g6-nanode-1", + Image: "linode/debian9", + Booted: &falseBool, } instance, err := client.CreateInstance(context.Background(), createOpts) if err != nil { @@ -110,7 +168,7 @@ func setupInstance(t *testing.T, fixturesYaml string) (*linodego.Client, *linode return client, instance, teardown, err } -func setupInstanceWithoutDisks(t *testing.T, fixturesYaml string) (*linodego.Client, *linodego.Instance, func(), error) { +func setupInstanceWithoutDisks(t *testing.T, fixturesYaml string) (*linodego.Client, *linodego.Instance, *linodego.InstanceConfig, func(), error) { t.Helper() client, fixtureTeardown := createTestClient(t, fixturesYaml) falseBool := false @@ -123,15 +181,15 @@ func setupInstanceWithoutDisks(t *testing.T, fixturesYaml string) (*linodego.Cli instance, err := client.CreateInstance(context.Background(), createOpts) if err != nil { t.Errorf("Error creating test Instance: %s", err) - return nil, nil, fixtureTeardown, err + return nil, nil, nil, fixtureTeardown, err } configOpts := linodego.InstanceConfigCreateOptions{ Label: "linodego-test-config", } - _, err = client.CreateInstanceConfig(context.Background(), instance.ID, configOpts) + config, err := client.CreateInstanceConfig(context.Background(), instance.ID, configOpts) if err != nil { t.Errorf("Error creating config: %s", err) - return nil, nil, fixtureTeardown, err + return nil, nil, nil, fixtureTeardown, err } teardown := func() { @@ -140,5 +198,5 @@ func setupInstanceWithoutDisks(t *testing.T, fixturesYaml string) (*linodego.Cli } fixtureTeardown() } - return client, instance, teardown, err + return client, instance, config, teardown, err } diff --git a/volumes_test.go b/volumes_test.go index 7885e62ee..6898bf18b 100644 --- a/volumes_test.go +++ b/volumes_test.go @@ -83,12 +83,15 @@ func TestGetVolume(t *testing.T) { if testing.Short() { t.Skip("Skipping test in short mode.") } - client, teardown := createTestClient(t, "fixtures/TestGetVolume") - defer teardown() + client, volume, teardownVolume, errVolume := setupVolume(t, "fixtures/TestGetVolume") + defer teardownVolume() + if errVolume != nil { + t.Error(errVolume) + } - _, err := client.GetVolume(context.Background(), TestVolumeID) + _, err := client.GetVolume(context.Background(), volume.ID) if err != nil { - t.Errorf("Error getting volume %d, expected *LinodeVolume, got error %v", TestVolumeID, err) + t.Errorf("Error getting volume %d, expected *LinodeVolume, got error %v", volume.ID, err) } } @@ -105,7 +108,7 @@ func TestWaitForVolumeLinodeID_nil(t *testing.T) { _, err = client.WaitForVolumeLinodeID(context.Background(), volume.ID, nil, 3) if err != nil { - t.Errorf("Error getting volume %d, expected *LinodeVolume, got error %v", TestVolumeID, err) + t.Errorf("Error getting volume %d, expected *LinodeVolume, got error %v", volume.ID, err) } }