Ensuring Code Changes do not Break Microservice REST APIs, as Part of Pull Request Validation

Published Jul 13 2021 12:22 AM 5,080 Views
Microsoft

Typically Integrated microservice APIs are tested quite late in the Application lifecycle, where the application code which has already been merged into the main branch, is then deployed to an environment, after which the API tests are executed. Detection of failures at this stage means that your main branch is already in an unclean / un deployable state

In this post we look at a Webvalidate based test harness which in many cases would enable us to validate that the changes introduced in a Pull Request (PR) do not break the Microservice API.

 

What we will be building?

 

Our objective is to shift the microservice API tests left, and execute them as a part of PR validation itself, using Azure Pipelines.  To enable this for a sample RESTful Microservice (backed by a document database) we need to build a PR pipeline / test harness which allows us to achieve these requirements:

  • The PR validation pipeline needs to execute on Azure Pipelines hosted agents (to keep cost of executing these tests to a minimum when executing for reach PR)
  • Following steps need to happen as a part of the PR validation pipeline:
    • Execute the service along with its virtualised dependencies.
    • Setup virtualized test harness components (components which enables us to setup test data for the Application, and to execute tests against the APIs)
    • Setup Test Data in collection / DB
    • Execute API Tests
    • Validate and Publish API Test Results.
    • The pipeline should fail if all API tests are not successful, there by preventing the pull request to get merged in to the main branch

API-build-validationv0.3.jpg

 

Sample Microservice

For this post we will be looking at the Books service as the Microservice for which the APIs need to be tested during PR validation. The initial code for Books API has been taken from the dotnet samples and tweaked for purpose of this post.

 

It is a simple API supporting basic CRUD operations for Books (Add, Delete , Put, Get one, List etc). The datastore which this microservice relies on is a Mongodb collection.

 

manisbindra_0-1625736588730.png

Application configurations like mongodb connection string, database name and collection name are injected using environment variables. We later look at how these are injected as part of the PR Validation pipeline.

 

With a few minor modifications (which will be covered later in this post), the test harness can also work if the application fetches configurations using Default Azure Credentials, Azure App Config and Azure Key Vault.

 

What is webvalidate?

The microsoft/webvalidate tool enables us to define tests cases and validations as simple JSON objects as shown below:

 

{
        "path": "/api/books/60e304aac7b8d60001b2d3cd",
        "verb": "Get",
        "tag": "GetNonExistentBook",
        "failOnValidationError": true,
        "validation": {
          "statusCode": 404,
          "contentType": "application/problem+json;"
        }
}

 

In this test case with tag "GetNonExistentBook" we assert that a request to get a book with id "60e304aac7b8d60001b2d3cd" would return a HTTP status code of 404 as book with that Id is not expected to exist. Complex validations as shown in the webvalidate samples can also be easily achieved. 

 

Code supporting this Post

The working code referenced in this post is available at the api-test-harness-webv github Repo This includes the tweaked api application code as well as the dockerfile, docker-compose file, test harness scripts, test data, and webvalidate test cases.

 

Overview of the key folder and files in this repository:

  • /BooksApi : This folder contains the dotnet code for the Books service. In addition this folder contains
    • /BooksApi/Dockerfile: This is the docker file for the service
    • /BooksApi/dockerComposeBooksApiTest.yml:  This is the API test harness orchestrator. This docker-compose file is used to bring up the service and mongo database, load the test data into the mongo collection, and execute webvalidate API tests against the APIs. We will look at this file in more detail in the next section.
  • /TestFiles: This folder containers test data, test cases and scripts required for load test data, executing tests, and for publishing API test data to Azure Pipelines Dashboard. Let us look at the a couple of its subfolders in more detail
    • /TestFiles/ApiTests/Data/BooksTestData.json: This file has the test mongodb data to be setup which the webvalidate tests will assert against. We will look at this file in more detail in the next section.
    • /TestFiles/ApiTests/TestCases/BooksTestCases.json: This file contains the webvalidate test cases to validate that the API functionality is not broken. We will look at this file in more detail in the next section
    • /TestFiles/scripts/import.sh: This script is used by the test harness to load the BooksTestData.json data into the mongodb collection used by the Books service
    • /TestFiles/scripts/executeTests.sh: This script is used by the test harness to execute webvalidate test cases against the Books API. The test results are output in the webvalidate json format
    • /TestFiles/scripts/webvtoJunit.py: This file is used to convert the webvalidate format test results into JUnit format, which can then be published to an Azure Pipelines Dashboard.
  • /ApiTestsAzurePipelines.yamlThis is the PR validation pipeline file. This pipeline is configured as a build validation pipeline for the main branch, and is triggered for each PR targeting the main branch. This pipeline is responsible for tying everything together, i.e. Bring up the virtualized application, database and test harness components , setting up the test data, executing the tests, and finally validating and publishing the test results. If any of the tests fail the PR shows a build validation failure, and prevents the PR from getting merged into the main branch

 

Digging Deeper into the key files

 

Mongodb collection test data - /TestFiles/ApiTests/Data/BooksTestData.json

 

[
    {
        "_id": {
            "$oid": "60e2e8fe7ed72f0001bf3a41"
        },
        "Name": "The Go Programming Language",
        "Price": 20,
        "Category": "Computer Programming",
        "Author": "Alan Donovan"
    },
    {
        "_id": {
            "$oid": "60e2e8fe7ed72f0001bf3a46"
        },
        "Name": "Design Patterns",
        "Price": 54.93,
        "Category": "Computers",
        "Author": "Ralph Johnson"
    }
]

 

  • This file contains the mongodb test data documents against which we will execute the webvalidate test cases. As we can see the format of _id column is in the mongodb compliant format
  • There are 2 test data documents which will be added in this case one for the book "The Go Programming Language" and the other for the book "Design Patterns"

 

Webvalidate Test Cases - /TestFiles/ApiTests/TestCases/BooksTestCases.json

 

{
    "requests": [
      {
        "path": "/api/books",
        "verb": "POST",
        "tag": "CreateBookValidRequest",
        "failOnValidationError": true,
        "body": "{\"Name\":\"Kubernetes Up and Running\",\r\n\"Price\":25,\r\n\"Category\":\"Computer Programming\",\r\n\"Author\":\"Adam Barr\"\r\n}",
        "contentMediaType": "application/json-patch+json",
        "validation": {
          "statusCode": 201,
          "contentType": "application/json",
          "jsonObject": [
            {
              "field": "Id"
            },
            {
              "field": "Name",
              "value": "Kubernetes Up and Running"
            },
            {
                "field": "Price",
                "value": 25
            }
          ]
        }
      },
      {
        "path": "/api/books",
        "verb": "POST",
        "tag": "CreateBookInvalidPrice",
        "failOnValidationError": true,
        "body": "{\"Name\":\"Kubernetes Up and Running\",\r\n\"Price\":\"twenty five\",\r\n\"Category\":\"Computer Programming\",\r\n\"Author\":\"Adam Barr\"\r\n}",
        "contentMediaType": "application/json-patch+json",
        "validation": {
          "statusCode": 400,
          "contentType": "application/problem+json;",
          "jsonObject": [
            {
              "field": "errors",
              "validation": {
                "jsonObject": [
                  { "field": "Price" }
                ]
              }
            }
          ]
        }
      },
      {
        "path": "/api/books/60e304aac7b8d60001b2d3cd",
        "verb": "Get",
        "tag": "GetNonExistentBook",
        "failOnValidationError": true,
        "validation": {
          "statusCode": 404,
          "contentType": "application/problem+json;"
        }
      },
      {
        "path": "/api/books/60e2e8fe7ed72f0001bf3a41",
        "verb": "Get",
        "tag": "GetExistingBook",
        "failOnValidationError": true,
        "validation": {
          "statusCode": 200,
          "contentType": "application/json",
          "exactMatch": "{\"Id\":\"60e2e8fe7ed72f0001bf3a41\",\"Name\":\"The Go Programming Language\",\"Price\":20.0,\"Category\":\"Computer Programming\",\"Author\":\"Alan Donovan\"}"
        }
      }
      
    ]
  }
  

 

  • This file contains 4 webvalidate format test cases which will be executed against the Books service and responses validated
  • The first test case with tag CreateBookValidRequest does a post against the API, the stringified json body element of this test case has the details of the book we are trying to create. Since the request is valid, the validation element of this test case contains the validations which are applied to the response, mainly :
    • HTTP response status code is 201
    • The response has an Id element corresponding to the unique id of the created book
    • The field Name in the response has value Kubernetes Up and Running
    • and the field Price in the response has value 25
  • The second test case with tag CreateBookInvalidPrice tries to create a book with invalid price (which is a string) in the body . This test case then validates that the http response status code is 400. It also validates that the HTTP response indicates that error is due to the field Price.
  • The third test case with tag GetNonExistentBook tries to do GET a book with id 60e304aac7b8d60001b2d3cd, which we did not add as a part of our test data. The test case then validates that the received status code is 404
  • Our fourth and final test case with tag GetExistingBook tries to GET a book with id 60e2e8fe7ed72f0001bf3a41. Since we added the test data for the book with this id (in/TestFiles/ApiTests/Data/BooksTestData.json) this book should exist. The test case then validates response status code is 200, the test case also validates the exact match against the expected response body. Since the response is based on the test data we created, we can assert using exact match feature of webvalidate.

 

PR Validation Azure Pipeline Yaml file - /ApiTestsAzurePipelines.yaml

 

.
.
steps:

- script: |
      cd $(System.DefaultWorkingDirectory)
      docker-compose -f BooksApi/dockerComposeBooksApiTest.yml build --no-cache  --build-arg ENVIRONMENT=local     
      docker-compose -f BooksApi/dockerComposeBooksApiTest.yml up --exit-code-from webv | tee $(System.DefaultWorkingDirectory)/dc.log
  displayName: "Execute API Tests"

- script: |
      # Pass parameters: path to docker-compose log file, path to output Junit file, and path to scripts directory
      bash $(System.DefaultWorkingDirectory)/TestFiles/scripts/webvToJunit.sh $(System.DefaultWorkingDirectory)/dc.log $(System.DefaultWorkingDirectory)/junit.xml $(System.DefaultWorkingDirectory)/TestFiles/scripts
  displayName: "Convert Test Execution Log output to JUnit Format"

