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 trace based testing examples #877

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
fc1005a
Adding a user purchasing product trace-based test case
danielbdias May 4, 2023
dbedfd6
Adding more tests
danielbdias May 4, 2023
5f31c6d
Adding run script
danielbdias May 4, 2023
d2d9d06
Fixed yaml lint issues
danielbdias May 4, 2023
32c0e72
Adding license header to the files
danielbdias May 4, 2023
d129654
Adding trace-based tests for more services
danielbdias May 11, 2023
804ef19
Updating tests and adding them on the same format as the integration …
danielbdias May 12, 2023
5eb055a
Fixed payment tests
danielbdias May 12, 2023
4080548
Fixing e2e web tests
danielbdias May 13, 2023
ddd9912
Fixing details found by yamllint
danielbdias May 15, 2023
43a6eeb
Updating trace-based tests to refer a protobuf file instead of embedd…
danielbdias Jun 5, 2023
b4f896d
Fixed data types for email test and improved test time
danielbdias Jun 5, 2023
c52d03b
Structured tests per service
danielbdias Jun 24, 2023
02d7f7b
Added tests for frontend service following endpoints used on loadgene…
danielbdias Jun 24, 2023
2bd7c5f
Merge branch 'main' into add/trace-based-testing-examples
danielbdias Jun 26, 2023
6725bbd
fixing yaml lint issues
danielbdias Jun 26, 2023
14e2ea6
Merge branch 'main' into add/trace-based-testing-examples
danielbdias Jul 6, 2023
5dbcec2
Merge branch 'main' into add/trace-based-testing-examples
danielbdias Jul 10, 2023
d60eebd
Merge branch 'main' into add/trace-based-testing-examples
danielbdias Jul 10, 2023
72d2cdd
Fixing small issues on tests
danielbdias Jul 10, 2023
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
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,10 @@ build-env-file:
run-tests:
docker compose run frontendTests
docker compose run integrationTests
docker compose run traceBasedTests

run-tracetesting:
docker compose run traceBasedTests

.PHONY: generate-protobuf
generate-protobuf:
Expand Down
96 changes: 96 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -740,3 +740,99 @@ services:
- recommendationservice
- shippingservice
- quoteservice

# Tracebased Tests
traceBasedTests:
image: ${IMAGE_NAME}:${IMAGE_VERSION}-traceBasedTests
container_name: traceBasedTests
profiles:
- tests
build:
context: ./
dockerfile: ./test/tracetesting/Dockerfile
environment:
- AD_SERVICE_ADDR
- CART_SERVICE_ADDR
- CHECKOUT_SERVICE_ADDR
- CURRENCY_SERVICE_ADDR
- EMAIL_SERVICE_ADDR
- FRONTEND_ADDR
- PAYMENT_SERVICE_ADDR
- PRODUCT_CATALOG_SERVICE_ADDR
- RECOMMENDATION_SERVICE_ADDR
- SHIPPING_SERVICE_ADDR
extra_hosts:
- "host.docker.internal:host-gateway"
depends_on:
tracetest-server:
condition: service_healthy
# adding demo services as dependencies
frontend:
condition: service_started
adservice:
condition: service_started
cartservice:
condition: service_started
checkoutservice:
condition: service_started
currencyservice:
condition: service_started
emailservice:
condition: service_started
paymentservice:
condition: service_started
productcatalogservice:
condition: service_started
recommendationservice:
condition: service_started
shippingservice:
condition: service_started
quoteservice:
condition: service_started

