Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add initial version of functional tests #35

Merged
merged 1 commit into from
Sep 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
139 changes: 139 additions & 0 deletions tests/000.hurl
Original file line number Diff line number Diff line change
@@ -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
11 changes: 11 additions & 0 deletions tests/999.hurl
Original file line number Diff line number Diff line change
@@ -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
34 changes: 34 additions & 0 deletions tests/readme.adoc
Original file line number Diff line number Diff line change
@@ -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.
Loading