Skip to content

Commit

Permalink
Adding a user purchasing product trace-based test case
Browse files Browse the repository at this point in the history
  • Loading branch information
danielbdias committed Jun 22, 2023
1 parent 846ae2d commit fc1005a
Show file tree
Hide file tree
Showing 8 changed files with 194 additions and 0 deletions.
76 changes: 76 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -712,3 +712,79 @@ services:
- recommendationservice
- shippingservice
- quoteservice

# Tracebased Tests
tracetest-server:
image: kubeshop/tracetest:latest
platform: linux/amd64
container_name: tracetest-server
volumes:
- type: bind
source: ./test/tracetesting/tracetest-config.yaml
target: /app/tracetest.yaml
- type: bind
source: ./test/tracetesting/tracetest-provision.yaml
target: /app/provision.yaml
command: --provisioning-file /app/provision.yaml
ports:
- 11633:11633
extra_hosts:
- "host.docker.internal:host-gateway"
depends_on:
tracetest-postgres:
condition: service_healthy
otelcol:
condition: service_started
# adding demo services as dependencies
accountingservice:
condition: service_started
adservice:
condition: service_started
cartservice:
condition: service_started
checkoutservice:
condition: service_started
currencyservice:
condition: service_started
emailservice:
condition: service_started
featureflagservice:
condition: service_started
frauddetectionservice:
condition: service_started
frontend:
condition: service_started
frontendproxy:
condition: service_started
paymentservice:
condition: service_started
productcatalogservice:
condition: service_started
quoteservice:
condition: service_started
recommendationservice:
condition: service_started
shippingservice:
condition: service_started

healthcheck:
test: [ "CMD", "wget", "--spider", "localhost:11633" ]
interval: 1s
timeout: 3s
retries: 60
environment:
TRACETEST_DEV: ${TRACETEST_DEV}

tracetest-postgres:
image: postgres:14
container_name: tracetest-postgres
environment:
POSTGRES_PASSWORD: postgres
POSTGRES_USER: postgres
healthcheck:
test: pg_isready -U "$$POSTGRES_USER" -d "$$POSTGRES_DB"
interval: 1s
timeout: 5s
retries: 60
ports:
- 5432
19 changes: 19 additions & 0 deletions test/tracetesting/business-tests/01-add-product-to-cart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
type: Test
spec:
id: add-product
name: Add product to the cart
description: Add a selected product to user shopping cart
trigger:
type: http
httpRequest:
url: ${env:CART_API_URL}
method: POST
headers:
- key: Content-Type
value: application/json
body: '{"item":{"productId":"${env:PRODUCT_ID}","quantity":1},"userId":"${env:USER_ID}"}'
specs:
- name: "The product was persisted correctly on the shopping cart"
selector: span[name="oteldemo.CartService/AddItem"]
assertions:
- attr:app.product.id = "${env:PRODUCT_ID}"
35 changes: 35 additions & 0 deletions test/tracetesting/business-tests/02-checking-out-cart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
type: Test
spec:
id: checkout-shopping-cart
name: Checking out shopping cart
description: Checking out shopping cart
trigger:
type: http
httpRequest:
url: ${env:CHECKOUT_API_URL}
method: POST
headers:
- key: Content-Type
value: application/json
body: '{"userId":"${env:USER_ID}","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:
- 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 = "${env:USER_ID}"
- 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
4 changes: 4 additions & 0 deletions test/tracetesting/business-tests/test-env.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
CART_API_URL: http://frontend:8080/api/cart
CHECKOUT_API_URL: http://frontend:8080/api/checkout
PRODUCT_ID: OLJCESPC7Z
USER_ID: 2491f868-88f1-4345-8836-d5d8511a9f83
8 changes: 8 additions & 0 deletions test/tracetesting/business-tests/user-purchasing-product.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
type: Transaction
spec:
id: user-purchase-product
name: User purchasing products
description: Simulate a process of a user purchasing products on Astronomy store
steps:
- ./01-add-product-to-cart.yaml
- ./02-checking-out-cart.yaml
3 changes: 3 additions & 0 deletions test/tracetesting/cli-config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
scheme: http
endpoint: localhost:11633
analyticsEnabled: false
21 changes: 21 additions & 0 deletions test/tracetesting/tracetest-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
postgres:
host: tracetest-postgres
user: postgres
password: postgres
port: 5432
dbname: postgres
params: sslmode=disable

telemetry:
exporters:
collector:
serviceName: tracetest
sampling: 100 # 100%
exporter:
type: collector
collector:
endpoint: otelcol:4317

server:
telemetry:
exporter: collector
28 changes: 28 additions & 0 deletions test/tracetesting/tracetest-provision.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
---
type: PollingProfile
spec:
name: Default
strategy: periodic
default: true
periodic:
retryDelay: 5s
timeout: 10m

---
type: Demo
spec:
name: "OpenTelemetry Shop"
enabled: true
type: otelstore
opentelemetryStore:
frontendEndpoint: http://frontend:8080

---
type: DataStore
spec:
name: Jaeger
type: jaeger
jaeger:
endpoint: jaeger:16685
tls:
insecure: true

0 comments on commit fc1005a

Please sign in to comment.