Skip to content

Commit

Permalink
Added tests for frontend service following endpoints used on loadgene…
Browse files Browse the repository at this point in the history
…rator
  • Loading branch information
danielbdias committed Jun 24, 2023
1 parent c52d03b commit 02d7f7b
Show file tree
Hide file tree
Showing 9 changed files with 246 additions and 2 deletions.
36 changes: 36 additions & 0 deletions test/tracetesting/frontend-service/01-see-ads.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# Copyright The OpenTelemetry Authors
# SPDX-License-Identifier: Apache-2.0

type: Test
spec:
id: frontend-see-adds
name: 'Frontend: See Ads'
description: Simulate the user seeing a ads on Astronomy Shop
trigger:
type: http
httpRequest:
url: http://${env:FRONTEND_ADDR}/api/data
method: GET
headers:
- key: Content-Type
value: application/json
body: |
{
"contextKeys": [
"binoculars",
"telescopes",
"accessories"
]
}
specs:
- name: It called the frontend with success and got a valid redirectUrl for each ads
selector: span[tracetest.span.type="general" name="Tracetest trigger"]
assertions:
- attr:tracetest.response.status = 200
- attr:tracetest.response.body | json_path '$[0].redirectUrl' contains "/product/"
- attr:tracetest.response.body | json_path '$[1].redirectUrl' contains "/product/"
- name: It returns two ads
selector: span[tracetest.span.type="rpc" name="oteldemo.AdService/GetAds" rpc.system="grpc" rpc.method="GetAds" rpc.service="oteldemo.AdService"]
assertions:
- attr:app.ads.count = 2

Check failure on line 36 in test/tracetesting/frontend-service/01-see-ads.yaml

View workflow job for this annotation

GitHub Actions / yamllint

36:1 [trailing-spaces] trailing spaces
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# Copyright The OpenTelemetry Authors
# SPDX-License-Identifier: Apache-2.0

type: Test
spec:
id: frontend-get-recommendation
name: 'Frontend: Get recommendations'
description: Simulate the user seeing recomendations on Astronomy Shop
trigger:
type: http
httpRequest:
url: http://${env:FRONTEND_ADDR}/api/recommendations
method: GET
headers:
- key: Content-Type
value: application/json
body: |
{
"productIds":[
"0PUK6V6EV0",
"1YMWWN1N4O",
"2ZYFJ3GM2N",
"66VCHSJNUP",
"6E92ZMYYFZ"
]
}
specs:
- name: It called the frontend with success

Check failure on line 28 in test/tracetesting/frontend-service/02-get-product-recommendation.yaml

View workflow job for this annotation

GitHub Actions / yamllint

28:46 [trailing-spaces] trailing spaces
selector: span[tracetest.span.type="general" name="Tracetest trigger"]
assertions:
- attr:tracetest.response.status = 200
- name: It called ListRecommendations correctly and got 5 products
selector: span[tracetest.span.type="rpc" name="/oteldemo.RecommendationService/ListRecommendations" rpc.system="grpc" rpc.method="ListRecommendations" rpc.service="oteldemo.RecommendationService"]
assertions:
- attr:rpc.grpc.status_code = 0
- attr:app.products_recommended.count = 5
32 changes: 32 additions & 0 deletions test/tracetesting/frontend-service/03-browse-product.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Copyright The OpenTelemetry Authors
# SPDX-License-Identifier: Apache-2.0