tracetest-server:
image: kubeshop/tracetest:latest
platform: linux/amd64
container_name: tracetest-server
profiles:
- tests
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
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
profiles:
- tests
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
4 changes: 2 additions & 2 deletions src/frontend/cypress/e2e/Home.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@ describe('Home Page', () => {

it('should validate the home page', () => {
getElementByField(CypressFields.HomePage).should('exist');
getElementByField(CypressFields.ProductCard, getElementByField(CypressFields.ProductList)).should('have.length', 9);
getElementByField(CypressFields.ProductCard, getElementByField(CypressFields.ProductList)).should('have.length', 10);

getElementByField(CypressFields.SessionId).should('contain', SessionGateway.getSession().userId);
});

it('should change currency', () => {
getElementByField(CypressFields.CurrencySwitcher).select('EUR');
getElementByField(CypressFields.ProductCard, getElementByField(CypressFields.ProductList)).should('have.length', 9);
getElementByField(CypressFields.ProductCard, getElementByField(CypressFields.ProductList)).should('have.length', 10);

getElementByField(CypressFields.CurrencySwitcher).should('have.value', 'EUR');

Expand Down
4 changes: 2 additions & 2 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ test("payment: expired credit card", (t) => {

test("product: list", async (t) => {
const res = await productList({});
t.is(res.products.length, 9);
t.is(res.products.length, 10);
});

test("product: get", async (t) => {
Expand Down Expand Up @@ -283,7 +283,7 @@ test("recommendation: list products", async (t) => {
const req = deepCopy(data.recommend);

const res = await recommend(req);
t.is(res.productIds.length, 4);
t.is(res.productIds.length, 5);
t.is(arrayIntersection(res.productIds, req.productIds).length, 0);
});

Expand Down
17 changes: 17 additions & 0 deletions test/tracetesting/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Copyright The OpenTelemetry Authors
# SPDX-License-Identifier: Apache-2.0


FROM alpine

WORKDIR /app

RUN apk --update add bash jq curl
RUN curl -L https://raw.githubusercontent.com/kubeshop/tracetest/main/install-cli.sh | bash

COPY ./test/tracetesting ./test/tracetesting
COPY ./pb ./pb

WORKDIR /app/test/tracetesting

CMD ["/bin/sh", "/app/test/tracetesting/run.bash"]
10 changes: 10 additions & 0 deletions test/tracetesting/ad-service/all.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Copyright The OpenTelemetry Authors
# SPDX-License-Identifier: Apache-2.0

type: Transaction
spec:
id: ad-service-all
name: 'Ad Service'
description: Run all Ad Service tests enabled in sequence
steps:
- ./get.yaml
28 changes: 28 additions & 0 deletions test/tracetesting/ad-service/get.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Copyright The OpenTelemetry Authors
# SPDX-License-Identifier: Apache-2.0

type: Test
spec:
id: ad-get-ads
name: 'Ad: get'
description: Get Ads from API
trigger:
type: grpc
grpc:
protobufFile: ../../../pb/demo.proto
address: ${env:AD_SERVICE_ADDR}
method: oteldemo.AdService.GetAds
request: |-
{
"contextKeys": [ "galaxy", "telescope" ]
}
specs:
- 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
- name: It returns a valid redirectUrl for each ads
selector: span[tracetest.span.type="general" name="Tracetest trigger"]
assertions:
- attr:tracetest.response.body | json_path '$.ads[0].redirectUrl' contains "/product/"
- attr:tracetest.response.body | json_path '$.ads[1].redirectUrl' contains "/product/"
35 changes: 35 additions & 0 deletions test/tracetesting/cart-service/add-item-to-cart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# Copyright The OpenTelemetry Authors
# SPDX-License-Identifier: Apache-2.0

type: Test
spec:
id: cart-add-item-to-cart
name: 'Cart: add item to cart'
description: Add one item to the shopping cart
trigger:
type: grpc
grpc:
protobufFile: ../../../pb/demo.proto
address: ${env:CART_SERVICE_ADDR}
method: oteldemo.CartService.AddItem
request: |-
{
"userId": "1234",
"item": {
"productId": "OLJCESPC7Z",
"quantity": 1
}
}
specs:
- name: It added an item correctly into the shopping cart
selector: span[name="oteldemo.CartService/AddItem"]
assertions:
- attr:rpc.grpc.status_code = 0
- 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 1234"
- name: It returned an empty cart
selector: span[tracetest.span.type="general" name="Tracetest trigger"]
assertions:
- "attr:tracetest.response.body = '{\n \n}'"
14 changes: 14 additions & 0 deletions test/tracetesting/cart-service/all.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Copyright The OpenTelemetry Authors
# SPDX-License-Identifier: Apache-2.0

type: Transaction
spec:
id: cart-all
name: 'Cart Service'
description: Run all Cart tests enabled in sequence
steps:
- ./empty-cart.yaml
- ./add-item-to-cart.yaml
- ./check-if-cart-is-populated.yaml
- ./empty-cart.yaml
- ./check-if-cart-is-empty.yaml
27 changes: 27 additions & 0 deletions test/tracetesting/cart-service/check-if-cart-is-empty.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: cart-check-if-cart-is-empty
name: 'Cart: check if cart is empty'
description: Check if the shopping cart has no items
trigger:
type: grpc
grpc:
protobufFile: ../../../pb/demo.proto
address: ${env:CART_SERVICE_ADDR}
method: oteldemo.CartService.GetCart
request: |-
{
"userId": "1234"
}
specs:
- name: It retrieved the cart items correctly
selector: span[name="oteldemo.CartService/GetCart"]
assertions:
- attr:rpc.grpc.status_code = 0
- name: It returned no items
selector: span[tracetest.span.type="general" name="Tracetest trigger"]
assertions:
- attr:tracetest.response.body | json_path '$.items' = "[]"
28 changes: 28 additions & 0 deletions test/tracetesting/cart-service/check-if-cart-is-populated.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Copyright The OpenTelemetry Authors
# SPDX-License-Identifier: Apache-2.0

type: Test
spec:
id: cart-check-if-cart-is-populated
name: 'Cart: check if cart is populated'
description: Check if the shopping cart has one item
trigger:
type: grpc
grpc:
protobufFile: ../../../pb/demo.proto
address: ${env:CART_SERVICE_ADDR}
method: oteldemo.CartService.GetCart
request: |-
{
"userId": "1234"
}
specs:
- name: It retrieved the cart items correctly
selector: span[name="oteldemo.CartService/GetCart"]
assertions:
- attr:rpc.grpc.status_code = 0
- name: It returned the first item with correct attributes
selector: span[tracetest.span.type="general" name="Tracetest trigger"]
assertions:
- attr:tracetest.response.body | json_path '$.items[0].quantity' = 1
- attr:tracetest.response.body | json_path '$.items[0].productId' = "OLJCESPC7Z"
27 changes: 27 additions & 0 deletions test/tracetesting/cart-service/empty-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: cart-empty-cart
name: 'Cart: empty cart'
description: Clean shopping cart
trigger:
type: grpc
grpc:
protobufFile: ../../../pb/demo.proto
address: ${env:CART_SERVICE_ADDR}
method: oteldemo.CartService.EmptyCart
request: |-
{
"userId": "1234"
}
specs:
- name: It emptied the shopping cart with success
selector: span[name="oteldemo.CartService/EmptyCart"]
assertions:
- attr:rpc.grpc.status_code = 0
- name: It sent cleaning message to the database
selector: span[tracetest.span.type="database" name="EXPIRE" db.system="redis" db.redis.database_index="0"]
assertions:
- attr:db.statement = "EXPIRE 1234"
10 changes: 10 additions & 0 deletions test/tracetesting/checkout-service/all.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Copyright The OpenTelemetry Authors
# SPDX-License-Identifier: Apache-2.0

type: Transaction
spec:
id: checkout-service-all
name: 'Checkout Service'
description: Run all Checkout Service tests enabled in sequence
steps:
- ./place-order.yaml
46 changes: 46 additions & 0 deletions test/tracetesting/checkout-service/place-order.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# Copyright The OpenTelemetry Authors
# SPDX-License-Identifier: Apache-2.0

type: Test
spec:
id: checkout-place-order
name: 'Checkout: place order'
description: Place one order on the system
trigger:
type: grpc
grpc:
protobufFile: ../../../pb/demo.proto
address: ${env:CHECKOUT_SERVICE_ADDR}
method: oteldemo.CheckoutService.PlaceOrder
request: |-
{
"userId": "1997",
"userCurrency": "USD",
"address": {
"streetAddress": "410 Terry Ave. North",
"city": "Seattle",
"state": "Washington",
"country": "United States",
"zipCode": "98109"
},
"email": "[email protected]",
"creditCard": {
"creditCardNumber": "4117-7059-6121-5486",
"creditCardCvv": 346,
"creditCardExpirationYear": 2025,
"creditCardExpirationMonth": 3
}
}
specs:
- name: It returns a valid order
selector: span[tracetest.span.type="general" name="Tracetest trigger"]
assertions:
- attr:tracetest.response.body | json_path '$.order.orderId' != ""
- attr:tracetest.response.body | json_path '$.order.shippingTrackingId' != ""
- attr:tracetest.response.body | json_path '$.order.shippingAddress' != "{}"
- attr:tracetest.response.body | json_path '$.order.shippingCost.currencyCode' = "USD"
- name: It calls the PlaceOrder method successfuly
selector: span[tracetest.span.type="rpc" name="oteldemo.CheckoutService/PlaceOrder"
rpc.system="grpc" rpc.method="PlaceOrder" rpc.service="oteldemo.CheckoutService"]
assertions:
- attr:rpc.grpc.status_code = 0
Loading