From d1296545a3d59e1859954e3319125c244e032638 Mon Sep 17 00:00:00 2001 From: Daniel Dias Date: Thu, 11 May 2023 17:42:53 -0300 Subject: [PATCH] Adding trace-based tests for more services --- .../business-tests/environment-vars.env | 4 - .../01-add-product-to-cart.yaml | 6 +- .../02-checking-out-cart.yaml | 6 +- test/tracetesting/run.bash | 23 +- .../{ad-get.yaml => ad-service/get.yaml} | 0 .../cart-service/add-item-to-cart.yaml | 354 +++++++++++++++++ .../tech-based-tests/cart-service/all.yaml | 15 + .../cart-service/check-if-cart-is-empty.yaml | 346 +++++++++++++++++ .../check-if-cart-is-populated.yaml | 348 +++++++++++++++++ .../cart-service/empty-cart.yaml | 348 +++++++++++++++++ .../checkout-service/place-order.yaml | 365 ++++++++++++++++++ .../convert.yaml} | 2 +- .../supported.yaml} | 0 .../email-service/confirmation.yaml | 62 +++ .../amex-credit-card-not-allowed.yaml | 358 +++++++++++++++++ .../payment-service/expired-credit-card.yaml | 356 +++++++++++++++++ .../payment-service/invalid-credit-card.yaml | 356 +++++++++++++++++ .../payment-service/valid-credit-card.yaml | 356 +++++++++++++++++ 18 files changed, 3282 insertions(+), 23 deletions(-) delete mode 100644 test/tracetesting/business-tests/environment-vars.env rename test/tracetesting/tech-based-tests/{ad-get.yaml => ad-service/get.yaml} (100%) create mode 100644 test/tracetesting/tech-based-tests/cart-service/add-item-to-cart.yaml create mode 100644 test/tracetesting/tech-based-tests/cart-service/all.yaml create mode 100644 test/tracetesting/tech-based-tests/cart-service/check-if-cart-is-empty.yaml create mode 100644 test/tracetesting/tech-based-tests/cart-service/check-if-cart-is-populated.yaml create mode 100644 test/tracetesting/tech-based-tests/cart-service/empty-cart.yaml create mode 100644 test/tracetesting/tech-based-tests/checkout-service/place-order.yaml rename test/tracetesting/tech-based-tests/{currency-convert.yaml => currency-service/convert.yaml} (99%) rename test/tracetesting/tech-based-tests/{currency-supported.yaml => currency-service/supported.yaml} (100%) create mode 100644 test/tracetesting/tech-based-tests/email-service/confirmation.yaml create mode 100644 test/tracetesting/tech-based-tests/payment-service/amex-credit-card-not-allowed.yaml create mode 100644 test/tracetesting/tech-based-tests/payment-service/expired-credit-card.yaml create mode 100644 test/tracetesting/tech-based-tests/payment-service/invalid-credit-card.yaml create mode 100644 test/tracetesting/tech-based-tests/payment-service/valid-credit-card.yaml diff --git a/test/tracetesting/business-tests/environment-vars.env b/test/tracetesting/business-tests/environment-vars.env deleted file mode 100644 index e0f9104acb..0000000000 --- a/test/tracetesting/business-tests/environment-vars.env +++ /dev/null @@ -1,4 +0,0 @@ -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 \ No newline at end of file diff --git a/test/tracetesting/business-tests/user-purchase-test-steps/01-add-product-to-cart.yaml b/test/tracetesting/business-tests/user-purchase-test-steps/01-add-product-to-cart.yaml index 8e1d3a160b..0eca6910f2 100644 --- a/test/tracetesting/business-tests/user-purchase-test-steps/01-add-product-to-cart.yaml +++ b/test/tracetesting/business-tests/user-purchase-test-steps/01-add-product-to-cart.yaml @@ -9,14 +9,14 @@ spec: trigger: type: http httpRequest: - url: ${env:CART_API_URL} + url: http://frontend:8080/api/cart method: POST headers: - key: Content-Type value: application/json - body: '{"item":{"productId":"${env:PRODUCT_ID}","quantity":1},"userId":"${env:USER_ID}"}' + body: '{"item":{"productId":"OLJCESPC7Z","quantity":1},"userId":"2491f868-88f1-4345-8836-d5d8511a9f83"}' 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}" + - attr:app.product.id = "OLJCESPC7Z" diff --git a/test/tracetesting/business-tests/user-purchase-test-steps/02-checking-out-cart.yaml b/test/tracetesting/business-tests/user-purchase-test-steps/02-checking-out-cart.yaml index 937f7e8b32..e80f6eba99 100644 --- a/test/tracetesting/business-tests/user-purchase-test-steps/02-checking-out-cart.yaml +++ b/test/tracetesting/business-tests/user-purchase-test-steps/02-checking-out-cart.yaml @@ -9,14 +9,14 @@ spec: trigger: type: http httpRequest: - url: ${env:CHECKOUT_API_URL} + url: http://frontend:8080/api/checkout method: POST headers: - key: Content-Type value: application/json body: | { - "userId": "${env:USER_ID}", + "userId": "2491f868-88f1-4345-8836-d5d8511a9f83", "email": "someone@example.com", "address": { "streetAddress": "1600 Amphitheatre Parkway", @@ -37,7 +37,7 @@ spec: - 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.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" diff --git a/test/tracetesting/run.bash b/test/tracetesting/run.bash index 628ee32d79..b73dadb508 100755 --- a/test/tracetesting/run.bash +++ b/test/tracetesting/run.bash @@ -22,14 +22,6 @@ run_tracetest() { return $? } -run_tracetest_with_env() { - test_file=$1 - env_file=$2 - - tracetest -c ./cli-config.yml test run -d $test_file --environment $env_file -w - return $? -} - check_if_tracetest_is_installed echo "Starting tests..." @@ -39,14 +31,21 @@ EXIT_STATUS=0 # run tech based tests echo "" echo "Running tech based tests..." -run_tracetest ./tech-based-tests/ad-get.yaml || EXIT_STATUS=$? -run_tracetest ./tech-based-tests/currency-convert.yaml || EXIT_STATUS=$? -run_tracetest ./tech-based-tests/currency-supported.yaml || EXIT_STATUS=$? +run_tracetest ./tech-based-tests/ad-service/get.yaml || EXIT_STATUS=$? +run_tracetest ./tech-based-tests/cart-service/all.yaml || EXIT_STATUS=$? +run_tracetest ./tech-based-tests/currency-service/convert.yaml || EXIT_STATUS=$? +run_tracetest ./tech-based-tests/currency-service/supported.yaml || EXIT_STATUS=$? +run_tracetest ./tech-based-tests/checkout-service/place-order.yaml || EXIT_STATUS=$? +run_tracetest ./tech-based-tests/email-service/confirmation.yaml || EXIT_STATUS=$? +run_tracetest ./tech-based-tests/payment-service/valid-credit-card.yaml || EXIT_STATUS=$? +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 business tests echo "" echo "Running business based tests..." -run_tracetest_with_env ./business-tests/user-purchase.yaml ./business-tests/environment-vars.env || EXIT_STATUS=$? +run_tracetest ./business-tests/user-purchase.yaml || EXIT_STATUS=$? echo "" echo "Tests done! Exit code: $EXIT_STATUS" diff --git a/test/tracetesting/tech-based-tests/ad-get.yaml b/test/tracetesting/tech-based-tests/ad-service/get.yaml similarity index 100% rename from test/tracetesting/tech-based-tests/ad-get.yaml rename to test/tracetesting/tech-based-tests/ad-service/get.yaml diff --git a/test/tracetesting/tech-based-tests/cart-service/add-item-to-cart.yaml b/test/tracetesting/tech-based-tests/cart-service/add-item-to-cart.yaml new file mode 100644 index 0000000000..280c252012 --- /dev/null +++ b/test/tracetesting/tech-based-tests/cart-service/add-item-to-cart.yaml @@ -0,0 +1,354 @@ +# 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: | + // Copyright 2020 Google LLC + // + // Licensed under the Apache License, Version 2.0 (the "License"); + // you may not use this file except in compliance with the License. + // You may obtain a copy of the License at + // + // http://www.apache.org/licenses/LICENSE-2.0 + // + // Unless required by applicable law or agreed to in writing, software + // distributed under the License is distributed on an "AS IS" BASIS, + // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + // See the License for the specific language governing permissions and + // limitations under the License. + + syntax = "proto3"; + + import "google/protobuf/timestamp.proto"; + + package oteldemo; + + option go_package = "genproto/oteldemo"; + + // -----------------Cart service----------------- + + service CartService { + rpc AddItem(AddItemRequest) returns (Empty) {} + rpc GetCart(GetCartRequest) returns (Cart) {} + rpc EmptyCart(EmptyCartRequest) returns (Empty) {} + } + + message CartItem { + string product_id = 1; + int32 quantity = 2; + } + + message AddItemRequest { + string user_id = 1; + CartItem item = 2; + } + + message EmptyCartRequest { + string user_id = 1; + } + + message GetCartRequest { + string user_id = 1; + } + + message Cart { + string user_id = 1; + repeated CartItem items = 2; + } + + message Empty {} + + // ---------------Recommendation service---------- + + service RecommendationService { + rpc ListRecommendations(ListRecommendationsRequest) returns (ListRecommendationsResponse){} + } + + message ListRecommendationsRequest { + string user_id = 1; + repeated string product_ids = 2; + } + + message ListRecommendationsResponse { + repeated string product_ids = 1; + } + + // ---------------Product Catalog---------------- + + service ProductCatalogService { + rpc ListProducts(Empty) returns (ListProductsResponse) {} + rpc GetProduct(GetProductRequest) returns (Product) {} + rpc SearchProducts(SearchProductsRequest) returns (SearchProductsResponse) {} + } + + message Product { + string id = 1; + string name = 2; + string description = 3; + string picture = 4; + Money price_usd = 5; + + // Categories such as "clothing" or "kitchen" that can be used to look up + // other related products. + repeated string categories = 6; + } + + message ListProductsResponse { + repeated Product products = 1; + } + + message GetProductRequest { + string id = 1; + } + + message SearchProductsRequest { + string query = 1; + } + + message SearchProductsResponse { + repeated Product results = 1; + } + + // ---------------Shipping Service---------- + + service ShippingService { + rpc GetQuote(GetQuoteRequest) returns (GetQuoteResponse) {} + rpc ShipOrder(ShipOrderRequest) returns (ShipOrderResponse) {} + } + + message GetQuoteRequest { + Address address = 1; + repeated CartItem items = 2; + } + + message GetQuoteResponse { + Money cost_usd = 1; + } + + message ShipOrderRequest { + Address address = 1; + repeated CartItem items = 2; + } + + message ShipOrderResponse { + string tracking_id = 1; + } + + message Address { + string street_address = 1; + string city = 2; + string state = 3; + string country = 4; + string zip_code = 5; + } + + // -----------------Currency service----------------- + + service CurrencyService { + rpc GetSupportedCurrencies(Empty) returns (GetSupportedCurrenciesResponse) {} + rpc Convert(CurrencyConversionRequest) returns (Money) {} + } + + // Represents an amount of money with its currency type. + message Money { + // The 3-letter currency code defined in ISO 4217. + string currency_code = 1; + + // The whole units of the amount. + // For example if `currencyCode` is `"USD"`, then 1 unit is one US dollar. + int64 units = 2; + + // Number of nano (10^-9) units of the amount. + // The value must be between -999,999,999 and +999,999,999 inclusive. + // If `units` is positive, `nanos` must be positive or zero. + // If `units` is zero, `nanos` can be positive, zero, or negative. + // If `units` is negative, `nanos` must be negative or zero. + // For example $-1.75 is represented as `units`=-1 and `nanos`=-750,000,000. + int32 nanos = 3; + } + + message GetSupportedCurrenciesResponse { + // The 3-letter currency code defined in ISO 4217. + repeated string currency_codes = 1; + } + + message CurrencyConversionRequest { + Money from = 1; + + // The 3-letter currency code defined in ISO 4217. + string to_code = 2; + } + + // -------------Payment service----------------- + + service PaymentService { + rpc Charge(ChargeRequest) returns (ChargeResponse) {} + } + + message CreditCardInfo { + string credit_card_number = 1; + int32 credit_card_cvv = 2; + int32 credit_card_expiration_year = 3; + int32 credit_card_expiration_month = 4; + } + + message ChargeRequest { + Money amount = 1; + CreditCardInfo credit_card = 2; + } + + message ChargeResponse { + string transaction_id = 1; + } + + // -------------Email service----------------- + + service EmailService { + rpc SendOrderConfirmation(SendOrderConfirmationRequest) returns (Empty) {} + } + + message OrderItem { + CartItem item = 1; + Money cost = 2; + } + + message OrderResult { + string order_id = 1; + string shipping_tracking_id = 2; + Money shipping_cost = 3; + Address shipping_address = 4; + repeated OrderItem items = 5; + } + + message SendOrderConfirmationRequest { + string email = 1; + OrderResult order = 2; + } + + + // -------------Checkout service----------------- + + service CheckoutService { + rpc PlaceOrder(PlaceOrderRequest) returns (PlaceOrderResponse) {} + } + + message PlaceOrderRequest { + string user_id = 1; + string user_currency = 2; + + Address address = 3; + string email = 5; + CreditCardInfo credit_card = 6; + } + + message PlaceOrderResponse { + OrderResult order = 1; + } + + // ------------Ad service------------------ + + service AdService { + rpc GetAds(AdRequest) returns (AdResponse) {} + } + + message AdRequest { + // List of important key words from the current page describing the context. + repeated string context_keys = 1; + } + + message AdResponse { + repeated Ad ads = 1; + } + + message Ad { + // url to redirect to when an ad is clicked. + string redirect_url = 1; + + // short advertisement text to display. + string text = 2; + } + + // ------------Feature flag service------------------ + + service FeatureFlagService { + rpc GetFlag(GetFlagRequest) returns (GetFlagResponse) {} + rpc CreateFlag(CreateFlagRequest) returns (CreateFlagResponse) {} + rpc UpdateFlag(UpdateFlagRequest) returns (UpdateFlagResponse) {} + rpc ListFlags(ListFlagsRequest) returns (ListFlagsResponse) {} + rpc DeleteFlag(DeleteFlagRequest) returns (DeleteFlagResponse) {} + } + + message Flag { + string name = 1; + string description = 2; + bool enabled = 3; + google.protobuf.Timestamp created_at = 4; + google.protobuf.Timestamp updated_at = 5; + } + + message GetFlagRequest { + string name = 1; + } + + message GetFlagResponse { + Flag flag = 1; + } + + message CreateFlagRequest { + string name = 1; + string description = 2; + bool enabled = 3; + } + + message CreateFlagResponse { + Flag flag = 1; + } + + message UpdateFlagRequest { + string name = 1; + bool enabled = 2; + } + + message UpdateFlagResponse {} + + message ListFlagsRequest {} + + message ListFlagsResponse { + repeated Flag flag = 1; + } + + message DeleteFlagRequest { + string name = 1; + } + + message DeleteFlagResponse {} + address: cartservice:7070 + 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[tracetest.span.type="rpc" name="oteldemo.CartService/AddItem" rpc.system="grpc" rpc.method="AddItem" rpc.service="oteldemo.CartService"] + assertions: + - attr:http.status_code = 200 + - 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}'" \ No newline at end of file diff --git a/test/tracetesting/tech-based-tests/cart-service/all.yaml b/test/tracetesting/tech-based-tests/cart-service/all.yaml new file mode 100644 index 0000000000..eed01bf866 --- /dev/null +++ b/test/tracetesting/tech-based-tests/cart-service/all.yaml @@ -0,0 +1,15 @@ +# Copyright The OpenTelemetry Authors +# SPDX-License-Identifier: Apache-2.0 + +type: Transaction +spec: + id: cart-all + name: 'Cart: all' + description: Run sequence of cart tests that depends on service state + steps: + - ./empty-cart.yaml + - ./add-item-to-cart.yaml + - ./check-if-cart-is-populated.yaml + - ./empty-cart.yaml + - ./check-if-cart-is-empty.yaml + \ No newline at end of file diff --git a/test/tracetesting/tech-based-tests/cart-service/check-if-cart-is-empty.yaml b/test/tracetesting/tech-based-tests/cart-service/check-if-cart-is-empty.yaml new file mode 100644 index 0000000000..b4027543f1 --- /dev/null +++ b/test/tracetesting/tech-based-tests/cart-service/check-if-cart-is-empty.yaml @@ -0,0 +1,346 @@ +# 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: | + // Copyright 2020 Google LLC + // + // Licensed under the Apache License, Version 2.0 (the "License"); + // you may not use this file except in compliance with the License. + // You may obtain a copy of the License at + // + // http://www.apache.org/licenses/LICENSE-2.0 + // + // Unless required by applicable law or agreed to in writing, software + // distributed under the License is distributed on an "AS IS" BASIS, + // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + // See the License for the specific language governing permissions and + // limitations under the License. + + syntax = "proto3"; + + import "google/protobuf/timestamp.proto"; + + package oteldemo; + + option go_package = "genproto/oteldemo"; + + // -----------------Cart service----------------- + + service CartService { + rpc AddItem(AddItemRequest) returns (Empty) {} + rpc GetCart(GetCartRequest) returns (Cart) {} + rpc EmptyCart(EmptyCartRequest) returns (Empty) {} + } + + message CartItem { + string product_id = 1; + int32 quantity = 2; + } + + message AddItemRequest { + string user_id = 1; + CartItem item = 2; + } + + message EmptyCartRequest { + string user_id = 1; + } + + message GetCartRequest { + string user_id = 1; + } + + message Cart { + string user_id = 1; + repeated CartItem items = 2; + } + + message Empty {} + + // ---------------Recommendation service---------- + + service RecommendationService { + rpc ListRecommendations(ListRecommendationsRequest) returns (ListRecommendationsResponse){} + } + + message ListRecommendationsRequest { + string user_id = 1; + repeated string product_ids = 2; + } + + message ListRecommendationsResponse { + repeated string product_ids = 1; + } + + // ---------------Product Catalog---------------- + + service ProductCatalogService { + rpc ListProducts(Empty) returns (ListProductsResponse) {} + rpc GetProduct(GetProductRequest) returns (Product) {} + rpc SearchProducts(SearchProductsRequest) returns (SearchProductsResponse) {} + } + + message Product { + string id = 1; + string name = 2; + string description = 3; + string picture = 4; + Money price_usd = 5; + + // Categories such as "clothing" or "kitchen" that can be used to look up + // other related products. + repeated string categories = 6; + } + + message ListProductsResponse { + repeated Product products = 1; + } + + message GetProductRequest { + string id = 1; + } + + message SearchProductsRequest { + string query = 1; + } + + message SearchProductsResponse { + repeated Product results = 1; + } + + // ---------------Shipping Service---------- + + service ShippingService { + rpc GetQuote(GetQuoteRequest) returns (GetQuoteResponse) {} + rpc ShipOrder(ShipOrderRequest) returns (ShipOrderResponse) {} + } + + message GetQuoteRequest { + Address address = 1; + repeated CartItem items = 2; + } + + message GetQuoteResponse { + Money cost_usd = 1; + } + + message ShipOrderRequest { + Address address = 1; + repeated CartItem items = 2; + } + + message ShipOrderResponse { + string tracking_id = 1; + } + + message Address { + string street_address = 1; + string city = 2; + string state = 3; + string country = 4; + string zip_code = 5; + } + + // -----------------Currency service----------------- + + service CurrencyService { + rpc GetSupportedCurrencies(Empty) returns (GetSupportedCurrenciesResponse) {} + rpc Convert(CurrencyConversionRequest) returns (Money) {} + } + + // Represents an amount of money with its currency type. + message Money { + // The 3-letter currency code defined in ISO 4217. + string currency_code = 1; + + // The whole units of the amount. + // For example if `currencyCode` is `"USD"`, then 1 unit is one US dollar. + int64 units = 2; + + // Number of nano (10^-9) units of the amount. + // The value must be between -999,999,999 and +999,999,999 inclusive. + // If `units` is positive, `nanos` must be positive or zero. + // If `units` is zero, `nanos` can be positive, zero, or negative. + // If `units` is negative, `nanos` must be negative or zero. + // For example $-1.75 is represented as `units`=-1 and `nanos`=-750,000,000. + int32 nanos = 3; + } + + message GetSupportedCurrenciesResponse { + // The 3-letter currency code defined in ISO 4217. + repeated string currency_codes = 1; + } + + message CurrencyConversionRequest { + Money from = 1; + + // The 3-letter currency code defined in ISO 4217. + string to_code = 2; + } + + // -------------Payment service----------------- + + service PaymentService { + rpc Charge(ChargeRequest) returns (ChargeResponse) {} + } + + message CreditCardInfo { + string credit_card_number = 1; + int32 credit_card_cvv = 2; + int32 credit_card_expiration_year = 3; + int32 credit_card_expiration_month = 4; + } + + message ChargeRequest { + Money amount = 1; + CreditCardInfo credit_card = 2; + } + + message ChargeResponse { + string transaction_id = 1; + } + + // -------------Email service----------------- + + service EmailService { + rpc SendOrderConfirmation(SendOrderConfirmationRequest) returns (Empty) {} + } + + message OrderItem { + CartItem item = 1; + Money cost = 2; + } + + message OrderResult { + string order_id = 1; + string shipping_tracking_id = 2; + Money shipping_cost = 3; + Address shipping_address = 4; + repeated OrderItem items = 5; + } + + message SendOrderConfirmationRequest { + string email = 1; + OrderResult order = 2; + } + + + // -------------Checkout service----------------- + + service CheckoutService { + rpc PlaceOrder(PlaceOrderRequest) returns (PlaceOrderResponse) {} + } + + message PlaceOrderRequest { + string user_id = 1; + string user_currency = 2; + + Address address = 3; + string email = 5; + CreditCardInfo credit_card = 6; + } + + message PlaceOrderResponse { + OrderResult order = 1; + } + + // ------------Ad service------------------ + + service AdService { + rpc GetAds(AdRequest) returns (AdResponse) {} + } + + message AdRequest { + // List of important key words from the current page describing the context. + repeated string context_keys = 1; + } + + message AdResponse { + repeated Ad ads = 1; + } + + message Ad { + // url to redirect to when an ad is clicked. + string redirect_url = 1; + + // short advertisement text to display. + string text = 2; + } + + // ------------Feature flag service------------------ + + service FeatureFlagService { + rpc GetFlag(GetFlagRequest) returns (GetFlagResponse) {} + rpc CreateFlag(CreateFlagRequest) returns (CreateFlagResponse) {} + rpc UpdateFlag(UpdateFlagRequest) returns (UpdateFlagResponse) {} + rpc ListFlags(ListFlagsRequest) returns (ListFlagsResponse) {} + rpc DeleteFlag(DeleteFlagRequest) returns (DeleteFlagResponse) {} + } + + message Flag { + string name = 1; + string description = 2; + bool enabled = 3; + google.protobuf.Timestamp created_at = 4; + google.protobuf.Timestamp updated_at = 5; + } + + message GetFlagRequest { + string name = 1; + } + + message GetFlagResponse { + Flag flag = 1; + } + + message CreateFlagRequest { + string name = 1; + string description = 2; + bool enabled = 3; + } + + message CreateFlagResponse { + Flag flag = 1; + } + + message UpdateFlagRequest { + string name = 1; + bool enabled = 2; + } + + message UpdateFlagResponse {} + + message ListFlagsRequest {} + + message ListFlagsResponse { + repeated Flag flag = 1; + } + + message DeleteFlagRequest { + string name = 1; + } + + message DeleteFlagResponse {} + address: cartservice:7070 + method: oteldemo.CartService.GetCart + request: |- + { + "userId": "1234" + } + 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"] + assertions: + - attr:http.status_code = 200 + - name: It returned no items + selector: span[tracetest.span.type="general" name="Tracetest trigger"] + assertions: + - attr:tracetest.response.body | json_path '$.items' = "[]" \ No newline at end of file diff --git a/test/tracetesting/tech-based-tests/cart-service/check-if-cart-is-populated.yaml b/test/tracetesting/tech-based-tests/cart-service/check-if-cart-is-populated.yaml new file mode 100644 index 0000000000..ae69283b08 --- /dev/null +++ b/test/tracetesting/tech-based-tests/cart-service/check-if-cart-is-populated.yaml @@ -0,0 +1,348 @@ +# 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: | + // Copyright 2020 Google LLC + // + // Licensed under the Apache License, Version 2.0 (the "License"); + // you may not use this file except in compliance with the License. + // You may obtain a copy of the License at + // + // http://www.apache.org/licenses/LICENSE-2.0 + // + // Unless required by applicable law or agreed to in writing, software + // distributed under the License is distributed on an "AS IS" BASIS, + // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + // See the License for the specific language governing permissions and + // limitations under the License. + + syntax = "proto3"; + + import "google/protobuf/timestamp.proto"; + + package oteldemo; + + option go_package = "genproto/oteldemo"; + + // -----------------Cart service----------------- + + service CartService { + rpc AddItem(AddItemRequest) returns (Empty) {} + rpc GetCart(GetCartRequest) returns (Cart) {} + rpc EmptyCart(EmptyCartRequest) returns (Empty) {} + } + + message CartItem { + string product_id = 1; + int32 quantity = 2; + } + + message AddItemRequest { + string user_id = 1; + CartItem item = 2; + } + + message EmptyCartRequest { + string user_id = 1; + } + + message GetCartRequest { + string user_id = 1; + } + + message Cart { + string user_id = 1; + repeated CartItem items = 2; + } + + message Empty {} + + // ---------------Recommendation service---------- + + service RecommendationService { + rpc ListRecommendations(ListRecommendationsRequest) returns (ListRecommendationsResponse){} + } + + message ListRecommendationsRequest { + string user_id = 1; + repeated string product_ids = 2; + } + + message ListRecommendationsResponse { + repeated string product_ids = 1; + } + + // ---------------Product Catalog---------------- + + service ProductCatalogService { + rpc ListProducts(Empty) returns (ListProductsResponse) {} + rpc GetProduct(GetProductRequest) returns (Product) {} + rpc SearchProducts(SearchProductsRequest) returns (SearchProductsResponse) {} + } + + message Product { + string id = 1; + string name = 2; + string description = 3; + string picture = 4; + Money price_usd = 5; + + // Categories such as "clothing" or "kitchen" that can be used to look up + // other related products. + repeated string categories = 6; + } + + message ListProductsResponse { + repeated Product products = 1; + } + + message GetProductRequest { + string id = 1; + } + + message SearchProductsRequest { + string query = 1; + } + + message SearchProductsResponse { + repeated Product results = 1; + } + + // ---------------Shipping Service---------- + + service ShippingService { + rpc GetQuote(GetQuoteRequest) returns (GetQuoteResponse) {} + rpc ShipOrder(ShipOrderRequest) returns (ShipOrderResponse) {} + } + + message GetQuoteRequest { + Address address = 1; + repeated CartItem items = 2; + } + + message GetQuoteResponse { + Money cost_usd = 1; + } + + message ShipOrderRequest { + Address address = 1; + repeated CartItem items = 2; + } + + message ShipOrderResponse { + string tracking_id = 1; + } + + message Address { + string street_address = 1; + string city = 2; + string state = 3; + string country = 4; + string zip_code = 5; + } + + // -----------------Currency service----------------- + + service CurrencyService { + rpc GetSupportedCurrencies(Empty) returns (GetSupportedCurrenciesResponse) {} + rpc Convert(CurrencyConversionRequest) returns (Money) {} + } + + // Represents an amount of money with its currency type. + message Money { + // The 3-letter currency code defined in ISO 4217. + string currency_code = 1; + + // The whole units of the amount. + // For example if `currencyCode` is `"USD"`, then 1 unit is one US dollar. + int64 units = 2; + + // Number of nano (10^-9) units of the amount. + // The value must be between -999,999,999 and +999,999,999 inclusive. + // If `units` is positive, `nanos` must be positive or zero. + // If `units` is zero, `nanos` can be positive, zero, or negative. + // If `units` is negative, `nanos` must be negative or zero. + // For example $-1.75 is represented as `units`=-1 and `nanos`=-750,000,000. + int32 nanos = 3; + } + + message GetSupportedCurrenciesResponse { + // The 3-letter currency code defined in ISO 4217. + repeated string currency_codes = 1; + } + + message CurrencyConversionRequest { + Money from = 1; + + // The 3-letter currency code defined in ISO 4217. + string to_code = 2; + } + + // -------------Payment service----------------- + + service PaymentService { + rpc Charge(ChargeRequest) returns (ChargeResponse) {} + } + + message CreditCardInfo { + string credit_card_number = 1; + int32 credit_card_cvv = 2; + int32 credit_card_expiration_year = 3; + int32 credit_card_expiration_month = 4; + } + + message ChargeRequest { + Money amount = 1; + CreditCardInfo credit_card = 2; + } + + message ChargeResponse { + string transaction_id = 1; + } + + // -------------Email service----------------- + + service EmailService { + rpc SendOrderConfirmation(SendOrderConfirmationRequest) returns (Empty) {} + } + + message OrderItem { + CartItem item = 1; + Money cost = 2; + } + + message OrderResult { + string order_id = 1; + string shipping_tracking_id = 2; + Money shipping_cost = 3; + Address shipping_address = 4; + repeated OrderItem items = 5; + } + + message SendOrderConfirmationRequest { + string email = 1; + OrderResult order = 2; + } + + + // -------------Checkout service----------------- + + service CheckoutService { + rpc PlaceOrder(PlaceOrderRequest) returns (PlaceOrderResponse) {} + } + + message PlaceOrderRequest { + string user_id = 1; + string user_currency = 2; + + Address address = 3; + string email = 5; + CreditCardInfo credit_card = 6; + } + + message PlaceOrderResponse { + OrderResult order = 1; + } + + // ------------Ad service------------------ + + service AdService { + rpc GetAds(AdRequest) returns (AdResponse) {} + } + + message AdRequest { + // List of important key words from the current page describing the context. + repeated string context_keys = 1; + } + + message AdResponse { + repeated Ad ads = 1; + } + + message Ad { + // url to redirect to when an ad is clicked. + string redirect_url = 1; + + // short advertisement text to display. + string text = 2; + } + + // ------------Feature flag service------------------ + + service FeatureFlagService { + rpc GetFlag(GetFlagRequest) returns (GetFlagResponse) {} + rpc CreateFlag(CreateFlagRequest) returns (CreateFlagResponse) {} + rpc UpdateFlag(UpdateFlagRequest) returns (UpdateFlagResponse) {} + rpc ListFlags(ListFlagsRequest) returns (ListFlagsResponse) {} + rpc DeleteFlag(DeleteFlagRequest) returns (DeleteFlagResponse) {} + } + + message Flag { + string name = 1; + string description = 2; + bool enabled = 3; + google.protobuf.Timestamp created_at = 4; + google.protobuf.Timestamp updated_at = 5; + } + + message GetFlagRequest { + string name = 1; + } + + message GetFlagResponse { + Flag flag = 1; + } + + message CreateFlagRequest { + string name = 1; + string description = 2; + bool enabled = 3; + } + + message CreateFlagResponse { + Flag flag = 1; + } + + message UpdateFlagRequest { + string name = 1; + bool enabled = 2; + } + + message UpdateFlagResponse {} + + message ListFlagsRequest {} + + message ListFlagsResponse { + repeated Flag flag = 1; + } + + message DeleteFlagRequest { + string name = 1; + } + + message DeleteFlagResponse {} + address: cartservice:7070 + method: oteldemo.CartService.GetCart + request: |- + { + "userId": "1234" + } + 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"] + assertions: + - attr:http.status_code = 200 + - 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" \ No newline at end of file diff --git a/test/tracetesting/tech-based-tests/cart-service/empty-cart.yaml b/test/tracetesting/tech-based-tests/cart-service/empty-cart.yaml new file mode 100644 index 0000000000..fcef14ee94 --- /dev/null +++ b/test/tracetesting/tech-based-tests/cart-service/empty-cart.yaml @@ -0,0 +1,348 @@ +# 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: | + // Copyright 2020 Google LLC + // + // Licensed under the Apache License, Version 2.0 (the "License"); + // you may not use this file except in compliance with the License. + // You may obtain a copy of the License at + // + // http://www.apache.org/licenses/LICENSE-2.0 + // + // Unless required by applicable law or agreed to in writing, software + // distributed under the License is distributed on an "AS IS" BASIS, + // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + // See the License for the specific language governing permissions and + // limitations under the License. + + syntax = "proto3"; + + import "google/protobuf/timestamp.proto"; + + package oteldemo; + + option go_package = "genproto/oteldemo"; + + // -----------------Cart service----------------- + + service CartService { + rpc AddItem(AddItemRequest) returns (Empty) {} + rpc GetCart(GetCartRequest) returns (Cart) {} + rpc EmptyCart(EmptyCartRequest) returns (Empty) {} + } + + message CartItem { + string product_id = 1; + int32 quantity = 2; + } + + message AddItemRequest { + string user_id = 1; + CartItem item = 2; + } + + message EmptyCartRequest { + string user_id = 1; + } + + message GetCartRequest { + string user_id = 1; + } + + message Cart { + string user_id = 1; + repeated CartItem items = 2; + } + + message Empty {} + + // ---------------Recommendation service---------- + + service RecommendationService { + rpc ListRecommendations(ListRecommendationsRequest) returns (ListRecommendationsResponse){} + } + + message ListRecommendationsRequest { + string user_id = 1; + repeated string product_ids = 2; + } + + message ListRecommendationsResponse { + repeated string product_ids = 1; + } + + // ---------------Product Catalog---------------- + + service ProductCatalogService { + rpc ListProducts(Empty) returns (ListProductsResponse) {} + rpc GetProduct(GetProductRequest) returns (Product) {} + rpc SearchProducts(SearchProductsRequest) returns (SearchProductsResponse) {} + } + + message Product { + string id = 1; + string name = 2; + string description = 3; + string picture = 4; + Money price_usd = 5; + + // Categories such as "clothing" or "kitchen" that can be used to look up + // other related products. + repeated string categories = 6; + } + + message ListProductsResponse { + repeated Product products = 1; + } + + message GetProductRequest { + string id = 1; + } + + message SearchProductsRequest { + string query = 1; + } + + message SearchProductsResponse { + repeated Product results = 1; + } + + // ---------------Shipping Service---------- + + service ShippingService { + rpc GetQuote(GetQuoteRequest) returns (GetQuoteResponse) {} + rpc ShipOrder(ShipOrderRequest) returns (ShipOrderResponse) {} + } + + message GetQuoteRequest { + Address address = 1; + repeated CartItem items = 2; + } + + message GetQuoteResponse { + Money cost_usd = 1; + } + + message ShipOrderRequest { + Address address = 1; + repeated CartItem items = 2; + } + + message ShipOrderResponse { + string tracking_id = 1; + } + + message Address { + string street_address = 1; + string city = 2; + string state = 3; + string country = 4; + string zip_code = 5; + } + + // -----------------Currency service----------------- + + service CurrencyService { + rpc GetSupportedCurrencies(Empty) returns (GetSupportedCurrenciesResponse) {} + rpc Convert(CurrencyConversionRequest) returns (Money) {} + } + + // Represents an amount of money with its currency type. + message Money { + // The 3-letter currency code defined in ISO 4217. + string currency_code = 1; + + // The whole units of the amount. + // For example if `currencyCode` is `"USD"`, then 1 unit is one US dollar. + int64 units = 2; + + // Number of nano (10^-9) units of the amount. + // The value must be between -999,999,999 and +999,999,999 inclusive. + // If `units` is positive, `nanos` must be positive or zero. + // If `units` is zero, `nanos` can be positive, zero, or negative. + // If `units` is negative, `nanos` must be negative or zero. + // For example $-1.75 is represented as `units`=-1 and `nanos`=-750,000,000. + int32 nanos = 3; + } + + message GetSupportedCurrenciesResponse { + // The 3-letter currency code defined in ISO 4217. + repeated string currency_codes = 1; + } + + message CurrencyConversionRequest { + Money from = 1; + + // The 3-letter currency code defined in ISO 4217. + string to_code = 2; + } + + // -------------Payment service----------------- + + service PaymentService { + rpc Charge(ChargeRequest) returns (ChargeResponse) {} + } + + message CreditCardInfo { + string credit_card_number = 1; + int32 credit_card_cvv = 2; + int32 credit_card_expiration_year = 3; + int32 credit_card_expiration_month = 4; + } + + message ChargeRequest { + Money amount = 1; + CreditCardInfo credit_card = 2; + } + + message ChargeResponse { + string transaction_id = 1; + } + + // -------------Email service----------------- + + service EmailService { + rpc SendOrderConfirmation(SendOrderConfirmationRequest) returns (Empty) {} + } + + message OrderItem { + CartItem item = 1; + Money cost = 2; + } + + message OrderResult { + string order_id = 1; + string shipping_tracking_id = 2; + Money shipping_cost = 3; + Address shipping_address = 4; + repeated OrderItem items = 5; + } + + message SendOrderConfirmationRequest { + string email = 1; + OrderResult order = 2; + } + + + // -------------Checkout service----------------- + + service CheckoutService { + rpc PlaceOrder(PlaceOrderRequest) returns (PlaceOrderResponse) {} + } + + message PlaceOrderRequest { + string user_id = 1; + string user_currency = 2; + + Address address = 3; + string email = 5; + CreditCardInfo credit_card = 6; + } + + message PlaceOrderResponse { + OrderResult order = 1; + } + + // ------------Ad service------------------ + + service AdService { + rpc GetAds(AdRequest) returns (AdResponse) {} + } + + message AdRequest { + // List of important key words from the current page describing the context. + repeated string context_keys = 1; + } + + message AdResponse { + repeated Ad ads = 1; + } + + message Ad { + // url to redirect to when an ad is clicked. + string redirect_url = 1; + + // short advertisement text to display. + string text = 2; + } + + // ------------Feature flag service------------------ + + service FeatureFlagService { + rpc GetFlag(GetFlagRequest) returns (GetFlagResponse) {} + rpc CreateFlag(CreateFlagRequest) returns (CreateFlagResponse) {} + rpc UpdateFlag(UpdateFlagRequest) returns (UpdateFlagResponse) {} + rpc ListFlags(ListFlagsRequest) returns (ListFlagsResponse) {} + rpc DeleteFlag(DeleteFlagRequest) returns (DeleteFlagResponse) {} + } + + message Flag { + string name = 1; + string description = 2; + bool enabled = 3; + google.protobuf.Timestamp created_at = 4; + google.protobuf.Timestamp updated_at = 5; + } + + message GetFlagRequest { + string name = 1; + } + + message GetFlagResponse { + Flag flag = 1; + } + + message CreateFlagRequest { + string name = 1; + string description = 2; + bool enabled = 3; + } + + message CreateFlagResponse { + Flag flag = 1; + } + + message UpdateFlagRequest { + string name = 1; + bool enabled = 2; + } + + message UpdateFlagResponse {} + + message ListFlagsRequest {} + + message ListFlagsResponse { + repeated Flag flag = 1; + } + + message DeleteFlagRequest { + string name = 1; + } + + message DeleteFlagResponse {} + address: cartservice:7070 + method: oteldemo.CartService.EmptyCart + request: |- + { + "userId": "1234" + } + 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"] + 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" \ No newline at end of file diff --git a/test/tracetesting/tech-based-tests/checkout-service/place-order.yaml b/test/tracetesting/tech-based-tests/checkout-service/place-order.yaml new file mode 100644 index 0000000000..9cdad76799 --- /dev/null +++ b/test/tracetesting/tech-based-tests/checkout-service/place-order.yaml @@ -0,0 +1,365 @@ +# 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: | + // Copyright 2020 Google LLC + // + // Licensed under the Apache License, Version 2.0 (the "License"); + // you may not use this file except in compliance with the License. + // You may obtain a copy of the License at + // + // http://www.apache.org/licenses/LICENSE-2.0 + // + // Unless required by applicable law or agreed to in writing, software + // distributed under the License is distributed on an "AS IS" BASIS, + // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + // See the License for the specific language governing permissions and + // limitations under the License. + + syntax = "proto3"; + + import "google/protobuf/timestamp.proto"; + + package oteldemo; + + option go_package = "genproto/oteldemo"; + + // -----------------Cart service----------------- + + service CartService { + rpc AddItem(AddItemRequest) returns (Empty) {} + rpc GetCart(GetCartRequest) returns (Cart) {} + rpc EmptyCart(EmptyCartRequest) returns (Empty) {} + } + + message CartItem { + string product_id = 1; + int32 quantity = 2; + } + + message AddItemRequest { + string user_id = 1; + CartItem item = 2; + } + + message EmptyCartRequest { + string user_id = 1; + } + + message GetCartRequest { + string user_id = 1; + } + + message Cart { + string user_id = 1; + repeated CartItem items = 2; + } + + message Empty {} + + // ---------------Recommendation service---------- + + service RecommendationService { + rpc ListRecommendations(ListRecommendationsRequest) returns (ListRecommendationsResponse){} + } + + message ListRecommendationsRequest { + string user_id = 1; + repeated string product_ids = 2; + } + + message ListRecommendationsResponse { + repeated string product_ids = 1; + } + + // ---------------Product Catalog---------------- + + service ProductCatalogService { + rpc ListProducts(Empty) returns (ListProductsResponse) {} + rpc GetProduct(GetProductRequest) returns (Product) {} + rpc SearchProducts(SearchProductsRequest) returns (SearchProductsResponse) {} + } + + message Product { + string id = 1; + string name = 2; + string description = 3; + string picture = 4; + Money price_usd = 5; + + // Categories such as "clothing" or "kitchen" that can be used to look up + // other related products. + repeated string categories = 6; + } + + message ListProductsResponse { + repeated Product products = 1; + } + + message GetProductRequest { + string id = 1; + } + + message SearchProductsRequest { + string query = 1; + } + + message SearchProductsResponse { + repeated Product results = 1; + } + + // ---------------Shipping Service---------- + + service ShippingService { + rpc GetQuote(GetQuoteRequest) returns (GetQuoteResponse) {} + rpc ShipOrder(ShipOrderRequest) returns (ShipOrderResponse) {} + } + + message GetQuoteRequest { + Address address = 1; + repeated CartItem items = 2; + } + + message GetQuoteResponse { + Money cost_usd = 1; + } + + message ShipOrderRequest { + Address address = 1; + repeated CartItem items = 2; + } + + message ShipOrderResponse { + string tracking_id = 1; + } + + message Address { + string street_address = 1; + string city = 2; + string state = 3; + string country = 4; + string zip_code = 5; + } + + // -----------------Currency service----------------- + + service CurrencyService { + rpc GetSupportedCurrencies(Empty) returns (GetSupportedCurrenciesResponse) {} + rpc Convert(CurrencyConversionRequest) returns (Money) {} + } + + // Represents an amount of money with its currency type. + message Money { + // The 3-letter currency code defined in ISO 4217. + string currency_code = 1; + + // The whole units of the amount. + // For example if `currencyCode` is `"USD"`, then 1 unit is one US dollar. + int64 units = 2; + + // Number of nano (10^-9) units of the amount. + // The value must be between -999,999,999 and +999,999,999 inclusive. + // If `units` is positive, `nanos` must be positive or zero. + // If `units` is zero, `nanos` can be positive, zero, or negative. + // If `units` is negative, `nanos` must be negative or zero. + // For example $-1.75 is represented as `units`=-1 and `nanos`=-750,000,000. + int32 nanos = 3; + } + + message GetSupportedCurrenciesResponse { + // The 3-letter currency code defined in ISO 4217. + repeated string currency_codes = 1; + } + + message CurrencyConversionRequest { + Money from = 1; + + // The 3-letter currency code defined in ISO 4217. + string to_code = 2; + } + + // -------------Payment service----------------- + + service PaymentService { + rpc Charge(ChargeRequest) returns (ChargeResponse) {} + } + + message CreditCardInfo { + string credit_card_number = 1; + int32 credit_card_cvv = 2; + int32 credit_card_expiration_year = 3; + int32 credit_card_expiration_month = 4; + } + + message ChargeRequest { + Money amount = 1; + CreditCardInfo credit_card = 2; + } + + message ChargeResponse { + string transaction_id = 1; + } + + // -------------Email service----------------- + + service EmailService { + rpc SendOrderConfirmation(SendOrderConfirmationRequest) returns (Empty) {} + } + + message OrderItem { + CartItem item = 1; + Money cost = 2; + } + + message OrderResult { + string order_id = 1; + string shipping_tracking_id = 2; + Money shipping_cost = 3; + Address shipping_address = 4; + repeated OrderItem items = 5; + } + + message SendOrderConfirmationRequest { + string email = 1; + OrderResult order = 2; + } + + + // -------------Checkout service----------------- + + service CheckoutService { + rpc PlaceOrder(PlaceOrderRequest) returns (PlaceOrderResponse) {} + } + + message PlaceOrderRequest { + string user_id = 1; + string user_currency = 2; + + Address address = 3; + string email = 5; + CreditCardInfo credit_card = 6; + } + + message PlaceOrderResponse { + OrderResult order = 1; + } + + // ------------Ad service------------------ + + service AdService { + rpc GetAds(AdRequest) returns (AdResponse) {} + } + + message AdRequest { + // List of important key words from the current page describing the context. + repeated string context_keys = 1; + } + + message AdResponse { + repeated Ad ads = 1; + } + + message Ad { + // url to redirect to when an ad is clicked. + string redirect_url = 1; + + // short advertisement text to display. + string text = 2; + } + + // ------------Feature flag service------------------ + + service FeatureFlagService { + rpc GetFlag(GetFlagRequest) returns (GetFlagResponse) {} + rpc CreateFlag(CreateFlagRequest) returns (CreateFlagResponse) {} + rpc UpdateFlag(UpdateFlagRequest) returns (UpdateFlagResponse) {} + rpc ListFlags(ListFlagsRequest) returns (ListFlagsResponse) {} + rpc DeleteFlag(DeleteFlagRequest) returns (DeleteFlagResponse) {} + } + + message Flag { + string name = 1; + string description = 2; + bool enabled = 3; + google.protobuf.Timestamp created_at = 4; + google.protobuf.Timestamp updated_at = 5; + } + + message GetFlagRequest { + string name = 1; + } + + message GetFlagResponse { + Flag flag = 1; + } + + message CreateFlagRequest { + string name = 1; + string description = 2; + bool enabled = 3; + } + + message CreateFlagResponse { + Flag flag = 1; + } + + message UpdateFlagRequest { + string name = 1; + bool enabled = 2; + } + + message UpdateFlagResponse {} + + message ListFlagsRequest {} + + message ListFlagsResponse { + repeated Flag flag = 1; + } + + message DeleteFlagRequest { + string name = 1; + } + + message DeleteFlagResponse {} + address: checkoutservice:5050 + 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": "amazon@example.com", + "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 \ No newline at end of file diff --git a/test/tracetesting/tech-based-tests/currency-convert.yaml b/test/tracetesting/tech-based-tests/currency-service/convert.yaml similarity index 99% rename from test/tracetesting/tech-based-tests/currency-convert.yaml rename to test/tracetesting/tech-based-tests/currency-service/convert.yaml index affebefdb6..a53159c09a 100644 --- a/test/tracetesting/tech-based-tests/currency-convert.yaml +++ b/test/tracetesting/tech-based-tests/currency-service/convert.yaml @@ -3,7 +3,7 @@ type: Test spec: - id: JVF5jfsVR + id: currency-convert name: 'Currency: Convert' description: Convert a currency trigger: diff --git a/test/tracetesting/tech-based-tests/currency-supported.yaml b/test/tracetesting/tech-based-tests/currency-service/supported.yaml similarity index 100% rename from test/tracetesting/tech-based-tests/currency-supported.yaml rename to test/tracetesting/tech-based-tests/currency-service/supported.yaml diff --git a/test/tracetesting/tech-based-tests/email-service/confirmation.yaml b/test/tracetesting/tech-based-tests/email-service/confirmation.yaml new file mode 100644 index 0000000000..c7f12aa004 --- /dev/null +++ b/test/tracetesting/tech-based-tests/email-service/confirmation.yaml @@ -0,0 +1,62 @@ +# Copyright The OpenTelemetry Authors +# SPDX-License-Identifier: Apache-2.0 + +type: Test +spec: + id: email-confirmation + name: 'Email: Confirmation' + description: Send an order confirmation email + trigger: + type: http + httpRequest: + url: http://emailservice:6060/send_order_confirmation + method: POST + headers: + - key: Content-Type + value: application/json + body: | + { + "email": "google@example.com", + "order": { + "orderId": "505", + "shippingTrackingId": "dead-beef", + "shippingCost": { + "currencyCode": "USD", + "units": 17, + "nanos": 980000000 + }, + "shippingAddress": { + "streetAddress": "1600 Amphitheatre Parkway", + "city": "Mountain View", + "state": "California", + "country": "United States", + "zipCode": "94043" + }, + "items": [ + { + "item": { + "productId": "1YMWWN1N4O", + "quantity": 5 + }, + "cost": { + "currencyCode": "USD", + "units": 100, + "nanos": 0 + } + } + ] + } + } + specs: + - name: It should be called successfully + selector: span[tracetest.span.type="http" name="POST /send_order_confirmation" http.method="POST"] + assertions: + - attr:http.status_code = 200 + - name: It should render a email to send + selector: span[tracetest.span.type="general" name="sinatra.render_template"] + assertions: + - attr:name = "sinatra.render_template" + - name: It should send an email + selector: span[tracetest.span.type="general" name="send_email"] + assertions: + - attr:name = "send_email" diff --git a/test/tracetesting/tech-based-tests/payment-service/amex-credit-card-not-allowed.yaml b/test/tracetesting/tech-based-tests/payment-service/amex-credit-card-not-allowed.yaml new file mode 100644 index 0000000000..1e63ba6616 --- /dev/null +++ b/test/tracetesting/tech-based-tests/payment-service/amex-credit-card-not-allowed.yaml @@ -0,0 +1,358 @@ +# Copyright The OpenTelemetry Authors +# SPDX-License-Identifier: Apache-2.0 + +type: Test +spec: + id: payment-amex-credit-card-not-allowed + name: 'Payment: Amex credit card not allowed' + description: Charge customer with an Amex credit card + trigger: + type: grpc + grpc: + protobufFile: | + // Copyright 2020 Google LLC + // + // Licensed under the Apache License, Version 2.0 (the "License"); + // you may not use this file except in compliance with the License. + // You may obtain a copy of the License at + // + // http://www.apache.org/licenses/LICENSE-2.0 + // + // Unless required by applicable law or agreed to in writing, software + // distributed under the License is distributed on an "AS IS" BASIS, + // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + // See the License for the specific language governing permissions and + // limitations under the License. + + syntax = "proto3"; + + import "google/protobuf/timestamp.proto"; + + package oteldemo; + + option go_package = "genproto/oteldemo"; + + // -----------------Cart service----------------- + + service CartService { + rpc AddItem(AddItemRequest) returns (Empty) {} + rpc GetCart(GetCartRequest) returns (Cart) {} + rpc EmptyCart(EmptyCartRequest) returns (Empty) {} + } + + message CartItem { + string product_id = 1; + int32 quantity = 2; + } + + message AddItemRequest { + string user_id = 1; + CartItem item = 2; + } + + message EmptyCartRequest { + string user_id = 1; + } + + message GetCartRequest { + string user_id = 1; + } + + message Cart { + string user_id = 1; + repeated CartItem items = 2; + } + + message Empty {} + + // ---------------Recommendation service---------- + + service RecommendationService { + rpc ListRecommendations(ListRecommendationsRequest) returns (ListRecommendationsResponse){} + } + + message ListRecommendationsRequest { + string user_id = 1; + repeated string product_ids = 2; + } + + message ListRecommendationsResponse { + repeated string product_ids = 1; + } + + // ---------------Product Catalog---------------- + + service ProductCatalogService { + rpc ListProducts(Empty) returns (ListProductsResponse) {} + rpc GetProduct(GetProductRequest) returns (Product) {} + rpc SearchProducts(SearchProductsRequest) returns (SearchProductsResponse) {} + } + + message Product { + string id = 1; + string name = 2; + string description = 3; + string picture = 4; + Money price_usd = 5; + + // Categories such as "clothing" or "kitchen" that can be used to look up + // other related products. + repeated string categories = 6; + } + + message ListProductsResponse { + repeated Product products = 1; + } + + message GetProductRequest { + string id = 1; + } + + message SearchProductsRequest { + string query = 1; + } + + message SearchProductsResponse { + repeated Product results = 1; + } + + // ---------------Shipping Service---------- + + service ShippingService { + rpc GetQuote(GetQuoteRequest) returns (GetQuoteResponse) {} + rpc ShipOrder(ShipOrderRequest) returns (ShipOrderResponse) {} + } + + message GetQuoteRequest { + Address address = 1; + repeated CartItem items = 2; + } + + message GetQuoteResponse { + Money cost_usd = 1; + } + + message ShipOrderRequest { + Address address = 1; + repeated CartItem items = 2; + } + + message ShipOrderResponse { + string tracking_id = 1; + } + + message Address { + string street_address = 1; + string city = 2; + string state = 3; + string country = 4; + string zip_code = 5; + } + + // -----------------Currency service----------------- + + service CurrencyService { + rpc GetSupportedCurrencies(Empty) returns (GetSupportedCurrenciesResponse) {} + rpc Convert(CurrencyConversionRequest) returns (Money) {} + } + + // Represents an amount of money with its currency type. + message Money { + // The 3-letter currency code defined in ISO 4217. + string currency_code = 1; + + // The whole units of the amount. + // For example if `currencyCode` is `"USD"`, then 1 unit is one US dollar. + int64 units = 2; + + // Number of nano (10^-9) units of the amount. + // The value must be between -999,999,999 and +999,999,999 inclusive. + // If `units` is positive, `nanos` must be positive or zero. + // If `units` is zero, `nanos` can be positive, zero, or negative. + // If `units` is negative, `nanos` must be negative or zero. + // For example $-1.75 is represented as `units`=-1 and `nanos`=-750,000,000. + int32 nanos = 3; + } + + message GetSupportedCurrenciesResponse { + // The 3-letter currency code defined in ISO 4217. + repeated string currency_codes = 1; + } + + message CurrencyConversionRequest { + Money from = 1; + + // The 3-letter currency code defined in ISO 4217. + string to_code = 2; + } + + // -------------Payment service----------------- + + service PaymentService { + rpc Charge(ChargeRequest) returns (ChargeResponse) {} + } + + message CreditCardInfo { + string credit_card_number = 1; + int32 credit_card_cvv = 2; + int32 credit_card_expiration_year = 3; + int32 credit_card_expiration_month = 4; + } + + message ChargeRequest { + Money amount = 1; + CreditCardInfo credit_card = 2; + } + + message ChargeResponse { + string transaction_id = 1; + } + + // -------------Email service----------------- + + service EmailService { + rpc SendOrderConfirmation(SendOrderConfirmationRequest) returns (Empty) {} + } + + message OrderItem { + CartItem item = 1; + Money cost = 2; + } + + message OrderResult { + string order_id = 1; + string shipping_tracking_id = 2; + Money shipping_cost = 3; + Address shipping_address = 4; + repeated OrderItem items = 5; + } + + message SendOrderConfirmationRequest { + string email = 1; + OrderResult order = 2; + } + + + // -------------Checkout service----------------- + + service CheckoutService { + rpc PlaceOrder(PlaceOrderRequest) returns (PlaceOrderResponse) {} + } + + message PlaceOrderRequest { + string user_id = 1; + string user_currency = 2; + + Address address = 3; + string email = 5; + CreditCardInfo credit_card = 6; + } + + message PlaceOrderResponse { + OrderResult order = 1; + } + + // ------------Ad service------------------ + + service AdService { + rpc GetAds(AdRequest) returns (AdResponse) {} + } + + message AdRequest { + // List of important key words from the current page describing the context. + repeated string context_keys = 1; + } + + message AdResponse { + repeated Ad ads = 1; + } + + message Ad { + // url to redirect to when an ad is clicked. + string redirect_url = 1; + + // short advertisement text to display. + string text = 2; + } + + // ------------Feature flag service------------------ + + service FeatureFlagService { + rpc GetFlag(GetFlagRequest) returns (GetFlagResponse) {} + rpc CreateFlag(CreateFlagRequest) returns (CreateFlagResponse) {} + rpc UpdateFlag(UpdateFlagRequest) returns (UpdateFlagResponse) {} + rpc ListFlags(ListFlagsRequest) returns (ListFlagsResponse) {} + rpc DeleteFlag(DeleteFlagRequest) returns (DeleteFlagResponse) {} + } + + message Flag { + string name = 1; + string description = 2; + bool enabled = 3; + google.protobuf.Timestamp created_at = 4; + google.protobuf.Timestamp updated_at = 5; + } + + message GetFlagRequest { + string name = 1; + } + + message GetFlagResponse { + Flag flag = 1; + } + + message CreateFlagRequest { + string name = 1; + string description = 2; + bool enabled = 3; + } + + message CreateFlagResponse { + Flag flag = 1; + } + + message UpdateFlagRequest { + string name = 1; + bool enabled = 2; + } + + message UpdateFlagResponse {} + + message ListFlagsRequest {} + + message ListFlagsResponse { + repeated Flag flag = 1; + } + + message DeleteFlagRequest { + string name = 1; + } + + message DeleteFlagResponse {} + address: paymentservice:50051 + method: oteldemo.PaymentService.Charge + request: |- + { + "amount": { + "currencyCode": "USD", + "units": 43, + "nanos": 130000000 + }, + "creditCard": { + "creditCardNumber": "3714 496353 98431", + "creditCardCvv": 672, + "creditCardExpirationYear": 2039, + "creditCardExpirationMonth": 1 + } + } + 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"] + 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." diff --git a/test/tracetesting/tech-based-tests/payment-service/expired-credit-card.yaml b/test/tracetesting/tech-based-tests/payment-service/expired-credit-card.yaml new file mode 100644 index 0000000000..958518c479 --- /dev/null +++ b/test/tracetesting/tech-based-tests/payment-service/expired-credit-card.yaml @@ -0,0 +1,356 @@ +# Copyright The OpenTelemetry Authors +# SPDX-License-Identifier: Apache-2.0 + +type: Test +spec: + id: payment-expired-credit-card + name: 'Payment: expired credit card' + description: Charge customer with an expired credit card + trigger: + type: grpc + grpc: + protobufFile: | + // Copyright 2020 Google LLC + // + // Licensed under the Apache License, Version 2.0 (the "License"); + // you may not use this file except in compliance with the License. + // You may obtain a copy of the License at + // + // http://www.apache.org/licenses/LICENSE-2.0 + // + // Unless required by applicable law or agreed to in writing, software + // distributed under the License is distributed on an "AS IS" BASIS, + // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + // See the License for the specific language governing permissions and + // limitations under the License. + + syntax = "proto3"; + + import "google/protobuf/timestamp.proto"; + + package oteldemo; + + option go_package = "genproto/oteldemo"; + + // -----------------Cart service----------------- + + service CartService { + rpc AddItem(AddItemRequest) returns (Empty) {} + rpc GetCart(GetCartRequest) returns (Cart) {} + rpc EmptyCart(EmptyCartRequest) returns (Empty) {} + } + + message CartItem { + string product_id = 1; + int32 quantity = 2; + } + + message AddItemRequest { + string user_id = 1; + CartItem item = 2; + } + + message EmptyCartRequest { + string user_id = 1; + } + + message GetCartRequest { + string user_id = 1; + } + + message Cart { + string user_id = 1; + repeated CartItem items = 2; + } + + message Empty {} + + // ---------------Recommendation service---------- + + service RecommendationService { + rpc ListRecommendations(ListRecommendationsRequest) returns (ListRecommendationsResponse){} + } + + message ListRecommendationsRequest { + string user_id = 1; + repeated string product_ids = 2; + } + + message ListRecommendationsResponse { + repeated string product_ids = 1; + } + + // ---------------Product Catalog---------------- + + service ProductCatalogService { + rpc ListProducts(Empty) returns (ListProductsResponse) {} + rpc GetProduct(GetProductRequest) returns (Product) {} + rpc SearchProducts(SearchProductsRequest) returns (SearchProductsResponse) {} + } + + message Product { + string id = 1; + string name = 2; + string description = 3; + string picture = 4; + Money price_usd = 5; + + // Categories such as "clothing" or "kitchen" that can be used to look up + // other related products. + repeated string categories = 6; + } + + message ListProductsResponse { + repeated Product products = 1; + } + + message GetProductRequest { + string id = 1; + } + + message SearchProductsRequest { + string query = 1; + } + + message SearchProductsResponse { + repeated Product results = 1; + } + + // ---------------Shipping Service---------- + + service ShippingService { + rpc GetQuote(GetQuoteRequest) returns (GetQuoteResponse) {} + rpc ShipOrder(ShipOrderRequest) returns (ShipOrderResponse) {} + } + + message GetQuoteRequest { + Address address = 1; + repeated CartItem items = 2; + } + + message GetQuoteResponse { + Money cost_usd = 1; + } + + message ShipOrderRequest { + Address address = 1; + repeated CartItem items = 2; + } + + message ShipOrderResponse { + string tracking_id = 1; + } + + message Address { + string street_address = 1; + string city = 2; + string state = 3; + string country = 4; + string zip_code = 5; + } + + // -----------------Currency service----------------- + + service CurrencyService { + rpc GetSupportedCurrencies(Empty) returns (GetSupportedCurrenciesResponse) {} + rpc Convert(CurrencyConversionRequest) returns (Money) {} + } + + // Represents an amount of money with its currency type. + message Money { + // The 3-letter currency code defined in ISO 4217. + string currency_code = 1; + + // The whole units of the amount. + // For example if `currencyCode` is `"USD"`, then 1 unit is one US dollar. + int64 units = 2; + + // Number of nano (10^-9) units of the amount. + // The value must be between -999,999,999 and +999,999,999 inclusive. + // If `units` is positive, `nanos` must be positive or zero. + // If `units` is zero, `nanos` can be positive, zero, or negative. + // If `units` is negative, `nanos` must be negative or zero. + // For example $-1.75 is represented as `units`=-1 and `nanos`=-750,000,000. + int32 nanos = 3; + } + + message GetSupportedCurrenciesResponse { + // The 3-letter currency code defined in ISO 4217. + repeated string currency_codes = 1; + } + + message CurrencyConversionRequest { + Money from = 1; + + // The 3-letter currency code defined in ISO 4217. + string to_code = 2; + } + + // -------------Payment service----------------- + + service PaymentService { + rpc Charge(ChargeRequest) returns (ChargeResponse) {} + } + + message CreditCardInfo { + string credit_card_number = 1; + int32 credit_card_cvv = 2; + int32 credit_card_expiration_year = 3; + int32 credit_card_expiration_month = 4; + } + + message ChargeRequest { + Money amount = 1; + CreditCardInfo credit_card = 2; + } + + message ChargeResponse { + string transaction_id = 1; + } + + // -------------Email service----------------- + + service EmailService { + rpc SendOrderConfirmation(SendOrderConfirmationRequest) returns (Empty) {} + } + + message OrderItem { + CartItem item = 1; + Money cost = 2; + } + + message OrderResult { + string order_id = 1; + string shipping_tracking_id = 2; + Money shipping_cost = 3; + Address shipping_address = 4; + repeated OrderItem items = 5; + } + + message SendOrderConfirmationRequest { + string email = 1; + OrderResult order = 2; + } + + + // -------------Checkout service----------------- + + service CheckoutService { + rpc PlaceOrder(PlaceOrderRequest) returns (PlaceOrderResponse) {} + } + + message PlaceOrderRequest { + string user_id = 1; + string user_currency = 2; + + Address address = 3; + string email = 5; + CreditCardInfo credit_card = 6; + } + + message PlaceOrderResponse { + OrderResult order = 1; + } + + // ------------Ad service------------------ + + service AdService { + rpc GetAds(AdRequest) returns (AdResponse) {} + } + + message AdRequest { + // List of important key words from the current page describing the context. + repeated string context_keys = 1; + } + + message AdResponse { + repeated Ad ads = 1; + } + + message Ad { + // url to redirect to when an ad is clicked. + string redirect_url = 1; + + // short advertisement text to display. + string text = 2; + } + + // ------------Feature flag service------------------ + + service FeatureFlagService { + rpc GetFlag(GetFlagRequest) returns (GetFlagResponse) {} + rpc CreateFlag(CreateFlagRequest) returns (CreateFlagResponse) {} + rpc UpdateFlag(UpdateFlagRequest) returns (UpdateFlagResponse) {} + rpc ListFlags(ListFlagsRequest) returns (ListFlagsResponse) {} + rpc DeleteFlag(DeleteFlagRequest) returns (DeleteFlagResponse) {} + } + + message Flag { + string name = 1; + string description = 2; + bool enabled = 3; + google.protobuf.Timestamp created_at = 4; + google.protobuf.Timestamp updated_at = 5; + } + + message GetFlagRequest { + string name = 1; + } + + message GetFlagResponse { + Flag flag = 1; + } + + message CreateFlagRequest { + string name = 1; + string description = 2; + bool enabled = 3; + } + + message CreateFlagResponse { + Flag flag = 1; + } + + message UpdateFlagRequest { + string name = 1; + bool enabled = 2; + } + + message UpdateFlagResponse {} + + message ListFlagsRequest {} + + message ListFlagsResponse { + repeated Flag flag = 1; + } + + message DeleteFlagRequest { + string name = 1; + } + + message DeleteFlagResponse {} + address: paymentservice:50051 + method: oteldemo.PaymentService.Charge + request: |- + { + "amount": { + "currencyCode": "USD", + "units": 43, + "nanos": 130000000 + }, + "creditCard": { + "creditCardNumber": "0000-0000-0000-0000", + "creditCardCvv": 672, + "creditCardExpirationYear": 2039, + "creditCardExpirationMonth": 1 + } + } + 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"] + 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." diff --git a/test/tracetesting/tech-based-tests/payment-service/invalid-credit-card.yaml b/test/tracetesting/tech-based-tests/payment-service/invalid-credit-card.yaml new file mode 100644 index 0000000000..bb5e16e612 --- /dev/null +++ b/test/tracetesting/tech-based-tests/payment-service/invalid-credit-card.yaml @@ -0,0 +1,356 @@ +# Copyright The OpenTelemetry Authors +# SPDX-License-Identifier: Apache-2.0 + +type: Test +spec: + id: payment-invalid-credit-card + name: 'Payment: invalid credit card' + description: Charge customer with an invalid credit card + trigger: + type: grpc + grpc: + protobufFile: | + // Copyright 2020 Google LLC + // + // Licensed under the Apache License, Version 2.0 (the "License"); + // you may not use this file except in compliance with the License. + // You may obtain a copy of the License at + // + // http://www.apache.org/licenses/LICENSE-2.0 + // + // Unless required by applicable law or agreed to in writing, software + // distributed under the License is distributed on an "AS IS" BASIS, + // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + // See the License for the specific language governing permissions and + // limitations under the License. + + syntax = "proto3"; + + import "google/protobuf/timestamp.proto"; + + package oteldemo; + + option go_package = "genproto/oteldemo"; + + // -----------------Cart service----------------- + + service CartService { + rpc AddItem(AddItemRequest) returns (Empty) {} + rpc GetCart(GetCartRequest) returns (Cart) {} + rpc EmptyCart(EmptyCartRequest) returns (Empty) {} + } + + message CartItem { + string product_id = 1; + int32 quantity = 2; + } + + message AddItemRequest { + string user_id = 1; + CartItem item = 2; + } + + message EmptyCartRequest { + string user_id = 1; + } + + message GetCartRequest { + string user_id = 1; + } + + message Cart { + string user_id = 1; + repeated CartItem items = 2; + } + + message Empty {} + + // ---------------Recommendation service---------- + + service RecommendationService { + rpc ListRecommendations(ListRecommendationsRequest) returns (ListRecommendationsResponse){} + } + + message ListRecommendationsRequest { + string user_id = 1; + repeated string product_ids = 2; + } + + message ListRecommendationsResponse { + repeated string product_ids = 1; + } + + // ---------------Product Catalog---------------- + + service ProductCatalogService { + rpc ListProducts(Empty) returns (ListProductsResponse) {} + rpc GetProduct(GetProductRequest) returns (Product) {} + rpc SearchProducts(SearchProductsRequest) returns (SearchProductsResponse) {} + } + + message Product { + string id = 1; + string name = 2; + string description = 3; + string picture = 4; + Money price_usd = 5; + + // Categories such as "clothing" or "kitchen" that can be used to look up + // other related products. + repeated string categories = 6; + } + + message ListProductsResponse { + repeated Product products = 1; + } + + message GetProductRequest { + string id = 1; + } + + message SearchProductsRequest { + string query = 1; + } + + message SearchProductsResponse { + repeated Product results = 1; + } + + // ---------------Shipping Service---------- + + service ShippingService { + rpc GetQuote(GetQuoteRequest) returns (GetQuoteResponse) {} + rpc ShipOrder(ShipOrderRequest) returns (ShipOrderResponse) {} + } + + message GetQuoteRequest { + Address address = 1; + repeated CartItem items = 2; + } + + message GetQuoteResponse { + Money cost_usd = 1; + } + + message ShipOrderRequest { + Address address = 1; + repeated CartItem items = 2; + } + + message ShipOrderResponse { + string tracking_id = 1; + } + + message Address { + string street_address = 1; + string city = 2; + string state = 3; + string country = 4; + string zip_code = 5; + } + + // -----------------Currency service----------------- + + service CurrencyService { + rpc GetSupportedCurrencies(Empty) returns (GetSupportedCurrenciesResponse) {} + rpc Convert(CurrencyConversionRequest) returns (Money) {} + } + + // Represents an amount of money with its currency type. + message Money { + // The 3-letter currency code defined in ISO 4217. + string currency_code = 1; + + // The whole units of the amount. + // For example if `currencyCode` is `"USD"`, then 1 unit is one US dollar. + int64 units = 2; + + // Number of nano (10^-9) units of the amount. + // The value must be between -999,999,999 and +999,999,999 inclusive. + // If `units` is positive, `nanos` must be positive or zero. + // If `units` is zero, `nanos` can be positive, zero, or negative. + // If `units` is negative, `nanos` must be negative or zero. + // For example $-1.75 is represented as `units`=-1 and `nanos`=-750,000,000. + int32 nanos = 3; + } + + message GetSupportedCurrenciesResponse { + // The 3-letter currency code defined in ISO 4217. + repeated string currency_codes = 1; + } + + message CurrencyConversionRequest { + Money from = 1; + + // The 3-letter currency code defined in ISO 4217. + string to_code = 2; + } + + // -------------Payment service----------------- + + service PaymentService { + rpc Charge(ChargeRequest) returns (ChargeResponse) {} + } + + message CreditCardInfo { + string credit_card_number = 1; + int32 credit_card_cvv = 2; + int32 credit_card_expiration_year = 3; + int32 credit_card_expiration_month = 4; + } + + message ChargeRequest { + Money amount = 1; + CreditCardInfo credit_card = 2; + } + + message ChargeResponse { + string transaction_id = 1; + } + + // -------------Email service----------------- + + service EmailService { + rpc SendOrderConfirmation(SendOrderConfirmationRequest) returns (Empty) {} + } + + message OrderItem { + CartItem item = 1; + Money cost = 2; + } + + message OrderResult { + string order_id = 1; + string shipping_tracking_id = 2; + Money shipping_cost = 3; + Address shipping_address = 4; + repeated OrderItem items = 5; + } + + message SendOrderConfirmationRequest { + string email = 1; + OrderResult order = 2; + } + + + // -------------Checkout service----------------- + + service CheckoutService { + rpc PlaceOrder(PlaceOrderRequest) returns (PlaceOrderResponse) {} + } + + message PlaceOrderRequest { + string user_id = 1; + string user_currency = 2; + + Address address = 3; + string email = 5; + CreditCardInfo credit_card = 6; + } + + message PlaceOrderResponse { + OrderResult order = 1; + } + + // ------------Ad service------------------ + + service AdService { + rpc GetAds(AdRequest) returns (AdResponse) {} + } + + message AdRequest { + // List of important key words from the current page describing the context. + repeated string context_keys = 1; + } + + message AdResponse { + repeated Ad ads = 1; + } + + message Ad { + // url to redirect to when an ad is clicked. + string redirect_url = 1; + + // short advertisement text to display. + string text = 2; + } + + // ------------Feature flag service------------------ + + service FeatureFlagService { + rpc GetFlag(GetFlagRequest) returns (GetFlagResponse) {} + rpc CreateFlag(CreateFlagRequest) returns (CreateFlagResponse) {} + rpc UpdateFlag(UpdateFlagRequest) returns (UpdateFlagResponse) {} + rpc ListFlags(ListFlagsRequest) returns (ListFlagsResponse) {} + rpc DeleteFlag(DeleteFlagRequest) returns (DeleteFlagResponse) {} + } + + message Flag { + string name = 1; + string description = 2; + bool enabled = 3; + google.protobuf.Timestamp created_at = 4; + google.protobuf.Timestamp updated_at = 5; + } + + message GetFlagRequest { + string name = 1; + } + + message GetFlagResponse { + Flag flag = 1; + } + + message CreateFlagRequest { + string name = 1; + string description = 2; + bool enabled = 3; + } + + message CreateFlagResponse { + Flag flag = 1; + } + + message UpdateFlagRequest { + string name = 1; + bool enabled = 2; + } + + message UpdateFlagResponse {} + + message ListFlagsRequest {} + + message ListFlagsResponse { + repeated Flag flag = 1; + } + + message DeleteFlagRequest { + string name = 1; + } + + message DeleteFlagResponse {} + address: paymentservice:50051 + method: oteldemo.PaymentService.Charge + request: |- + { + "amount": { + "currencyCode": "USD", + "units": 43, + "nanos": 130000000 + }, + "creditCard": { + "creditCardNumber": "0000-0000-0000-0000", + "creditCardCvv": 672, + "creditCardExpirationYear": 2039, + "creditCardExpirationMonth": 1 + } + } + 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"] + 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." diff --git a/test/tracetesting/tech-based-tests/payment-service/valid-credit-card.yaml b/test/tracetesting/tech-based-tests/payment-service/valid-credit-card.yaml new file mode 100644 index 0000000000..5cd663c43f --- /dev/null +++ b/test/tracetesting/tech-based-tests/payment-service/valid-credit-card.yaml @@ -0,0 +1,356 @@ +# Copyright The OpenTelemetry Authors +# SPDX-License-Identifier: Apache-2.0 + +type: Test +spec: + id: payment-valid-credit-card + name: 'Payment: valid credit card' + description: Charge customer with a valid credit card + trigger: + type: grpc + grpc: + protobufFile: | + // Copyright 2020 Google LLC + // + // Licensed under the Apache License, Version 2.0 (the "License"); + // you may not use this file except in compliance with the License. + // You may obtain a copy of the License at + // + // http://www.apache.org/licenses/LICENSE-2.0 + // + // Unless required by applicable law or agreed to in writing, software + // distributed under the License is distributed on an "AS IS" BASIS, + // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + // See the License for the specific language governing permissions and + // limitations under the License. + + syntax = "proto3"; + + import "google/protobuf/timestamp.proto"; + + package oteldemo; + + option go_package = "genproto/oteldemo"; + + // -----------------Cart service----------------- + + service CartService { + rpc AddItem(AddItemRequest) returns (Empty) {} + rpc GetCart(GetCartRequest) returns (Cart) {} + rpc EmptyCart(EmptyCartRequest) returns (Empty) {} + } + + message CartItem { + string product_id = 1; + int32 quantity = 2; + } + + message AddItemRequest { + string user_id = 1; + CartItem item = 2; + } + + message EmptyCartRequest { + string user_id = 1; + } + + message GetCartRequest { + string user_id = 1; + } + + message Cart { + string user_id = 1; + repeated CartItem items = 2; + } + + message Empty {} + + // ---------------Recommendation service---------- + + service RecommendationService { + rpc ListRecommendations(ListRecommendationsRequest) returns (ListRecommendationsResponse){} + } + + message ListRecommendationsRequest { + string user_id = 1; + repeated string product_ids = 2; + } + + message ListRecommendationsResponse { + repeated string product_ids = 1; + } + + // ---------------Product Catalog---------------- + + service ProductCatalogService { + rpc ListProducts(Empty) returns (ListProductsResponse) {} + rpc GetProduct(GetProductRequest) returns (Product) {} + rpc SearchProducts(SearchProductsRequest) returns (SearchProductsResponse) {} + } + + message Product { + string id = 1; + string name = 2; + string description = 3; + string picture = 4; + Money price_usd = 5; + + // Categories such as "clothing" or "kitchen" that can be used to look up + // other related products. + repeated string categories = 6; + } + + message ListProductsResponse { + repeated Product products = 1; + } + + message GetProductRequest { + string id = 1; + } + + message SearchProductsRequest { + string query = 1; + } + + message SearchProductsResponse { + repeated Product results = 1; + } + + // ---------------Shipping Service---------- + + service ShippingService { + rpc GetQuote(GetQuoteRequest) returns (GetQuoteResponse) {} + rpc ShipOrder(ShipOrderRequest) returns (ShipOrderResponse) {} + } + + message GetQuoteRequest { + Address address = 1; + repeated CartItem items = 2; + } + + message GetQuoteResponse { + Money cost_usd = 1; + } + + message ShipOrderRequest { + Address address = 1; + repeated CartItem items = 2; + } + + message ShipOrderResponse { + string tracking_id = 1; + } + + message Address { + string street_address = 1; + string city = 2; + string state = 3; + string country = 4; + string zip_code = 5; + } + + // -----------------Currency service----------------- + + service CurrencyService { + rpc GetSupportedCurrencies(Empty) returns (GetSupportedCurrenciesResponse) {} + rpc Convert(CurrencyConversionRequest) returns (Money) {} + } + + // Represents an amount of money with its currency type. + message Money { + // The 3-letter currency code defined in ISO 4217. + string currency_code = 1; + + // The whole units of the amount. + // For example if `currencyCode` is `"USD"`, then 1 unit is one US dollar. + int64 units = 2; + + // Number of nano (10^-9) units of the amount. + // The value must be between -999,999,999 and +999,999,999 inclusive. + // If `units` is positive, `nanos` must be positive or zero. + // If `units` is zero, `nanos` can be positive, zero, or negative. + // If `units` is negative, `nanos` must be negative or zero. + // For example $-1.75 is represented as `units`=-1 and `nanos`=-750,000,000. + int32 nanos = 3; + } + + message GetSupportedCurrenciesResponse { + // The 3-letter currency code defined in ISO 4217. + repeated string currency_codes = 1; + } + + message CurrencyConversionRequest { + Money from = 1; + + // The 3-letter currency code defined in ISO 4217. + string to_code = 2; + } + + // -------------Payment service----------------- + + service PaymentService { + rpc Charge(ChargeRequest) returns (ChargeResponse) {} + } + + message CreditCardInfo { + string credit_card_number = 1; + int32 credit_card_cvv = 2; + int32 credit_card_expiration_year = 3; + int32 credit_card_expiration_month = 4; + } + + message ChargeRequest { + Money amount = 1; + CreditCardInfo credit_card = 2; + } + + message ChargeResponse { + string transaction_id = 1; + } + + // -------------Email service----------------- + + service EmailService { + rpc SendOrderConfirmation(SendOrderConfirmationRequest) returns (Empty) {} + } + + message OrderItem { + CartItem item = 1; + Money cost = 2; + } + + message OrderResult { + string order_id = 1; + string shipping_tracking_id = 2; + Money shipping_cost = 3; + Address shipping_address = 4; + repeated OrderItem items = 5; + } + + message SendOrderConfirmationRequest { + string email = 1; + OrderResult order = 2; + } + + + // -------------Checkout service----------------- + + service CheckoutService { + rpc PlaceOrder(PlaceOrderRequest) returns (PlaceOrderResponse) {} + } + + message PlaceOrderRequest { + string user_id = 1; + string user_currency = 2; + + Address address = 3; + string email = 5; + CreditCardInfo credit_card = 6; + } + + message PlaceOrderResponse { + OrderResult order = 1; + } + + // ------------Ad service------------------ + + service AdService { + rpc GetAds(AdRequest) returns (AdResponse) {} + } + + message AdRequest { + // List of important key words from the current page describing the context. + repeated string context_keys = 1; + } + + message AdResponse { + repeated Ad ads = 1; + } + + message Ad { + // url to redirect to when an ad is clicked. + string redirect_url = 1; + + // short advertisement text to display. + string text = 2; + } + + // ------------Feature flag service------------------ + + service FeatureFlagService { + rpc GetFlag(GetFlagRequest) returns (GetFlagResponse) {} + rpc CreateFlag(CreateFlagRequest) returns (CreateFlagResponse) {} + rpc UpdateFlag(UpdateFlagRequest) returns (UpdateFlagResponse) {} + rpc ListFlags(ListFlagsRequest) returns (ListFlagsResponse) {} + rpc DeleteFlag(DeleteFlagRequest) returns (DeleteFlagResponse) {} + } + + message Flag { + string name = 1; + string description = 2; + bool enabled = 3; + google.protobuf.Timestamp created_at = 4; + google.protobuf.Timestamp updated_at = 5; + } + + message GetFlagRequest { + string name = 1; + } + + message GetFlagResponse { + Flag flag = 1; + } + + message CreateFlagRequest { + string name = 1; + string description = 2; + bool enabled = 3; + } + + message CreateFlagResponse { + Flag flag = 1; + } + + message UpdateFlagRequest { + string name = 1; + bool enabled = 2; + } + + message UpdateFlagResponse {} + + message ListFlagsRequest {} + + message ListFlagsResponse { + repeated Flag flag = 1; + } + + message DeleteFlagRequest { + string name = 1; + } + + message DeleteFlagResponse {} + address: paymentservice:50051 + method: oteldemo.PaymentService.Charge + request: |- + { + "amount": { + "currencyCode": "USD", + "units": 43, + "nanos": 130000000 + }, + "creditCard": { + "creditCardNumber": "4432-8015-6152-0454", + "creditCardCvv": 672, + "creditCardExpirationYear": 2021, + "creditCardExpirationMonth": 1 + } + } + specs: + - name: It should call Charge method successfully + 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 = 0 + - name: It should return a transaction ID + selector: span[tracetest.span.type="general" name="Tracetest trigger"] + assertions: + - attr:tracetest.response.body| json_path '$.transactionId' != ""