type: Test
spec:
id: frontend-browse-product
name: 'Frontend: Browse products'
description: Simulate the user browsing products on Astronomy Shop
trigger:
type: http
httpRequest:
url: http://${env:FRONTEND_ADDR}/api/products/0PUK6V6EV0
method: GET
headers:
- key: Content-Type
value: application/json
specs:
- name: It called the frontend with success and got a product with valid attributes
selector: span[tracetest.span.type="general" name="Tracetest trigger"]
assertions:
- attr:tracetest.response.status = 200
- attr:tracetest.response.body | json_path '$.id' = "0PUK6V6EV0"
- attr:tracetest.response.body | json_path '$.description' != ""
- attr:tracetest.response.body | json_path '$.picture' != ""
- attr:tracetest.response.body | json_path '$.priceUsd' != "{}"
- attr:tracetest.response.body | json_path '$.categories' != "[]"
- name: It queried the product catalog correctly for a specific product
selector: span[tracetest.span.type="rpc" name="oteldemo.ProductCatalogService/GetProduct" rpc.system="grpc" rpc.method="GetProduct" rpc.service="oteldemo.ProductCatalogService"]
assertions:
- attr:rpc.grpc.status_code = 0
- attr:app.product.id = "0PUK6V6EV0"

Check failure on line 32 in test/tracetesting/frontend-service/03-browse-product.yaml

View workflow job for this annotation

GitHub Actions / yamllint

32:1 [trailing-spaces] trailing spaces
38 changes: 38 additions & 0 deletions test/tracetesting/frontend-service/04-add-product-to-cart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# Copyright The OpenTelemetry Authors
# SPDX-License-Identifier: Apache-2.0

type: Test
spec:
id: frontend-add-product
name: 'Frontend: Add product to the cart'
description: Simulate a user adding a selected product to the shopping cart
trigger:
type: http
httpRequest:
url: http://${env:FRONTEND_ADDR}/api/cart
method: POST
headers:
- key: Content-Type
value: application/json
body: |
{
"item": {
"productId": "0PUK6V6EV0",
"quantity": 2
},
"userId": "2491f868-88f1-4345-8836-d5d8511a9f83"
}
specs:
- name: It called the frontend with success
selector: span[tracetest.span.type="general" name="Tracetest trigger"]
assertions:
- attr:tracetest.response.status = 200
- name: It added an item correctly into the shopping cart
selector: span[name="oteldemo.CartService/AddItem"]
assertions:
- attr:rpc.grpc.status_code = 0
- attr:app.product.id = "0PUK6V6EV0"
- name: It set the cart item correctly on the database
selector: span[tracetest.span.type="database" name="HMSET" db.system="redis" db.redis.database_index="0"]
assertions:
- attr:db.statement = "HMSET 2491f868-88f1-4345-8836-d5d8511a9f83"
27 changes: 27 additions & 0 deletions test/tracetesting/frontend-service/05-view-cart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Copyright The OpenTelemetry Authors
# SPDX-License-Identifier: Apache-2.0

type: Test
spec:
id: frontend-view-cart
name: 'Frontend: View cart'
description: Simulate a user viewing the shopping cart
trigger:
type: http
httpRequest:
url: http://${env:FRONTEND_ADDR}/api/cart
method: GET
headers:
- key: Content-Type
value: application/json
specs:
- name: It called the frontend with success and returned the first item with correct attributes
selector: span[tracetest.span.type="general" name="Tracetest trigger"]
assertions:
- attr:tracetest.response.status = 200
- attr:tracetest.response.body | json_path '$.items[0].quantity' = 1
- attr:tracetest.response.body | json_path '$.items[0].productId' = "0PUK6V6EV0"
- name: It retrieved the cart items correctly
selector: span[name="oteldemo.CartService/GetCart"]
assertions:
- attr:rpc.grpc.status_code = 0
60 changes: 60 additions & 0 deletions test/tracetesting/frontend-service/06-checking-out-cart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
# Copyright The OpenTelemetry Authors
# SPDX-License-Identifier: Apache-2.0

