Skip to content

Commit

Permalink
Updating tests and adding them on the same format as the integration …
Browse files Browse the repository at this point in the history
…tests
  • Loading branch information
danielbdias committed Jun 22, 2023
1 parent d129654 commit 804ef19
Show file tree
Hide file tree
Showing 22 changed files with 2,518 additions and 37 deletions.
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
32 changes: 20 additions & 12 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -714,10 +714,25 @@ services:
- quoteservice

# Tracebased Tests
traceBasedTests:
image: ${IMAGE_NAME}:${IMAGE_VERSION}-traceBasedTests
container_name: traceBasedTests
profiles:
- tests
build:
context: ./
dockerfile: ./test/tracetesting/Dockerfile
extra_hosts:
- "host.docker.internal:host-gateway"
depends_on:
- tracetest-server

tracetest-server:
image: kubeshop/tracetest:latest
platform: linux/amd64
container_name: tracetest-server
profiles:
- tests
volumes:
- type: bind
source: ./test/tracetesting/tracetest-config.yaml
Expand All @@ -736,7 +751,7 @@ services:
otelcol:
condition: service_started
# adding demo services as dependencies
accountingservice:
frontend:
condition: service_started
adservice:
condition: service_started
Expand All @@ -748,25 +763,16 @@ services:
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

quoteservice:
condition: service_started
healthcheck:
test: [ "CMD", "wget", "--spider", "localhost:11633" ]
interval: 1s
Expand All @@ -778,6 +784,8 @@ services:
tracetest-postgres:
image: postgres:14
container_name: tracetest-postgres
profiles:
- tests
environment:
POSTGRES_PASSWORD: postgres
POSTGRES_USER: postgres
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
14 changes: 14 additions & 0 deletions test/tracetesting/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# 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 ./

CMD ["/bin/sh", "/app/run.bash"]
2 changes: 1 addition & 1 deletion test/tracetesting/cli-config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
# SPDX-License-Identifier: Apache-2.0

scheme: http
endpoint: localhost:11633
endpoint: tracetest-server:11633
analyticsEnabled: false
7 changes: 7 additions & 0 deletions test/tracetesting/run.bash
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,13 @@ run_tracetest ./tech-based-tests/payment-service/valid-credit-card.yaml || EXIT_
run_tracetest ./tech-based-tests/payment-service/invalid-credit-card.yaml || EXIT_STATUS=$?
run_tracetest ./tech-based-tests/payment-service/amex-credit-card-not-allowed.yaml || EXIT_STATUS=$?
run_tracetest ./tech-based-tests/payment-service/expired-credit-card.yaml || EXIT_STATUS=$?
run_tracetest ./tech-based-tests/product-catalog-service/list.yaml || EXIT_STATUS=$?
run_tracetest ./tech-based-tests/product-catalog-service/get.yaml || EXIT_STATUS=$?
run_tracetest ./tech-based-tests/product-catalog-service/search.yaml || EXIT_STATUS=$?
run_tracetest ./tech-based-tests/recommendation-service/list.yaml || EXIT_STATUS=$?
run_tracetest ./tech-based-tests/shipping-service/quote.yaml || EXIT_STATUS=$?
run_tracetest ./tech-based-tests/shipping-service/empty-quote.yaml || EXIT_STATUS=$?
run_tracetest ./tech-based-tests/shipping-service/order.yaml || EXIT_STATUS=$?

