diff --git a/tests/000.hurl b/tests/000.hurl new file mode 100644 index 00000000..4ce858cd --- /dev/null +++ b/tests/000.hurl @@ -0,0 +1,139 @@ + +GET http://{{host}}/api/v1/login +Authorization: Bearer {{login_token}} +HTTP 200 +[Captures] +access_token: jsonpath "$.access_token" +[Asserts] +jsonpath "$.access_token" isString +jsonpath "$.access_token_exp" isString + +GET http://{{host}}/api/v1/accounts/aws/sandbox3192 +Authorization: Bearer {{access_token}} +HTTP 200 +[Asserts] +jsonpath "$.name" == "sandbox3192" + +DELETE http://{{host}}/api/v1/placements/{{uuid}} +Authorization: Bearer {{access_token}} +HTTP * + +GET http://{{host}}/api/v1/placements/{{uuid}} +Authorization: Bearer {{access_token}} +HTTP 404 + +POST http://{{host}}/api/v1/placements +Authorization: Bearer {{access_token}} +{ + "service_uuid": "{{uuid}}", + "resources": [ + { + "kind": "AwsSandbox", + "count": 1 + } + ] +} +HTTP 200 +[Captures] +account: jsonpath "$.Placement.resources[0].name" +[Asserts] +jsonpath "$.message" == "Placement Created" +jsonpath "$.Placement.service_uuid" == "{{uuid}}" +jsonpath "$.Placement.resources" count == 1 +jsonpath "$.Placement.resources[0].available" == false + + +PUT http://{{host}}/api/v1/placements/{{uuid}}/stop +Authorization: Bearer {{access_token}} +HTTP 202 +[Captures] +r_stop: jsonpath "$.request_id" +[Asserts] +jsonpath "$.message" == "stop request created" + +# Wait for the stop to successfully finish +GET http://{{host}}/api/v1/requests/{{r_stop}}/status +Authorization: Bearer {{access_token}} +[Options] +retry: 40 +HTTP 200 +[Asserts] +jsonpath "$.status" == "success" + +PUT http://{{host}}/api/v1/placements/{{uuid}}/start +Authorization: Bearer {{access_token}} +HTTP 202 +[Captures] +r_start: jsonpath "$.request_id" +[Asserts] +jsonpath "$.message" == "start request created" + +# Wait for the start to successfully finish +GET http://{{host}}/api/v1/requests/{{r_start}}/status +Authorization: Bearer {{access_token}} +[Options] +retry: 40 +HTTP 200 +[Asserts] +jsonpath "$.status" == "success" + +GET http://{{host}}/api/v1/placements/{{uuid}}/status +Authorization: Bearer {{access_token}} +HTTP 500 + +PUT http://{{host}}/api/v1/placements/{{uuid}}/status +Authorization: Bearer {{access_token}} +HTTP 202 +[Captures] +r_status: jsonpath "$.request_id" +[Asserts] +jsonpath "$.message" == "status request created" + +# Wait for the status to successfully finish +GET http://{{host}}/api/v1/requests/{{r_status}}/status +Authorization: Bearer {{access_token}} +[Options] +retry: 40 +HTTP 200 +[Asserts] +jsonpath "$.status" == "success" + +# Now get the status again + +GET http://{{host}}/api/v1/placements/{{uuid}}/status +Authorization: Bearer {{access_token}} +HTTP 200 +[Asserts] +jsonpath "$.status" count == 1 +jsonpath "$.status[0].account_name" == "{{account}}" +jsonpath "$.status[0].account_kind" == "aws_account" +jsonpath "$.status[0].status" == "success" + +# Start right before deleting the placement + +PUT http://{{host}}/api/v1/placements/{{uuid}}/start +Authorization: Bearer {{access_token}} +HTTP 202 +[Captures] +r_start: jsonpath "$.request_id" +[Asserts] +jsonpath "$.message" == "start request created" + +DELETE http://{{host}}/api/v1/placements/{{uuid}} +Authorization: Bearer {{access_token}} +HTTP 200 + +# Ensure request doesn't exist +GET http://{{host}}/api/v1/requests/{{r_stop}}/status +Authorization: Bearer {{access_token}} +HTTP 404 + +# Ensure request doesn't exist +GET http://{{host}}/api/v1/requests/{{r_start}}/status +Authorization: Bearer {{access_token}} +HTTP 404 + +# Ensure placement doesn't exist +GET http://{{host}}/api/v1/placements/{{uuid}} +Authorization: Bearer {{access_token}} +HTTP 404 diff --git a/tests/999.hurl b/tests/999.hurl new file mode 100644 index 00000000..e80b936a --- /dev/null +++ b/tests/999.hurl @@ -0,0 +1,11 @@ +GET http://{{host}}/api/v1/login +Authorization: Bearer {{login_token}} +HTTP 200 +[Captures] +access_token: jsonpath "$.access_token" + +DELETE http://{{host}}/api/v1/placements/{{uuid}} +Authorization: Bearer {{access_token}} +[Options] +retry: 40 +HTTP 404 diff --git a/tests/readme.adoc b/tests/readme.adoc new file mode 100644 index 00000000..f8e544e4 --- /dev/null +++ b/tests/readme.adoc @@ -0,0 +1,34 @@ +== Functional tests == + +See link:https://hurl.dev/[hurl.dev] for upstream documentation. + + +.Run local tests +---- +make run-api + +uuid=$(uuidgen) + +hurl --test \ + --variable login_token=... \ + --variable host=localhost:8080 \ + --variable uuid=$uuid \ + *.hurl +---- + +.Example output +---- +000.hurl: Running [1/2] +000.hurl: Success (36 request(s) in 35304 ms) +999.hurl: Running [2/2] +999.hurl: Success (2 request(s) in 371 ms) +-------------------------------------------------------------------------------- +Executed files: 2 +Succeeded files: 2 (100.0%) +Failed files: 0 (0.0%) +Duration: 35680 ms +---- + +=== Troubleshoot === + +Add the `--verbose` argument to the `hurl` command to see the full requests.