- task: PublishTestResults@2
  displayName: 'Validate and Publish Component Test Results'
  inputs:
    testResultsFormat: JUnit
    testResultsFiles: 'junit.xml'
    searchFolder: $(System.DefaultWorkingDirectory)
    testRunTitle: 'webapitestrestults'
    failTaskOnFailedTests: true

 

There are 3 main steps in this PR validation Azure Pipeline file:

  • We build the/BooksApi/dockerComposeBooksApiTest.yml docker-compose file, which builds the microservice code. Next we execute the docker-compose up with the docker compose file. This command brings up the microservice, mongodb database container, mongodb import container, and webvalidate container. This also configures the service to use a specific mongodb collection. Next the mongodb import container loads the test data into the mongodb collection, and finally the webvalidate container executes the tests and outputs the results. and we all forwarded common logs to a file, which can then be parsed to extract the webvalidate test results in the following step. One point to note here is that in the current configuration the build argument "ENVIRONMENT=local" is not adding any value, however for more complex application configurations, like for instance, where the application needs to fetch its configurations using say DefaultAzureCredentials, Azure App Config and Azure Key Vault, this environment variable can be used in the dockerfile to conditionally install things like az cli (in which case in the docker-compose file we would mount the ~/.azure directory to enable the DefaultAzureCredentials library to fetch the azure credentilas in this local execution environment, which would then enable the application to connect to things like Azure app configuration). 
  • In the next step the docker compose file is parsed to fetch the webvalidate results, the results are then transformed in to the JUnit format
  • Finally the webvalidate results are published to Azure Pipelines dashboard. If there are any webvalidate test failures, the build validation fails and the PR modifcations cannot be merged in to the main branch

 

Docker Compose API Test Harness - /BooksApi/dockerComposeBooksApiTest.yml

 

version: '3'
services:
  booksapi:
    build:
      context: .
      dockerfile: ./Dockerfile
    ports:
      - '5011:80'
    networks:
      - books
    # volumes:
    #   - ${HOME}/.azure:/root/.azure
    environment:
      - BookstoreDatabaseSettings__ConnectionString=mongodb://mongo:27017
      - BookstoreDatabaseSettings__DatabaseName=BookstoreDb
      - BookstoreDatabaseSettings__BooksCollectionName=Books
    
  mongo:
    container_name: books.mongo
    image: mongo:4.4
    networks:
      - books
  
  mongo-import:
    image: mongo:4.4
    depends_on:
    - mongo
    volumes:
    - ../TestFiles:/testFiles/
    - ../TestFiles/scripts/import.sh:/command/import.sh
    - ../TestFiles/scripts/index.js:/command/index.js
    networks:
      - books
    environment:
    - MONGO_URI=mongodb://mongo:27017
    - MONGO_DB=BookstoreDb
    - MONGO_COLL=Books
    - TEST_TYPE=ApiTests
    entrypoint: /command/import.sh

  webv:
    image: retaildevcrew/webvalidate@sha256:183228cb62915e7ecac72fa0746fed4f7127a546428229291e6eeb202b2a5973
    depends_on:
    - mongo
    - booksapi
    volumes:
    - ../TestFiles:/testFiles/
    - ../TestFiles/scripts/executeTests.sh:/command/executeTests.sh
    networks:
      - books
    environment:
    - TEST_TYPE=ApiTests
    - TEST_SVC_ENDPOINT=http://booksapi
    - TEST_DATA_LOAD_DELAY=25
    entrypoint: ["/bin/sh","/command/executeTests.sh"]

networks:
  books:

 

  • The booksapi docker-compose service brings up the microservice. Mongo db configurations are passed in as environment settings
  • mongo docker-compose service brings up the mongodb db container.
  • mongo-import docker-compose service brings up the mongo db container which is used to load the test data from /TestFiles/ApiTests/Data/BooksTestData.json file into the configured mongo db (mongo docker-compose service) collection. The startup script used by this container is /TestFiles/scripts/import.sh
  • Finally the webvalidate docker-compose service brings up the webvalidate container. This container waits for configured delay before executing the webvalidate tests defined in /TestFiles/ApiTests/TestCases/BooksTestCases.json against the booksapi service. The startup script used by this container is /TestFiles/scripts/executeTests.sh

 

The Test harness in action

 

Abstract from execution stage log

 

.
Successfully built b312635a0c59
Successfully tagged booksapi_booksapi:latest
.
.
Creating books.mongo ... 
Creating booksapi_booksapi_1 ... 
Creating books.mongo         ... done
Creating booksapi_mongo-import_1 ... 
Creating booksapi_booksapi_1     ... done
Creating booksapi_webv_1         ... 
Creating booksapi_mongo-import_1 ... done
Creating booksapi_webv_1         ... done
Attaching to books.mongo, booksapi_booksapi_1, booksapi_mongo-import_1, booksapi_webv_1
.
.
mongo-import_1  | 2021-07-12T07:23:29.882+0000	2 document(s) imported successfully. 0 document(s) failed to import.
.
.
webv_1          | {"date":"2021-07-12T07:23:55.3355122Z","verb":"POST","server":"http://booksapi","statusCode":201,"failed":false,"validated":true,"correlationVector":"MtKp\u002BU7CpE6VAJLRF/kGlQ.0","errorCount":0,"duration":550,"contentLength":136,"category":"","tag":"CreateBookValidRequest","path":"/api/books","errors":[]}
.
.
Stopping booksapi_mongo-import_1 ... 
Stopping booksapi_booksapi_1     ... 
Stopping books.mongo             ... 
Stopping booksapi_booksapi_1     ... done
Stopping booksapi_mongo-import_1 ... done
Stopping books.mongo             ... done
Aborting on container exit...


 

  • First the containers are started (mongo, booksapi, mongo-import and webv)
  • After that the mongo-import container add the 2 test documents into the booksapi mongodb collection
  • After which there is an entry for each webvalidate test case in json format, which has all details of the execution
  • After webvalidate testcase execution is complete, the webv container exists, causing docker-compose to terminate all other containers

 

Failure Scenario

Before testing the harness, we need to create an Azure Pipeline using out PR Validation Pipeline yaml file, and then configure this pipeline to execute as part of main branch build validation. For simplicity to cause the API test to fail let us modify the CreateBookValidRequest webvalidate test case to expect a Price of 26 in the response instead of 25, as shown in the commit

manisbindra_0-1625834392977.png

 

Once a Pull request is created, we should see the PR validation build kicking in, and then failing in a couple of minutes as shown:

PR-created-1.jpg

 

Next we drill down into the pipeline and choose the Tests tab, which gives us an overview of the test execution. Where we see that 1 of the 4 tests has failed:

test-failure-overview.jpg

 

On clicking the failed test, the error details window shows us the reason of the error (Actual Price "25", Expected Price "26")

manisbindra_1-1625835368580.png

 

Since this is a required check for the PR, merging of the PR is blocked:

manisbindra_0-1626073514846.png

 

Success Scenario

As we can see below if the PR validation is successful, the changes can be approved and merged:

manisbindra_0-1626075477709.png

 

Limitations of this Approach and Other Considerations

There are a few limitations of this simplistic API testing during PR validation approach:

  • Here since the Microservice has a single main dependency (mongodb) which can be containerized, as a result it was possible to use docker-compose to containerize 4 containers (booksapi, mongodb, mongo-import and webvalidate) on a single Azure Pipelines hosted agent. For more complex scenarios where the microservice depends on multiple other microservices each with their own dependencies, then this approach will not work. For such deployments other options like Bridge to Kubernetes may be evaluated.
  • In case the microservice has dependency on a single database which cannot be containerized, like a cloud based service, then the test harness will need to be modified to initialize the cloud database each time the PR validation pipeline executes, and taking care that parallel executions do not interfere with each other (perhaps creating unique test collection for each execution, which is then torn down after test execution)
  • In this case docker-compose was selected as the pipeline orchestrator as the inner loop development process on the developer machines was using docker-compose. Kind Cluster can also be used on the Azure Pipelines hosted agent.
  • We need to bear mind that in this approach we are using a virtualized database (mongodb), and some features are different on the virtualized database as compared to corresponding cloud based services (like Mongodb Atlas), so it is possible that some tests which are passing in our PR validation pipeline (on Azure Pipelines hosted agent), might fail in proper integration testing environment where the microservice is connected to the actual service (Like Mongodb Atlas). 
  • A feature request has been made in the webvalidate github repo to include option for directly exporting results to Junit format. Once this feature is available in the next release of webvalidate, we will not need to have a step in the pipeline which transforms the test results in the Junit format.

 

Thanks for reading this post. I hope you liked it. Please feel free to write your comments and views about the same over here or at @manisbindra

 