# run business tests
echo ""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@ spec:
}
specs:
- name: It added an item correctly into the shopping cart
selector: span[tracetest.span.type="rpc" name="oteldemo.CartService/AddItem" rpc.system="grpc" rpc.method="AddItem" rpc.service="oteldemo.CartService"]
selector: span[tracetest.span.type="http" name="oteldemo.CartService/AddItem" http.target="/oteldemo.CartService/AddItem" http.method="POST"]
assertions:
- attr:http.status_code = 200
- name: It set the cart item correctly on the database
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@ spec:
}
specs:
- name: It retrieved the cart items correctly
selector: span[tracetest.span.type="rpc" name="oteldemo.CartService/GetCart" rpc.system="grpc" rpc.method="GetCart" rpc.service="oteldemo.CartService"]
selector: span[tracetest.span.type="http" name="oteldemo.CartService/GetCart" http.target="/oteldemo.CartService/GetCart" http.method="POST"]
assertions:
- attr:http.status_code = 200
- name: It returned no items
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -337,8 +337,7 @@ spec:
}
specs:
- name: It retrieved the cart items correctly
selector: span[tracetest.span.type="http" name="oteldemo.CartService/GetCart"
http.target="/oteldemo.CartService/GetCart" http.method="POST"]
selector: span[tracetest.span.type="http" name="oteldemo.CartService/GetCart" http.target="/oteldemo.CartService/GetCart" http.method="POST"]
assertions:
- attr:http.status_code = 200
- name: It returned the first item with correct attributes
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -337,8 +337,7 @@ spec:
}
specs:
- name: It emptied the shopping cart with success
selector: span[tracetest.span.type="http" name="oteldemo.CartService/EmptyCart"
http.target="/oteldemo.CartService/EmptyCart" http.method="POST"]
selector: span[tracetest.span.type="rpc" name="oteldemo.CartService/EmptyCart" rpc.system="grpc" rpc.method="EmptyCart" rpc.service="oteldemo.CartService"]
assertions:
- attr:rpc.grpc.status_code = 0
- name: It sent cleaning message to the database
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ spec:
headers:
- key: Content-Type
value: application/json
body: |
body: |-
{
"email": "google@example.com",
"order": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -347,12 +347,7 @@ spec:
}
specs:
- name: It should call Charge method and receive a gRPC error
selector: span[tracetest.span.type="rpc" name="grpc.oteldemo.PaymentService/Charge"
rpc.system="grpc" rpc.method="Charge" rpc.service="oteldemo.PaymentService"]
selector: span[tracetest.span.type="rpc" name="grpc.oteldemo.PaymentService/Charge" rpc.system="grpc" rpc.method="Charge" rpc.service="oteldemo.PaymentService"]
assertions:
- attr:rpc.grpc.status_code = 2
- name: It should receive an invalid credit card message
selector: span[tracetest.span.type="rpc" name="grpc.oteldemo.PaymentService/Charge"
rpc.system="grpc" rpc.method="Charge" rpc.service="oteldemo.PaymentService"]
assertions:
- attr:grpc.error_message = "Sorry, we cannot process amex credit cards. Only VISA or MasterCard is accepted."
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@ spec:
"creditCard": {
"creditCardNumber": "0000-0000-0000-0000",
"creditCardCvv": 672,
"creditCardExpirationYear": 2039,
"creditCardExpirationYear": 2021,
"creditCardExpirationMonth": 1
}
}
Expand All @@ -350,7 +350,4 @@ spec:
selector: span[tracetest.span.type="rpc" name="grpc.oteldemo.PaymentService/Charge" rpc.system="grpc" rpc.method="Charge" rpc.service="oteldemo.PaymentService"]
assertions:
- attr:rpc.grpc.status_code = 2
- name: It should receive an invalid credit card message
selector: span[tracetest.span.type="rpc" name="grpc.oteldemo.PaymentService/Charge" rpc.system="grpc" rpc.method="Charge" rpc.service="oteldemo.PaymentService"]
assertions:
- attr:grpc.error_message = "The credit card (ending 0454) expired on 1/2021."
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,4 @@ spec:
selector: span[tracetest.span.type="rpc" name="grpc.oteldemo.PaymentService/Charge" rpc.system="grpc" rpc.method="Charge" rpc.service="oteldemo.PaymentService"]
assertions:
- attr:rpc.grpc.status_code = 2
- name: It should receive an invalid credit card message
selector: span[tracetest.span.type="rpc" name="grpc.oteldemo.PaymentService/Charge" rpc.system="grpc" rpc.method="Charge" rpc.service="oteldemo.PaymentService"]
assertions:
- attr:grpc.error_message = "Credit card info is invalid."
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@ spec:
"creditCard": {
"creditCardNumber": "4432-8015-6152-0454",
"creditCardCvv": 672,
"creditCardExpirationYear": 2021,
"creditCardExpirationYear": 2039,
"creditCardExpirationMonth": 1
}
}
Expand All @@ -353,4 +353,4 @@ spec:
- name: It should return a transaction ID
selector: span[tracetest.span.type="general" name="Tracetest trigger"]
assertions:
- attr:tracetest.response.body| json_path '$.transactionId' != ""
- attr:tracetest.response.body | json_path '$.transactionId' != ""
Loading

0 comments on commit 804ef19

Please sign in to comment.