type: Test
spec:
id: frontend-checkout-shopping-cart
name: 'Frontend: Checking out shopping cart'
description: Simulate user checking out shopping cart
trigger:
type: http
httpRequest:
url: http://${env:FRONTEND_ADDR}/api/checkout
method: POST
headers:
- key: Content-Type
value: application/json
body: |
{
"userId": "2491f868-88f1-4345-8836-d5d8511a9f83",
"email": "someone@example.com",
"address": {
"streetAddress": "1600 Amphitheatre Parkway",
"state": "CA",
"country": "United States",
"city": "Mountain View",
"zipCode": "94043"
},
"userCurrency": "USD",
"creditCard": {
"creditCardCvv": 672,
"creditCardExpirationMonth": 1,
"creditCardExpirationYear": 2030,
"creditCardNumber": "4432-8015-6152-0454"
}
}
specs:
- name: It called the frontend with success
selector: span[tracetest.span.type="general" name="Tracetest trigger"]
assertions:
- attr:tracetest.response.status = 200
- selector: span[tracetest.span.type="rpc" name="oteldemo.CheckoutService/PlaceOrder" rpc.system="grpc" rpc.method="PlaceOrder" rpc.service="oteldemo.CheckoutService"]
name: "The order was placed"
assertions:
- attr:app.user.id = "2491f868-88f1-4345-8836-d5d8511a9f83"
- attr:app.order.items.count = 1
- selector: span[tracetest.span.type="rpc" name="oteldemo.PaymentService/Charge" rpc.system="grpc" rpc.method="Charge" rpc.service="oteldemo.PaymentService"]
name: "The user was charged"
assertions:
- attr:rpc.grpc.status_code = 0
- attr:tracetest.selected_spans.count >= 1
- selector: span[tracetest.span.type="rpc" name="oteldemo.ShippingService/ShipOrder" rpc.system="grpc" rpc.method="ShipOrder" rpc.service="oteldemo.ShippingService"]
name: "The product was shipped"
assertions:
- attr:rpc.grpc.status_code = 0
- attr:tracetest.selected_spans.count >= 1
- selector: span[tracetest.span.type="rpc" name="oteldemo.CartService/EmptyCart" rpc.system="grpc" rpc.method="EmptyCart" rpc.service="oteldemo.CartService"]
name: "The cart was emptied"
assertions:
- attr:rpc.grpc.status_code = 0
- attr:tracetest.selected_spans.count >= 1
15 changes: 15 additions & 0 deletions test/tracetesting/frontend-service/all.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Copyright The OpenTelemetry Authors
# SPDX-License-Identifier: Apache-2.0

type: Transaction
spec:
id: frontend-all
name: 'Frontend Service'
description: Run all Frontend tests enabled in sequence, simulating a process of a user purchasing products on Astronomy store
steps:
- ./01-see-ads.yaml
- ./02-get-product-recommendation.yaml
- ./03-browse-product.yaml
- ./04-add-product-to-cart.yaml
- ./05-see-cart.yaml
- ./06-checking-out-cart.yaml
3 changes: 1 addition & 2 deletions test/tracetesting/recommendation-service/list.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@ spec:
}
specs:
- name: It called ListRecommendations correctly and got 5 products
selector: span[tracetest.span.type="rpc" name="/oteldemo.RecommendationService/ListRecommendations"
rpc.system="grpc" rpc.method="ListRecommendations" rpc.service="oteldemo.RecommendationService"]
selector: span[tracetest.span.type="rpc" name="/oteldemo.RecommendationService/ListRecommendations" rpc.system="grpc" rpc.method="ListRecommendations" rpc.service="oteldemo.RecommendationService"]
assertions:
- attr:rpc.grpc.status_code = 0
- attr:app.products_recommended.count = 5
1 change: 1 addition & 0 deletions test/tracetesting/run.bash
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ run_tracetest ad-service || EXIT_STATUS=$?
run_tracetest cart-service || EXIT_STATUS=$?
run_tracetest currency-service || EXIT_STATUS=$?
run_tracetest checkout-service || EXIT_STATUS=$?
run_tracetest frontend-service || EXIT_STATUS=$?
run_tracetest email-service || EXIT_STATUS=$?
run_tracetest payment-service || EXIT_STATUS=$?
run_tracetest product-catalog-service || EXIT_STATUS=$?
Expand Down

0 comments on commit 02d7f7b

Please sign in to comment.