%3CLINGO-SUB%20id%3D%22lingo-sub-2526554%22%20slang%3D%22en-US%22%3EEnsuring%20Code%20Changes%20do%20not%20Break%20Microservice%20REST%20APIs%2C%20as%20Part%20of%20Pull%20Request%20Validation%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2526554%22%20slang%3D%22en-US%22%3E%3CP%3ETypically%20Integrated%3CSTRONG%3E%20microservice%20APIs%20%3C%2FSTRONG%3Eare%3CSTRONG%3E%20tested%20quite%20late%20in%20the%20Application%20lifecycle%3C%2FSTRONG%3E%2C%20where%20the%20application%20code%20which%20has%20already%20been%20merged%20into%20the%20main%20branch%2C%20is%20then%20deployed%20to%20an%20environment%2C%20after%20which%20the%20API%20tests%20are%20executed.%20Detection%20of%20failures%20at%20this%20stage%20means%20that%20your%20%3CSTRONG%3Emain%20branch%20is%20already%20in%20an%20unclean%20%2F%20un%20deployable%20state%3C%2FSTRONG%3E.%26nbsp%3B%3C%2FP%3E%0A%3CP%3EIn%20this%20post%20we%20look%20at%20a%20%3CSTRONG%3EWebvalidate%20%3C%2FSTRONG%3Ebased%20%3CSTRONG%3Etest%20harness%20%3C%2FSTRONG%3Ewhich%20in%20many%20cases%20would%20enable%20us%20to%20validate%20that%20the%26nbsp%3B%3CSTRONG%3Echanges%20introduced%20in%20a%20Pull%20Request%20(PR)%20do%20not%20break%20the%20Microservice%20API%3C%2FSTRONG%3E.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CH2%20id%3D%22toc-hId--411466843%22%20id%3D%22toc-hId--411466843%22%3E%3CSTRONG%3EWhat%20we%20will%20be%20building%3F%3C%2FSTRONG%3E%3C%2FH2%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3EOur%20objective%20is%20to%20shift%20the%20microservice%20API%20tests%20left%2C%20and%20execute%20them%20as%20a%20part%20of%20PR%20validation%20itself%2C%20using%20Azure%20Pipelines.%26nbsp%3B%20%3C%2FSTRONG%3ETo%20enable%20this%20for%20a%20sample%20RESTful%20Microservice%20(backed%20by%20a%20document%20database)%20we%20need%20to%20build%20a%20PR%20pipeline%20%2F%20test%20harness%20which%20allows%20us%20to%20achieve%20these%20requirements%3CSTRONG%3E%3A%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CUL%3E%0A%3CLI%3EThe%20PR%20validation%20pipeline%20needs%20to%20execute%20on%20Azure%20Pipelines%20hosted%20agents%20(to%20keep%20cost%20of%20executing%20these%20tests%20to%20a%20minimum%20when%20executing%20for%20reach%20PR)%3C%2FLI%3E%0A%3CLI%3EFollowing%20steps%20need%20to%20happen%20as%20a%20part%20of%20the%20PR%20validation%20pipeline%3A%3C%2FLI%3E%0A%3CUL%3E%0A%3CLI%3EExecute%20the%20service%20along%20with%20its%20virtualised%20dependencies.%3C%2FLI%3E%0A%3CLI%3ESetup%20virtualized%20test%20harness%20components%20(components%20which%20enables%20us%20to%20setup%20test%20data%20for%20the%20Application%2C%20and%20to%20execute%20tests%20against%20the%20APIs)%3C%2FLI%3E%0A%3CLI%3ESetup%20Test%20Data%20in%20collection%20%2F%20DB%3C%2FLI%3E%0A%3CLI%3EExecute%20API%20Tests%3C%2FLI%3E%0A%3CLI%3EValidate%20and%20Publish%20API%20Test%20Results.%3C%2FLI%3E%0A%3CLI%3E%3CSTRONG%3EThe%20pipeline%20should%20fail%20if%20all%20API%20tests%20are%20not%20successful%2C%20there%20by%20preventing%20the%20pull%20request%20to%20get%20merged%20in%20to%20the%20main%20branch%3C%2FSTRONG%3E%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3C%2FUL%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22API-build-validationv0.3.jpg%22%20style%3D%22width%3A%20999px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F294247iF17F48A67F3E80DF%2Fimage-size%2Flarge%3Fv%3Dv2%26amp%3Bpx%3D999%22%20role%3D%22button%22%20title%3D%22API-build-validationv0.3.jpg%22%20alt%3D%22API-build-validationv0.3.jpg%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3E%26nbsp%3B%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CH2%20id%3D%22toc-hId-2076045990%22%20id%3D%22toc-hId-2076045990%22%3E%3CSTRONG%3ESample%20Microservice%3C%2FSTRONG%3E%3C%2FH2%3E%0A%3CP%3EFor%20this%20post%20we%20will%20be%20looking%20at%20the%20Books%20service%20as%20the%20Microservice%20for%20which%20the%20APIs%20need%20to%20be%20tested%20during%20PR%20validation.%20The%20initial%20code%20for%20Books%20API%20has%20been%20taken%20from%20the%20%3CA%20href%3D%22https%3A%2F%2Fgithub.com%2Fdotnet%2FAspNetCore.Docs%2Ftree%2Fmain%2Faspnetcore%2Ftutorials%2Ffirst-mongo-app%2Fsamples%2F3.x%2FSampleApp%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3Edotnet%20samples%3C%2FA%3E%20and%20tweaked%20for%20purpose%20of%20this%20post.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EIt%20is%20a%20simple%20API%20supporting%20basic%20CRUD%20operations%20for%20Books%20(Add%2C%20Delete%20%2C%20Put%2C%20Get%20one%2C%20List%20etc).%20The%20datastore%20which%20this%20microservice%20relies%20on%20is%20a%20Mongodb%20collection.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22manisbindra_0-1625736588730.png%22%20style%3D%22width%3A%20400px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F294248i36F48B5E0171CFDA%2Fimage-size%2Fmedium%3Fv%3Dv2%26amp%3Bpx%3D400%22%20role%3D%22button%22%20title%3D%22manisbindra_0-1625736588730.png%22%20alt%3D%22manisbindra_0-1625736588730.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3EApplication%20configurations%20like%20mongodb%20connection%20string%2C%20database%20name%20and%20collection%20name%20are%20injected%20using%20environment%20variables.%20We%20later%20look%20at%20how%20these%20are%20injected%20as%20part%20of%20the%20PR%20Validation%20pipeline.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EWith%20a%20few%20minor%20modifications%20(which%20will%20be%20covered%20later%20in%20this%20post)%2C%20the%20test%20harness%20can%20also%20work%20if%26nbsp%3Bthe%20application%20fetches%20configurations%20using%20Default%20Azure%20Credentials%2C%20Azure%20App%20Config%20and%20Azure%20Key%20Vault.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CH2%20id%3D%22toc-hId-268591527%22%20id%3D%22toc-hId-268591527%22%3E%3CSTRONG%3EWhat%20is%20webvalidate%3F%3C%2FSTRONG%3E%3C%2FH2%3E%0A%3CP%20data-unlink%3D%22true%22%3EThe%26nbsp%3B%3CA%20href%3D%22https%3A%2F%2Fgithub.com%2Fmicrosoft%2Fwebvalidate%22%20target%3D%22_self%22%20rel%3D%22noopener%20noreferrer%22%3Emicrosoft%2Fwebvalidate%3C%2FA%3E%26nbsp%3Btool%20enables%26nbsp%3B%3CSPAN%3Eus%20to%20define%20tests%20cases%20and%20validations%20as%20simple%20JSON%20objects%20as%20shown%20below%3A%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%20class%3D%22lia-code-sample%20language-json%22%3E%3CCODE%3E%7B%0A%20%20%20%20%20%20%20%20%22path%22%3A%20%22%2Fapi%2Fbooks%2F60e304aac7b8d60001b2d3cd%22%2C%0A%20%20%20%20%20%20%20%20%22verb%22%3A%20%22Get%22%2C%0A%20%20%20%20%20%20%20%20%22tag%22%3A%20%22GetNonExistentBook%22%2C%0A%20%20%20%20%20%20%20%20%22failOnValidationError%22%3A%20true%2C%0A%20%20%20%20%20%20%20%20%22validation%22%3A%20%7B%0A%20%20%20%20%20%20%20%20%20%20%22statusCode%22%3A%20404%2C%0A%20%20%20%20%20%20%20%20%20%20%22contentType%22%3A%20%22application%2Fproblem%2Bjson%3B%22%0A%20%20%20%20%20%20%20%20%7D%0A%7D%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EIn%20this%20test%20case%20with%20tag%20%22%3CSPAN%3E%3CSTRONG%3EGetNonExistentBook%3C%2FSTRONG%3E%22%20we%20assert%20that%20a%20request%20to%20get%20a%20book%20with%20id%20%2260e304aac7b8d60001b2d3cd%22%20would%20return%20a%20HTTP%20status%20code%20of%20404%20as%20book%20with%20that%20Id%20is%20not%20expected%20to%20exist.%26nbsp%3BComplex%20validations%20as%20shown%20in%20the%20%3CA%20href%3D%22https%3A%2F%2Fgithub.com%2Fmicrosoft%2Fwebvalidate%2Fblob%2Fmain%2Fsrc%2Fapp%2Fgithub.json%22%20target%3D%22_self%22%20rel%3D%22noopener%20noreferrer%22%3Ewebvalidate%20samples%3C%2FA%3E%26nbsp%3Bcan%20also%20be%20easily%20achieved.%26nbsp%3B%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CH2%20id%3D%22toc-hId--1538862936%22%20id%3D%22toc-hId--1538862936%22%3E%3CSTRONG%3ECode%20supporting%20this%20Post%3C%2FSTRONG%3E%3C%2FH2%3E%0A%3CP%3EThe%20working%20code%20referenced%20in%20this%20post%20is%20available%20at%20the%20%3CA%20href%3D%22https%3A%2F%2Fgithub.com%2FmaniSbindra%2Fapi-test-harness-webv%22%20target%3D%22_self%22%20rel%3D%22noopener%20noreferrer%22%3Eapi-test-harness-webv%20github%20Repo%3C%2FA%3E%3CSTRONG%3E%20.%26nbsp%3B%3C%2FSTRONG%3E%26nbsp%3BThis%20includes%20the%20tweaked%20api%20application%20code%20as%20well%20as%20the%20dockerfile%2C%20docker-compose%20file%2C%20test%20harness%20scripts%2C%20test%20data%2C%20and%20webvalidate%20test%20cases.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3EOverview%20of%20the%20key%20folder%20and%20files%20in%20this%20repository%3A%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CUL%3E%0A%3CLI%3E%3CSTRONG%3E%2FBooksApi%3C%2FSTRONG%3E%20%3A%20This%20folder%20contains%20the%20dotnet%20code%20for%20the%20Books%20service.%20In%20addition%20this%20folder%20contains%3CUL%3E%0A%3CLI%3E%3CA%20href%3D%22https%3A%2F%2Fgithub.com%2FmaniSbindra%2Fapi-test-harness-webv%2Fblob%2Fmaster%2FBooksApi%2FDockerfile%22%20target%3D%22_self%22%20rel%3D%22noopener%20noreferrer%22%3E%2FBooksApi%2FDockerfile%3C%2FA%3E%3CSTRONG%3E%3A%3C%2FSTRONG%3E%26nbsp%3BThis%20is%20the%20docker%20file%20for%20the%20service%3C%2FLI%3E%0A%3CLI%3E%3CA%20href%3D%22https%3A%2F%2Fgithub.com%2FmaniSbindra%2Fapi-test-harness-webv%2Fblob%2Fmaster%2FBooksApi%2FdockerComposeBooksApiTest.yml%22%20target%3D%22_self%22%20rel%3D%22noopener%20noreferrer%22%3E%2FBooksApi%2FdockerComposeBooksApiTest.yml%3C%2FA%3E%3CSTRONG%3E%3A%3C%2FSTRONG%3E%20%3CSTRONG%3E%26nbsp%3B%3C%2FSTRONG%3EThis%20is%20the%20%3CSTRONG%3EAPI%20test%20harness%20orchestrator.%3C%2FSTRONG%3E%26nbsp%3BThis%20%3CSTRONG%3Edocker-compose%20file%3C%2FSTRONG%3E%20is%20used%20to%20%3CSTRONG%3Ebring%20up%20the%20service%20and%20mongo%20database%3C%2FSTRONG%3E%2C%20%3CSTRONG%3Eload%20the%20test%20data%3C%2FSTRONG%3E%20into%20the%20mongo%20collection%2C%20and%3CSTRONG%3E%20execute%20webvalidate%20API%20tests%3C%2FSTRONG%3E%20against%20the%20APIs.%20We%20will%20look%20at%20this%20file%20in%20more%20detail%20in%20the%20next%20section.%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3C%2FLI%3E%0A%3CLI%3E%3CSTRONG%3E%2FTestFiles%3A%26nbsp%3B%3C%2FSTRONG%3EThis%20folder%20containers%20test%20data%2C%20test%20cases%20and%20scripts%20required%20for%20load%20test%20data%2C%20executing%20tests%2C%20and%20for%20publishing%20API%20test%20data%20to%20Azure%20Pipelines%20Dashboard.%20Let%20us%20look%20at%20the%20a%20couple%20of%20its%20subfolders%20in%20more%20detail%3CUL%3E%0A%3CLI%3E%3CA%20href%3D%22https%3A%2F%2Fgithub.com%2FmaniSbindra%2Fapi-test-harness-webv%2Fblob%2Fmaster%2FTestFiles%2FApiTests%2FData%2FBooksTestData.json%22%20target%3D%22_self%22%20rel%3D%22noopener%20noreferrer%22%3E%2FTestFiles%2FApiTests%2FData%2FBooksTestData.json%3C%2FA%3E%3A%20This%20file%20has%20the%20test%20mongodb%20data%20to%20be%20setup%20which%20the%20webvalidate%20tests%20will%20assert%20against.%20We%20will%20look%20at%20this%20file%20in%20more%20detail%20in%20the%20next%20section.%3C%2FLI%3E%0A%3CLI%3E%3CA%20href%3D%22https%3A%2F%2Fgithub.com%2FmaniSbindra%2Fapi-test-harness-webv%2Fblob%2Fmaster%2FTestFiles%2FApiTests%2FTestCases%2FBooksTestCases.json%22%20target%3D%22_self%22%20rel%3D%22noopener%20noreferrer%22%3E%2FTestFiles%2FApiTests%2FTestCases%2FBooksTestCases.json%3C%2FA%3E%3A%20This%20file%20contains%20the%20webvalidate%20test%20cases%20to%20validate%20that%20the%20API%20functionality%20is%20not%20broken.%20We%20will%20look%20at%20this%20file%20in%20more%20detail%20in%20the%20next%20section%3C%2FLI%3E%0A%3CLI%3E%3CA%20href%3D%22https%3A%2F%2Fgithub.com%2FmaniSbindra%2Fapi-test-harness-webv%2Fblob%2Fmaster%2FTestFiles%2Fscripts%2Fimport.sh%22%20target%3D%22_self%22%20rel%3D%22noopener%20noreferrer%22%3E%2FTestFiles%2Fscripts%2Fimport.sh%3C%2FA%3E%3A%20This%20script%20is%20used%20by%20the%20test%20harness%20to%20load%20the%20BooksTestData.json%20data%20into%20the%20mongodb%20collection%20used%20by%20the%20Books%20service%3C%2FLI%3E%0A%3CLI%3E%3CA%20href%3D%22https%3A%2F%2Fgithub.com%2FmaniSbindra%2Fapi-test-harness-webv%2Fblob%2Fmaster%2FTestFiles%2Fscripts%2FexecuteTests.sh%22%20target%3D%22_self%22%20rel%3D%22noopener%20noreferrer%22%3E%2FTestFiles%2Fscripts%2FexecuteTests.sh%3C%2FA%3E%3A%20This%20script%20is%20used%20by%20the%20test%20harness%20to%20execute%20webvalidate%20test%20cases%20against%20the%20Books%20API.%20The%20test%20results%20are%20output%20in%20the%20webvalidate%20json%20format%3C%2FLI%3E%0A%3CLI%3E%3CA%20href%3D%22https%3A%2F%2Fgithub.com%2FmaniSbindra%2Fapi-test-harness-webv%2Fblob%2Fmaster%2FTestFiles%2Fscripts%2FwebvtoJunit.py%22%20target%3D%22_self%22%20rel%3D%22noopener%20noreferrer%22%3E%2FTestFiles%2Fscripts%2FwebvtoJunit.py%3C%2FA%3E%3A%20This%20file%20is%20used%20to%20convert%20the%20webvalidate%20format%20test%20results%20into%20JUnit%20format%2C%20which%20can%20then%20be%20published%20to%20an%20Azure%20Pipelines%20Dashboard.%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3C%2FLI%3E%0A%3CLI%3E%3CSTRONG%3E%3CA%20href%3D%22https%3A%2F%2Fgithub.com%2FmaniSbindra%2Fapi-test-harness-webv%2Fblob%2Fmaster%2FApiTestsAzurePipelines.yaml%22%20target%3D%22_self%22%20rel%3D%22noopener%20noreferrer%22%3E%2FApiTestsAzurePipelines.yaml%3C%2FA%3E%3A%26nbsp%3B%3C%2FSTRONG%3EThis%20is%20the%20PR%20validation%20pipeline%20file.%20This%20pipeline%20is%20%3CSTRONG%3Econfigured%3C%2FSTRONG%3E%20as%20a%20%3CSTRONG%3Ebuild%20validation%20pipeline%3C%2FSTRONG%3E%20for%20the%20%3CSTRONG%3Emain%3C%2FSTRONG%3E%20branch%2C%20and%20is%20%3CSTRONG%3Etriggered%20for%20each%20PR%20targeting%20the%20main%20branch%3C%2FSTRONG%3E.%20This%20pipeline%20is%20responsible%20for%20tying%20everything%20together%2C%20i.e.%20Bring%20up%20the%20virtualized%20application%2C%20database%20and%20test%20harness%20components%20%2C%20setting%20up%20the%20test%20data%2C%20executing%20the%20tests%2C%20and%20finally%20validating%20and%20publishing%20the%20test%20results.%20If%20any%20of%20the%20tests%20fail%20the%20PR%20shows%20a%20build%20validation%20failure%2C%20and%20prevents%20the%20PR%20from%20getting%20merged%20into%20the%20main%20branch%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3CH2%20id%3D%22toc-hId-948649897%22%20id%3D%22toc-hId-948649897%22%3E%26nbsp%3B%3C%2FH2%3E%0A%3CH2%20id%3D%22toc-hId--858804566%22%20id%3D%22toc-hId--858804566%22%3E%3CSTRONG%3EDigging%20Deeper%20into%20the%20key%20files%3C%2FSTRONG%3E%3C%2FH2%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3EMongodb%20collection%20test%20data%3C%2FSTRONG%3E%20%3CSTRONG%3E%3CA%20href%3D%22https%3A%2F%2Fgithub.com%2FmaniSbindra%2Fapi-test-harness-webv%2Fblob%2Fmaster%2FTestFiles%2FApiTests%2FData%2FBooksTestData.json%22%20target%3D%22_self%22%20rel%3D%22noopener%20noreferrer%22%3E-%20%2FTestFiles%2FApiTests%2FData%2FBooksTestData.json%3C%2FA%3E%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%20class%3D%22lia-code-sample%20language-json%22%3E%3CCODE%3E%5B%0A%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20%22_id%22%3A%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%22%24oid%22%3A%20%2260e2e8fe7ed72f0001bf3a41%22%0A%20%20%20%20%20%20%20%20%7D%2C%0A%20%20%20%20%20%20%20%20%22Name%22%3A%20%22The%20Go%20Programming%20Language%22%2C%0A%20%20%20%20%20%20%20%20%22Price%22%3A%2020%2C%0A%20%20%20%20%20%20%20%20%22Category%22%3A%20%22Computer%20Programming%22%2C%0A%20%20%20%20%20%20%20%20%22Author%22%3A%20%22Alan%20Donovan%22%0A%20%20%20%20%7D%2C%0A%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20%22_id%22%3A%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%22%24oid%22%3A%20%2260e2e8fe7ed72f0001bf3a46%22%0A%20%20%20%20%20%20%20%20%7D%2C%0A%20%20%20%20%20%20%20%20%22Name%22%3A%20%22Design%20Patterns%22%2C%0A%20%20%20%20%20%20%20%20%22Price%22%3A%2054.93%2C%0A%20%20%20%20%20%20%20%20%22Category%22%3A%20%22Computers%22%2C%0A%20%20%20%20%20%20%20%20%22Author%22%3A%20%22Ralph%20Johnson%22%0A%20%20%20%20%7D%0A%5D%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CUL%3E%0A%3CLI%3EThis%20file%20contains%20the%20mongodb%20test%20data%20documents%20against%20which%20we%20will%20execute%20the%20webvalidate%20test%20cases.%20As%20we%20can%20see%20the%20format%20of%20_id%20column%20is%20in%20the%20mongodb%20compliant%20format%3C%2FLI%3E%0A%3CLI%3EThere%20are%202%20test%20data%20documents%20which%20will%20be%20added%20in%20this%20case%20one%20for%20the%20book%20%22The%20Go%20Programming%20Language%22%20and%20the%20other%20for%20the%20book%20%22Design%20Patterns%22%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3EWebvalidate%20Test%20Cases%20-%20%3CA%20href%3D%22https%3A%2F%2Fgithub.com%2FmaniSbindra%2Fapi-test-harness-webv%2Fblob%2Fmaster%2FTestFiles%2FApiTests%2FTestCases%2FBooksTestCases.json%22%20target%3D%22_self%22%20rel%3D%22noopener%20noreferrer%22%3E%2FTestFiles%2FApiTests%2FTestCases%2FBooksTestCases.json%3C%2FA%3E%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%20class%3D%22lia-code-sample%20language-json%22%3E%3CCODE%3E%7B%0A%20%20%20%20%22requests%22%3A%20%5B%0A%20%20%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20%22path%22%3A%20%22%2Fapi%2Fbooks%22%2C%0A%20%20%20%20%20%20%20%20%22verb%22%3A%20%22POST%22%2C%0A%20%20%20%20%20%20%20%20%22tag%22%3A%20%22CreateBookValidRequest%22%2C%0A%20%20%20%20%20%20%20%20%22failOnValidationError%22%3A%20true%2C%0A%20%20%20%20%20%20%20%20%22body%22%3A%20%22%7B%5C%22Name%5C%22%3A%5C%22Kubernetes%20Up%20and%20Running%5C%22%2C%5Cr%5Cn%5C%22Price%5C%22%3A25%2C%5Cr%5Cn%5C%22Category%5C%22%3A%5C%22Computer%20Programming%5C%22%2C%5Cr%5Cn%5C%22Author%5C%22%3A%5C%22Adam%20Barr%5C%22%5Cr%5Cn%7D%22%2C%0A%20%20%20%20%20%20%20%20%22contentMediaType%22%3A%20%22application%2Fjson-patch%2Bjson%22%2C%0A%20%20%20%20%20%20%20%20%22validation%22%3A%20%7B%0A%20%20%20%20%20%20%20%20%20%20%22statusCode%22%3A%20201%2C%0A%20%20%20%20%20%20%20%20%20%20%22contentType%22%3A%20%22application%2Fjson%22%2C%0A%20%20%20%20%20%20%20%20%20%20%22jsonObject%22%3A%20%5B%0A%20%20%20%20%20%20%20%20%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22field%22%3A%20%22Id%22%0A%20%20%20%20%20%20%20%20%20%20%20%20%7D%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22field%22%3A%20%22Name%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22value%22%3A%20%22Kubernetes%20Up%20and%20Running%22%0A%20%20%20%20%20%20%20%20%20%20%20%20%7D%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22field%22%3A%20%22Price%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22value%22%3A%2025%0A%20%20%20%20%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%20%20%20%20%20%20%5D%0A%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%20%20%7D%2C%0A%20%20%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20%22path%22%3A%20%22%2Fapi%2Fbooks%22%2C%0A%20%20%20%20%20%20%20%20%22verb%22%3A%20%22POST%22%2C%0A%20%20%20%20%20%20%20%20%22tag%22%3A%20%22CreateBookInvalidPrice%22%2C%0A%20%20%20%20%20%20%20%20%22failOnValidationError%22%3A%20true%2C%0A%20%20%20%20%20%20%20%20%22body%22%3A%20%22%7B%5C%22Name%5C%22%3A%5C%22Kubernetes%20Up%20and%20Running%5C%22%2C%5Cr%5Cn%5C%22Price%5C%22%3A%5C%22twenty%20five%5C%22%2C%5Cr%5Cn%5C%22Category%5C%22%3A%5C%22Computer%20Programming%5C%22%2C%5Cr%5Cn%5C%22Author%5C%22%3A%5C%22Adam%20Barr%5C%22%5Cr%5Cn%7D%22%2C%0A%20%20%20%20%20%20%20%20%22contentMediaType%22%3A%20%22application%2Fjson-patch%2Bjson%22%2C%0A%20%20%20%20%20%20%20%20%22validation%22%3A%20%7B%0A%20%20%20%20%20%20%20%20%20%20%22statusCode%22%3A%20400%2C%0A%20%20%20%20%20%20%20%20%20%20%22contentType%22%3A%20%22application%2Fproblem%2Bjson%3B%22%2C%0A%20%20%20%20%20%20%20%20%20%20%22jsonObject%22%3A%20%5B%0A%20%20%20%20%20%20%20%20%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22field%22%3A%20%22errors%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22validation%22%3A%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22jsonObject%22%3A%20%5B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%7B%20%22field%22%3A%20%22Price%22%20%7D%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%5D%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%20%20%20%20%20%20%5D%0A%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%20%20%7D%2C%0A%20%20%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20%22path%22%3A%20%22%2Fapi%2Fbooks%2F60e304aac7b8d60001b2d3cd%22%2C%0A%20%20%20%20%20%20%20%20%22verb%22%3A%20%22Get%22%2C%0A%20%20%20%20%20%20%20%20%22tag%22%3A%20%22GetNonExistentBook%22%2C%0A%20%20%20%20%20%20%20%20%22failOnValidationError%22%3A%20true%2C%0A%20%20%20%20%20%20%20%20%22validation%22%3A%20%7B%0A%20%20%20%20%20%20%20%20%20%20%22statusCode%22%3A%20404%2C%0A%20%20%20%20%20%20%20%20%20%20%22contentType%22%3A%20%22application%2Fproblem%2Bjson%3B%22%0A%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%20%20%7D%2C%0A%20%20%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20%22path%22%3A%20%22%2Fapi%2Fbooks%2F60e2e8fe7ed72f0001bf3a41%22%2C%0A%20%20%20%20%20%20%20%20%22verb%22%3A%20%22Get%22%2C%0A%20%20%20%20%20%20%20%20%22tag%22%3A%20%22GetExistingBook%22%2C%0A%20%20%20%20%20%20%20%20%22failOnValidationError%22%3A%20true%2C%0A%20%20%20%20%20%20%20%20%22validation%22%3A%20%7B%0A%20%20%20%20%20%20%20%20%20%20%22statusCode%22%3A%20200%2C%0A%20%20%20%20%20%20%20%20%20%20%22contentType%22%3A%20%22application%2Fjson%22%2C%0A%20%20%20%20%20%20%20%20%20%20%22exactMatch%22%3A%20%22%7B%5C%22Id%5C%22%3A%5C%2260e2e8fe7ed72f0001bf3a41%5C%22%2C%5C%22Name%5C%22%3A%5C%22The%20Go%20Programming%20Language%5C%22%2C%5C%22Price%5C%22%3A20.0%2C%5C%22Category%5C%22%3A%5C%22Computer%20Programming%5C%22%2C%5C%22Author%5C%22%3A%5C%22Alan%20Donovan%5C%22%7D%22%0A%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%20%20%7D%0A%20%20%20%20%20%20%0A%20%20%20%20%5D%0A%20%20%7D%0A%20%20%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CUL%3E%0A%3CLI%3EThis%20file%20contains%204%20webvalidate%20format%20test%20cases%20which%20will%20be%20executed%20against%20the%20Books%20service%20and%20responses%20validated%3C%2FLI%3E%0A%3CLI%3EThe%20first%20test%20case%20with%20tag%26nbsp%3B%3CSTRONG%3ECreateBookValidRequest%26nbsp%3B%3C%2FSTRONG%3Edoes%20a%20post%20against%20the%20API%2C%20the%20stringified%20json%20%3CSTRONG%3Ebody%20%3C%2FSTRONG%3Eelement%26nbsp%3Bof%20this%20test%20case%20has%20the%20details%20of%20the%20book%20we%20are%20trying%20to%20create.%20Since%20the%20request%20is%20valid%2C%20the%20%3CSTRONG%3Evalidation%26nbsp%3B%3C%2FSTRONG%3Eelement%20of%20this%20test%20case%20contains%20the%20validations%20which%20are%20applied%20to%20the%20response%2C%20mainly%20%3A%3CUL%3E%0A%3CLI%3EHTTP%20response%20status%20code%20is%20%3CSTRONG%3E201%3C%2FSTRONG%3E%3C%2FLI%3E%0A%3CLI%3EThe%20response%20has%20an%20%3CSTRONG%3EId%3C%2FSTRONG%3E%20element%20corresponding%20to%20the%20unique%20id%20of%20the%20created%20book%3C%2FLI%3E%0A%3CLI%3EThe%20field%26nbsp%3B%3CSTRONG%3EName%26nbsp%3B%3C%2FSTRONG%3Ein%20the%20response%20has%20value%20%3CSTRONG%3EKubernetes%20Up%20and%20Running%3C%2FSTRONG%3E%3C%2FLI%3E%0A%3CLI%3Eand%20the%20field%20%3CSTRONG%3EPrice%26nbsp%3B%3C%2FSTRONG%3Ein%20the%20response%20has%20value%20%3CSTRONG%3E25%3C%2FSTRONG%3E%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3C%2FLI%3E%0A%3CLI%3EThe%20second%20test%20case%20with%20tag%26nbsp%3B%3CSTRONG%3ECreateBookInvalidPrice%26nbsp%3B%3C%2FSTRONG%3Etries%20to%20create%20a%20book%20with%20invalid%20price%20(which%20is%20a%20string)%20in%20the%20%3CSTRONG%3Ebody%20.%26nbsp%3B%3C%2FSTRONG%3EThis%20test%20case%20then%20validates%20that%20the%20http%20response%20status%20code%20is%20%3CSTRONG%3E400.%26nbsp%3B%3C%2FSTRONG%3EIt%20also%20validates%20that%20the%20HTTP%20response%20indicates%20that%20error%20is%20due%20to%20the%20%3CSTRONG%3Efield%3C%2FSTRONG%3E%20%3CSTRONG%3EPrice.%3C%2FSTRONG%3E%3C%2FLI%3E%0A%3CLI%3EThe%20third%20test%20case%20with%20tag%20%3CSTRONG%3EGetNonExistentBook%26nbsp%3B%3C%2FSTRONG%3Etries%20to%20do%20%3CSTRONG%3EGET%3C%2FSTRONG%3E%20a%20book%20with%20id%26nbsp%3B60e304aac7b8d60001b2d3cd%2C%20which%20we%20did%20not%20add%20as%20a%20part%20of%20our%20test%20data.%20The%20test%20case%20then%20validates%20that%20the%20received%20status%20code%20is%20%3CSTRONG%3E404%3C%2FSTRONG%3E%3C%2FLI%3E%0A%3CLI%3EOur%20fourth%20and%20final%20test%20case%20with%20tag%26nbsp%3B%3CSTRONG%3EGetExistingBook%26nbsp%3B%3C%2FSTRONG%3Etries%20to%20%3CSTRONG%3EGET%3C%2FSTRONG%3E%20a%20book%20with%20id%26nbsp%3B%3CSTRONG%3E60e2e8fe7ed72f0001bf3a41%3C%2FSTRONG%3E.%20Since%20we%20added%20the%20test%20data%20for%20the%20book%20with%20this%20id%20(in%3CSTRONG%3E%3CA%20href%3D%22https%3A%2F%2Fgithub.com%2FmaniSbindra%2Fapi-test-harness-webv%2Fblob%2Fmaster%2FTestFiles%2FApiTests%2FData%2FBooksTestData.json%22%20target%3D%22_self%22%20rel%3D%22noopener%20noreferrer%22%3E%2FTestFiles%2FApiTests%2FData%2FBooksTestData.json%3C%2FA%3E%3C%2FSTRONG%3E)%20this%20book%20should%20exist.%20The%20test%20case%20then%20validates%20response%20status%20code%20is%20%3CSTRONG%3E200%2C%26nbsp%3B%3C%2FSTRONG%3Ethe%20test%20case%20also%20validates%20the%20%3CSTRONG%3Eexact%20match%26nbsp%3B%3C%2FSTRONG%3Eagainst%20the%20expected%20response%20body.%20Since%20the%20response%20is%20based%20on%20the%20test%20data%20we%20created%2C%20we%20can%20assert%20using%20exact%20match%20feature%20of%20webvalidate.%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3EPR%20Validation%20Azure%20Pipeline%20Yaml%20file%26nbsp%3B%3C%2FSTRONG%3E%3CSTRONG%3E%3CA%20href%3D%22https%3A%2F%2Fgithub.com%2FmaniSbindra%2Fapi-test-harness-webv%2Fblob%2Fmaster%2FApiTestsAzurePipelines.yaml%22%20target%3D%22_self%22%20rel%3D%22noopener%20noreferrer%22%3E-%20%2FApiTestsAzurePipelines.yaml%3C%2FA%3E%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%20class%3D%22lia-code-sample%20language-yaml%22%3E%3CCODE%3E.%0A.%0Asteps%3A%0A%0A-%20script%3A%20%7C%0A%20%20%20%20%20%20cd%20%24(System.DefaultWorkingDirectory)%0A%20%20%20%20%20%20docker-compose%20-f%20BooksApi%2FdockerComposeBooksApiTest.yml%20build%20--no-cache%20%20--build-arg%20ENVIRONMENT%3Dlocal%20%20%20%20%20%0A%20%20%20%20%20%20docker-compose%20-f%20BooksApi%2FdockerComposeBooksApiTest.yml%20up%20--exit-code-from%20webv%20%7C%20tee%20%24(System.DefaultWorkingDirectory)%2Fdc.log%0A%20%20displayName%3A%20%22Execute%20API%20Tests%22%0A%0A-%20script%3A%20%7C%0A%20%20%20%20%20%20%23%20Pass%20parameters%3A%20path%20to%20docker-compose%20log%20file%2C%20path%20to%20output%20Junit%20file%2C%20and%20path%20to%20scripts%20directory%0A%20%20%20%20%20%20bash%20%24(System.DefaultWorkingDirectory)%2FTestFiles%2Fscripts%2FwebvToJunit.sh%20%24(System.DefaultWorkingDirectory)%2Fdc.log%20%24(System.DefaultWorkingDirectory)%2Fjunit.xml%20%24(System.DefaultWorkingDirectory)%2FTestFiles%2Fscripts%0A%20%20displayName%3A%20%22Convert%20Test%20Execution%20Log%20output%20to%20JUnit%20Format%22%0A%0A-%20task%3A%20PublishTestResults%402%0A%20%20displayName%3A%20'Validate%20and%20Publish%20Component%20Test%20Results'%0A%20%20inputs%3A%0A%20%20%20%20testResultsFormat%3A%20JUnit%0A%20%20%20%20testResultsFiles%3A%20'junit.xml'%0A%20%20%20%20searchFolder%3A%20%24(System.DefaultWorkingDirectory)%0A%20%20%20%20testRunTitle%3A%20'webapitestrestults'%0A%20%20%20%20failTaskOnFailedTests%3A%20true%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EThere%20are%203%20main%20steps%20in%20this%20PR%20validation%20Azure%20Pipeline%20file%3A%3C%2FP%3E%0A%3CUL%3E%0A%3CLI%3EWe%20build%20the%3CA%20href%3D%22https%3A%2F%2Fgithub.com%2FmaniSbindra%2Fapi-test-harness-webv%2Fblob%2Fmaster%2FBooksApi%2FdockerComposeBooksApiTest.yml%22%20target%3D%22_self%22%20rel%3D%22noopener%20noreferrer%22%3E%2FBooksApi%2FdockerComposeBooksApiTest.yml%3C%2FA%3E%26nbsp%3Bdocker-compose%20file%2C%20which%20builds%20the%20microservice%20code.%20Next%20we%20execute%20the%20%3CSTRONG%3Edocker-compose%20up%3C%2FSTRONG%3E%20with%20the%20docker%20compose%20file.%20This%20command%20brings%20up%20the%20%3CSTRONG%3Emicroservice%3C%2FSTRONG%3E%2C%20%3CSTRONG%3Emongodb%3C%2FSTRONG%3E%20database%20container%2C%20%3CSTRONG%3Emongodb%20import%3C%2FSTRONG%3E%20container%2C%20and%20%3CSTRONG%3Ewebvalidate%3C%2FSTRONG%3E%20container.%20This%20also%20configures%20the%20service%20to%20use%20a%20specific%20mongodb%20collection.%20Next%20the%20mongodb%20import%20container%20loads%20the%20test%20data%20into%20the%20mongodb%20collection%2C%20and%20finally%20the%20webvalidate%20container%20executes%20the%20tests%20and%20outputs%20the%20results.%26nbsp%3Band%20we%20all%20forwarded%20common%20logs%20to%20a%20file%2C%20which%20can%20then%20be%20parsed%20to%20extract%20the%20webvalidate%20test%20results%20in%20the%20following%20step.%20One%20point%20to%20note%20here%20is%20that%20in%20the%20current%20configuration%20the%20build%20argument%20%3CSTRONG%3E%22ENVIRONMENT%3Dlocal%22%3C%2FSTRONG%3E%20is%20not%20adding%20any%20value%2C%20however%20for%20%3CSTRONG%3Emore%20complex%20application%20configurations%3C%2FSTRONG%3E%2C%20like%20for%20instance%2C%20where%20the%20application%20needs%20to%20fetch%20its%20configurations%20using%20say%20DefaultAzureCredentials%2C%20Azure%20App%20Config%20and%20Azure%20Key%20Vault%2C%20this%20environment%20variable%20can%20be%20used%20in%20the%20dockerfile%20to%20conditionally%20install%20things%20like%20%3CSTRONG%3Eaz%20cli%20%3C%2FSTRONG%3E(in%20which%20case%20in%20the%20docker-compose%20file%20we%20would%20mount%20the%20~%2F.azure%20directory%20to%20enable%20the%20DefaultAzureCredentials%20library%20to%20fetch%20the%20azure%20credentilas%20in%20this%20%3CSTRONG%3Elocal%20execution%20environment%2C%26nbsp%3B%3C%2FSTRONG%3Ewhich%20would%20then%20enable%20the%20application%20to%20connect%20to%20things%20like%20Azure%20app%20configuration).%26nbsp%3B%3C%2FLI%3E%0A%3CLI%3EIn%20the%20next%20step%20the%20docker%20compose%20file%20is%20parsed%20to%20fetch%20the%20webvalidate%20results%2C%20the%20results%20are%20then%20transformed%20in%20to%20the%20JUnit%20format%3C%2FLI%3E%0A%3CLI%3EFinally%20the%20webvalidate%20results%20are%20published%20to%20Azure%20Pipelines%20dashboard%3CSTRONG%3E.%20If%20there%20are%20any%20webvalidate%20test%20failures%2C%20the%20build%20validation%20fails%20and%20the%20PR%20modifcations%20cannot%20be%20merged%20in%20to%20the%20main%20branch%3C%2FSTRONG%3E%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3EDocker%20Compose%20API%20Test%20Harness%26nbsp%3B%3C%2FSTRONG%3E%3CSTRONG%3E%3CA%20href%3D%22https%3A%2F%2Fgithub.com%2FmaniSbindra%2Fapi-test-harness-webv%2Fblob%2Fmaster%2FBooksApi%2FdockerComposeBooksApiTest.yml%22%20target%3D%22_self%22%20rel%3D%22noopener%20noreferrer%22%3E-%20%2FBooksApi%2FdockerComposeBooksApiTest.yml%3C%2FA%3E%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%20class%3D%22lia-code-sample%20language-yaml%22%3E%3CCODE%3Eversion%3A%20'3'%0Aservices%3A%0A%20%20booksapi%3A%0A%20%20%20%20build%3A%0A%20%20%20%20%20%20context%3A%20.%0A%20%20%20%20%20%20dockerfile%3A%20.%2FDockerfile%0A%20%20%20%20ports%3A%0A%20%20%20%20%20%20-%20'5011%3A80'%0A%20%20%20%20networks%3A%0A%20%20%20%20%20%20-%20books%0A%20%20%20%20%23%20volumes%3A%0A%20%20%20%20%23%20%20%20-%20%24%7BHOME%7D%2F.azure%3A%2Froot%2F.azure%0A%20%20%20%20environment%3A%0A%20%20%20%20%20%20-%20BookstoreDatabaseSettings__ConnectionString%3Dmongodb%3A%2F%2Fmongo%3A27017%0A%20%20%20%20%20%20-%20BookstoreDatabaseSettings__DatabaseName%3DBookstoreDb%0A%20%20%20%20%20%20-%20BookstoreDatabaseSettings__BooksCollectionName%3DBooks%0A%20%20%20%20%0A%20%20mongo%3A%0A%20%20%20%20container_name%3A%20books.mongo%0A%20%20%20%20image%3A%20mongo%3A4.4%0A%20%20%20%20networks%3A%0A%20%20%20%20%20%20-%20books%0A%20%20%0A%20%20mongo-import%3A%0A%20%20%20%20image%3A%20mongo%3A4.4%0A%20%20%20%20depends_on%3A%0A%20%20%20%20-%20mongo%0A%20%20%20%20volumes%3A%0A%20%20%20%20-%20..%2FTestFiles%3A%2FtestFiles%2F%0A%20%20%20%20-%20..%2FTestFiles%2Fscripts%2Fimport.sh%3A%2Fcommand%2Fimport.sh%0A%20%20%20%20-%20..%2FTestFiles%2Fscripts%2Findex.js%3A%2Fcommand%2Findex.js%0A%20%20%20%20networks%3A%0A%20%20%20%20%20%20-%20books%0A%20%20%20%20environment%3A%0A%20%20%20%20-%20MONGO_URI%3Dmongodb%3A%2F%2Fmongo%3A27017%0A%20%20%20%20-%20MONGO_DB%3DBookstoreDb%0A%20%20%20%20-%20MONGO_COLL%3DBooks%0A%20%20%20%20-%20TEST_TYPE%3DApiTests%0A%20%20%20%20entrypoint%3A%20%2Fcommand%2Fimport.sh%0A%0A%20%20webv%3A%0A%20%20%20%20image%3A%20retaildevcrew%2Fwebvalidate%40sha256%3A183228cb62915e7ecac72fa0746fed4f7127a546428229291e6eeb202b2a5973%0A%20%20%20%20depends_on%3A%0A%20%20%20%20-%20mongo%0A%20%20%20%20-%20booksapi%0A%20%20%20%20volumes%3A%0A%20%20%20%20-%20..%2FTestFiles%3A%2FtestFiles%2F%0A%20%20%20%20-%20..%2FTestFiles%2Fscripts%2FexecuteTests.sh%3A%2Fcommand%2FexecuteTests.sh%0A%20%20%20%20networks%3A%0A%20%20%20%20%20%20-%20books%0A%20%20%20%20environment%3A%0A%20%20%20%20-%20TEST_TYPE%3DApiTests%0A%20%20%20%20-%20TEST_SVC_ENDPOINT%3Dhttp%3A%2F%2Fbooksapi%0A%20%20%20%20-%20TEST_DATA_LOAD_DELAY%3D25%0A%20%20%20%20entrypoint%3A%20%5B%22%2Fbin%2Fsh%22%2C%22%2Fcommand%2FexecuteTests.sh%22%5D%0A%0Anetworks%3A%0A%20%20books%3A%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CUL%3E%0A%3CLI%3EThe%20booksapi%20docker-compose%20service%20brings%20up%20the%20microservice.%20Mongo%20db%20configurations%20are%20passed%20in%20as%20environment%20settings%3C%2FLI%3E%0A%3CLI%3Emongo%26nbsp%3Bdocker-compose%20service%20brings%20up%20the%20mongodb%20db%20container.%3C%2FLI%3E%0A%3CLI%3Emongo-import%26nbsp%3Bdocker-compose%20service%20brings%20up%20the%20mongo%20db%20container%20which%20is%20used%20to%20load%20the%20test%20data%20from%26nbsp%3B%3CA%20href%3D%22https%3A%2F%2Fgithub.com%2FmaniSbindra%2Fapi-test-harness-webv%2Fblob%2Fmaster%2FTestFiles%2FApiTests%2FData%2FBooksTestData.json%22%20target%3D%22_self%22%20rel%3D%22noopener%20noreferrer%22%3E%2FTestFiles%2FApiTests%2FData%2FBooksTestData.json%3C%2FA%3E%26nbsp%3Bfile%20into%20the%20configured%20mongo%20db%20(mongo%20docker-compose%20service)%20collection.%20The%20startup%20script%20used%20by%20this%20container%20is%26nbsp%3B%3CA%20href%3D%22https%3A%2F%2Fgithub.com%2FmaniSbindra%2Fapi-test-harness-webv%2Fblob%2Fmaster%2FTestFiles%2Fscripts%2Fimport.sh%22%20target%3D%22_self%22%20rel%3D%22noopener%20noreferrer%22%3E%2FTestFiles%2Fscripts%2Fimport.sh%3C%2FA%3E%3C%2FLI%3E%0A%3CLI%3EFinally%20the%20webvalidate%20docker-compose%20service%20brings%20up%20the%20webvalidate%20container.%20This%20container%20waits%20for%20configured%20delay%20before%20executing%20the%20webvalidate%20tests%20defined%20in%26nbsp%3B%3CA%20href%3D%22https%3A%2F%2Fgithub.com%2FmaniSbindra%2Fapi-test-harness-webv%2Fblob%2Fmaster%2FTestFiles%2FApiTests%2FTestCases%2FBooksTestCases.json%22%20target%3D%22_self%22%20rel%3D%22noopener%20noreferrer%22%3E%2FTestFiles%2FApiTests%2FTestCases%2FBooksTestCases.json%3C%2FA%3E%26nbsp%3Bagainst%20the%20booksapi%20service.%20The%20startup%20script%20used%20by%20this%20container%20is%26nbsp%3B%3CA%20href%3D%22https%3A%2F%2Fgithub.com%2FmaniSbindra%2Fapi-test-harness-webv%2Fblob%2Fmaster%2FTestFiles%2Fscripts%2FexecuteTests.sh%22%20target%3D%22_self%22%20rel%3D%22noopener%20noreferrer%22%3E%2FTestFiles%2Fscripts%2FexecuteTests.sh%3C%2FA%3E%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3CH2%20id%3D%22toc-hId-1628708267%22%20id%3D%22toc-hId-1628708267%22%3E%26nbsp%3B%3C%2FH2%3E%0A%3CH2%20id%3D%22toc-hId--178746196%22%20id%3D%22toc-hId--178746196%22%3E%3CSTRONG%3EThe%20Test%20harness%20in%20action%3C%2FSTRONG%3E%3C%2FH2%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CH4%20id%3D%22toc-hId--1285136081%22%20id%3D%22toc-hId--1285136081%22%3E%3CSTRONG%3EAbstract%20from%20execution%20stage%20log%3C%2FSTRONG%3E%3C%2FH4%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%20class%3D%22lia-code-sample%20language-bash%22%3E%3CCODE%3E.%0ASuccessfully%20built%20b312635a0c59%0ASuccessfully%20tagged%20booksapi_booksapi%3Alatest%0A.%0A.%0ACreating%20books.mongo%20...%20%0ACreating%20booksapi_booksapi_1%20...%20%0ACreating%20books.mongo%20%20%20%20%20%20%20%20%20...%20done%0ACreating%20booksapi_mongo-import_1%20...%20%0ACreating%20booksapi_booksapi_1%20%20%20%20%20...%20done%0ACreating%20booksapi_webv_1%20%20%20%20%20%20%20%20%20...%20%0ACreating%20booksapi_mongo-import_1%20...%20done%0ACreating%20booksapi_webv_1%20%20%20%20%20%20%20%20%20...%20done%0AAttaching%20to%20books.mongo%2C%20booksapi_booksapi_1%2C%20booksapi_mongo-import_1%2C%20booksapi_webv_1%0A.%0A.%0Amongo-import_1%20%20%7C%202021-07-12T07%3A23%3A29.882%2B0000%202%20document(s)%20imported%20successfully.%200%20document(s)%20failed%20to%20import.%0A.%0A.%0Awebv_1%20%20%20%20%20%20%20%20%20%20%7C%20%7B%22date%22%3A%222021-07-12T07%3A23%3A55.3355122Z%22%2C%22verb%22%3A%22POST%22%2C%22server%22%3A%22http%3A%2F%2Fbooksapi%22%2C%22statusCode%22%3A201%2C%22failed%22%3Afalse%2C%22validated%22%3Atrue%2C%22correlationVector%22%3A%22MtKp%5Cu002BU7CpE6VAJLRF%2FkGlQ.0%22%2C%22errorCount%22%3A0%2C%22duration%22%3A550%2C%22contentLength%22%3A136%2C%22category%22%3A%22%22%2C%22tag%22%3A%22CreateBookValidRequest%22%2C%22path%22%3A%22%2Fapi%2Fbooks%22%2C%22errors%22%3A%5B%5D%7D%0A.%0A.%0AStopping%20booksapi_mongo-import_1%20...%20%0AStopping%20booksapi_booksapi_1%20%20%20%20%20...%20%0AStopping%20books.mongo%20%20%20%20%20%20%20%20%20%20%20%20%20...%20%0AStopping%20booksapi_booksapi_1%20%20%20%20%20...%20done%0AStopping%20booksapi_mongo-import_1%20...%20done%0AStopping%20books.mongo%20%20%20%20%20%20%20%20%20%20%20%20%20...%20done%0AAborting%20on%20container%20exit...%0A%0A%0A%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CUL%3E%0A%3CLI%3EFirst%20the%20containers%20are%20started%20(mongo%2C%20booksapi%2C%20mongo-import%20and%20webv)%3C%2FLI%3E%0A%3CLI%3EAfter%20that%20the%20mongo-import%20container%20add%20the%20%3CSTRONG%3E2%20test%20documents%3C%2FSTRONG%3E%20into%20the%20booksapi%20mongodb%20collection%3C%2FLI%3E%0A%3CLI%3EAfter%20which%20there%20is%20an%20entry%20for%20each%20webvalidate%20test%20case%20in%20json%20format%2C%20which%20has%20all%20details%20of%20the%20execution%3C%2FLI%3E%0A%3CLI%3EAfter%20webvalidate%20testcase%20execution%20is%20complete%2C%20the%20webv%20container%20exists%2C%20causing%20docker-compose%20to%20terminate%20all%20other%20containers%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CH4%20id%3D%22toc-hId-1202376752%22%20id%3D%22toc-hId-1202376752%22%3E%3CSTRONG%3EFailure%20Scenario%3C%2FSTRONG%3E%3C%2FH4%3E%0A%3CP%3EBefore%20testing%20the%20harness%2C%20we%20need%20to%20create%20an%20Azure%20Pipeline%20using%20out%20PR%20Validation%20Pipeline%20yaml%20file%2C%20and%20then%20configure%20this%20pipeline%20to%20execute%20as%20part%20of%20main%20branch%20%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fazure%2Fdevops%2Frepos%2Fgit%2Fbranch-policies%3Fview%3Dazure-devops%23build-validation%22%20target%3D%22_self%22%20rel%3D%22noopener%20noreferrer%22%3Ebuild%20validation%3C%2FA%3E.%20For%20simplicity%20to%20cause%20the%20API%20test%20to%20fail%20let%20us%20modify%20the%26nbsp%3B%3CSTRONG%3ECreateBookValidRequest%3C%2FSTRONG%3E%26nbsp%3Bwebvalidate%20test%20case%20to%20%3CSTRONG%3Eexpect%20a%20Price%20of%2026%20in%20the%20response%20instead%20of%2025%3C%2FSTRONG%3E%2C%20as%20shown%20in%20the%20%3CA%20href%3D%22https%3A%2F%2Fgithub.com%2FmaniSbindra%2Fapi-test-harness-webv%2Fcommit%2F44da50a759ba84e6cf63e0d8400f220ab98077dd%22%20target%3D%22_self%22%20rel%3D%22noopener%20noreferrer%22%3Ecommit%3C%2FA%3E%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22manisbindra_0-1625834392977.png%22%20style%3D%22width%3A%20400px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F294606i9E6E4A4FC3ACF1F5%2Fimage-size%2Fmedium%3Fv%3Dv2%26amp%3Bpx%3D400%22%20role%3D%22button%22%20title%3D%22manisbindra_0-1625834392977.png%22%20alt%3D%22manisbindra_0-1625834392977.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3EOnce%20a%20Pull%20request%20is%20created%3C%2FSTRONG%3E%2C%20we%20should%20see%20the%20%3CSTRONG%3EPR%20validation%20build%20kicking%20in%3C%2FSTRONG%3E%2C%20and%20%3CSTRONG%3Ethen%20failing%3C%2FSTRONG%3E%20in%20a%20couple%20of%20minutes%20as%20shown%3A%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22PR-created-1.jpg%22%20style%3D%22width%3A%20400px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F294936i62591DDD0480CDA3%2Fimage-size%2Fmedium%3Fv%3Dv2%26amp%3Bpx%3D400%22%20role%3D%22button%22%20title%3D%22PR-created-1.jpg%22%20alt%3D%22PR-created-1.jpg%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3ENext%20we%20drill%20down%20into%20the%20pipeline%20and%20choose%20the%20%3CSTRONG%3ETests%3C%2FSTRONG%3E%20tab%2C%20which%20gives%20us%20an%20%3CSTRONG%3Eoverview%20of%20the%20test%20execution%3C%2FSTRONG%3E.%20Where%20we%20see%20that%201%20of%20the%204%20tests%20has%20failed%3A%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22test-failure-overview.jpg%22%20style%3D%22width%3A%20999px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F294937iC2FA0F849B76FD4B%2Fimage-size%2Flarge%3Fv%3Dv2%26amp%3Bpx%3D999%22%20role%3D%22button%22%20title%3D%22test-failure-overview.jpg%22%20alt%3D%22test-failure-overview.jpg%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EOn%20clicking%20the%20failed%20test%2C%20the%20%3CSTRONG%3Eerror%20details%20window%3C%2FSTRONG%3E%20shows%20us%20the%20reason%20of%20the%20error%20(Actual%20Price%20%2225%22%2C%20Expected%20Price%20%2226%22)%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22manisbindra_1-1625835368580.png%22%20style%3D%22width%3A%20999px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F294611i7B30CB96D6C2F63F%2Fimage-size%2Flarge%3Fv%3Dv2%26amp%3Bpx%3D999%22%20role%3D%22button%22%20title%3D%22manisbindra_1-1625835368580.png%22%20alt%3D%22manisbindra_1-1625835368580.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3ESince%20this%20is%20a%20required%20check%20for%20the%20PR%2C%20%3CSTRONG%3Emerging%20of%20the%20PR%20is%20blocked%3C%2FSTRONG%3E%3A%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22manisbindra_0-1626073514846.png%22%20style%3D%22width%3A%20999px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F294939iD149A9FFF0FDD1B7%2Fimage-size%2Flarge%3Fv%3Dv2%26amp%3Bpx%3D999%22%20role%3D%22button%22%20title%3D%22manisbindra_0-1626073514846.png%22%20alt%3D%22manisbindra_0-1626073514846.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CH4%20id%3D%22toc-hId-625792888%22%20id%3D%22toc-hId-625792888%22%3E%3CSTRONG%3ESuccess%20Scenario%3C%2FSTRONG%3E%3C%2FH4%3E%0A%3CP%3EAs%20we%20can%20see%20below%20if%20the%20PR%20validation%20is%20successful%2C%20the%20changes%20can%20be%20approved%20and%20merged%3A%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22manisbindra_0-1626075477709.png%22%20style%3D%22width%3A%20999px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F294972iAF23064E407750A5%2Fimage-size%2Flarge%3Fv%3Dv2%26amp%3Bpx%3D999%22%20role%3D%22button%22%20title%3D%22manisbindra_0-1626075477709.png%22%20alt%3D%22manisbindra_0-1626075477709.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CH2%20id%3D%22toc-hId--1439827013%22%20id%3D%22toc-hId--1439827013%22%3E%3CSTRONG%3ELimitations%20of%20this%20Approach%20and%20Other%20Considerations%3C%2FSTRONG%3E%3C%2FH2%3E%0A%3CP%3EThere%20are%20a%20few%20limitations%20of%20this%20simplistic%20API%20testing%20during%20PR%20validation%20approach%3A%3C%2FP%3E%0A%3CUL%3E%0A%3CLI%3EHere%20since%20the%20Microservice%20has%20a%20single%20main%20dependency%20(mongodb)%20which%20can%20be%20containerized%2C%20as%20a%20result%20it%20was%20possible%20to%20use%20docker-compose%20to%20containerize%204%20containers%20(booksapi%2C%20mongodb%2C%20mongo-import%20and%20webvalidate)%20on%20a%20single%20Azure%20Pipelines%20hosted%20agent.%20For%20more%20complex%20scenarios%20where%20the%20microservice%20depends%20on%20multiple%20other%20microservices%20each%20with%20their%20own%20dependencies%2C%20then%20this%20approach%20will%20not%20work.%20For%20such%20deployments%20other%20options%20like%20%3CA%20href%3D%22https%3A%2F%2Fgithub.com%2Fmicrosoft%2Fmindaro%22%20target%3D%22_self%22%20rel%3D%22noopener%20noreferrer%22%3EBridge%20to%20Kubernetes%3C%2FA%3E%20may%20be%20evaluated.%3C%2FLI%3E%0A%3CLI%3EIn%20case%20the%20microservice%20has%20dependency%20on%20a%20single%20database%20which%20cannot%20be%20containerized%2C%20like%20a%20cloud%20based%20service%2C%20then%20the%20test%20harness%20will%20need%20to%20be%20modified%20to%20initialize%20the%20cloud%20database%20each%20time%20the%20PR%20validation%20pipeline%20executes%2C%20and%20taking%20care%20that%20parallel%20executions%20do%20not%20interfere%20with%20each%20other%20(perhaps%20creating%20unique%20test%20collection%20for%20each%20execution%2C%20which%20is%20then%20torn%20down%20after%20test%20execution)%3C%2FLI%3E%0A%3CLI%3EIn%20this%20case%20docker-compose%20was%20selected%20as%20the%20pipeline%20orchestrator%20as%20the%20inner%20loop%20development%20process%20on%20the%20developer%20machines%20was%20using%20docker-compose.%20Kind%20Cluster%20can%20also%20be%20used%20on%20the%20Azure%20Pipelines%20hosted%20agent.%3C%2FLI%3E%0A%3CLI%3EWe%20need%20to%20bear%20mind%20that%20in%20this%20approach%20we%20are%20using%20a%20virtualized%20database%20(mongodb)%2C%20and%20some%20features%20are%20different%20on%20the%20virtualized%20database%20as%20compared%20to%20corresponding%20cloud%20based%20services%20(like%20Mongodb%20Atlas)%2C%20so%20it%20is%20possible%20that%20some%20tests%20which%20are%20passing%20in%20our%20PR%20validation%20pipeline%20(on%20Azure%20Pipelines%20hosted%20agent)%2C%20might%20fail%20in%20proper%20integration%20testing%20environment%20where%20the%20microservice%20is%20connected%20to%20the%20actual%20service%20(Like%20Mongodb%20Atlas).%26nbsp%3B%3C%2FLI%3E%0A%3CLI%3EA%20%3CA%20href%3D%22https%3A%2F%2Fgithub.com%2Fmicrosoft%2Fwebvalidate%2Fissues%2F20%22%20target%3D%22_self%22%20rel%3D%22noopener%20noreferrer%22%3Efeature%20request%3C%2FA%3E%20has%20been%20made%20in%20the%20webvalidate%20github%20repo%20to%20include%20option%20for%20directly%20exporting%20results%20to%20Junit%20format.%20Once%20this%20feature%20is%20available%20in%20the%20next%20release%20of%20webvalidate%2C%20we%20will%20not%20need%20to%20have%20a%20step%20in%20the%20pipeline%20which%20transforms%20the%20test%20results%20in%20the%20Junit%20format.%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EThanks%20for%20reading%20this%20post.%20I%20hope%20you%20liked%20it.%20Please%20feel%20free%20to%20write%20your%20comments%20and%20views%20about%20the%20same%20over%20here%20or%20at%20%3CA%20class%3D%22cf%20md%22%20href%3D%22https%3A%2F%2Ftwitter.com%2FmaniSbindra%22%20target%3D%22_blank%22%20rel%3D%22noopener%20nofollow%20noreferrer%22%3E%40manisbindra%3C%2FA%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-TEASER%20id%3D%22lingo-teaser-2526554%22%20slang%3D%22en-US%22%3E%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22API-build-validationv0.3.jpg%22%20style%3D%22width%3A%20999px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F294211i1385AD7905ECE11D%2Fimage-size%2Flarge%3Fv%3Dv2%26amp%3Bpx%3D999%22%20role%3D%22button%22%20title%3D%22API-build-validationv0.3.jpg%22%20alt%3D%22API-build-validationv0.3.jpg%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%20style%3D%22margin%3A%200in%3B%20font-family%3A%20Calibri%3B%20font-size%3A%2011.0pt%3B%22%3ETypical%20Pull%20Request%20(PR)%20validation%20checks%20validate%20things%20like%20linting%2C%20unit%20tests%20and%20code%20coverage%2C%20however%20%3CSTRONG%3Efor%20REST%20based%20microservices%20these%20do%20not%20ensure%20that%20the%20merged%20changes%20will%20not%20break%20the%20integrated%20APIs%3C%2FSTRONG%3E.%20In%20this%20post%20we%20look%20at%20a%20%3CSTRONG%3EWebvalidate%20based%20test%20harness%20%3C%2FSTRONG%3Ewhich%20in%20many%20cases%20would%3CSTRONG%3E%20enable%20us%20to%20validate%20that%20changes%20introduced%20in%20a%20PR%20do%20not%20break%20the%20Microservice%20API%3C%2FSTRONG%3E.%20These%20checks%20can%20be%20carried%20out%20as%20a%20%3CSTRONG%3Epart%20of%20the%20PR%20validation%3C%2FSTRONG%3E%26nbsp%3Bitself.%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-TEASER%3E%3CLINGO-LABS%20id%3D%22lingo-labs-2526554%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3E.%20NET%20Core%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EDevOps%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EWeb%20Apps%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E
Co-Authors
Version history
Last update:
‎Jul 14 2021 12:11 AM
Updated by: