This site contains the documentation that is relevant to older WSO2 product versions and offerings.
For the latest WSO2 documentation, visit https://wso2.com/documentation/.

Adding test cases

Before you begin

This document assumes that you have completed the instructions in the following guides.

  1. Getting Started

  2. Deploying your first environment

Test cases are available in the chart source repository under a directory named “tests”. This step by step guide demonstrates how you can add test cases to your WSO2 API Microgateway pipeline

  1. Create a fork of the sample chart source repository.

  2. Create a clone of the forked chart source repository using the following command.

    $ git clone https://github.com/<ORGANIZATION_NAME>/cicd-sample-chart-mgw.git
    Replace the <ORGANIZATION_NAME> tag with the name of your GitHub organization.
  3. In the sample chart repository, observe the sample test script provided in cicd-sample-chart- mgw/tests and open test.sh

    This script in the test.sh file checks if the server has successfully started by performing health checks on Microgateway endpoints. If the desired response, of any of the provided endpoints, are not met, the script throws a non-zero exit code causing the test to fail.
  4. Uncomment the health check endpoints provided in the sample test script.

    declare -a healthcheckEndpoints=(
    
    "https://wso2micro-gw-service.wso2mgw-staging.svc.cluster.local:9095/petstore/v1/pet/findByStatus?status=available"
    
    #     "Endpoint 2"
    
    #     "Endpoint 3"
    
    )
  5. Change the chart repository in the sample values file used in the Getting Started Guide to use a custom chart.

    applications:
    
    - name: wso2mgw
    
      email: <EMAIL>
    
          testScript:
    
            path: tests
    
            command: test.sh
    
          chart:
    
            customChart: false
    
            name: microgateway
    
            version: 3.0.1-1
    
            repo: 'https://github.com/<ORGANIZATION_NAME>/cicd-sample-chart-mgw
  6. Upgrade the Helm chart with the command below, providing the modified sample values file.

    $ helm upgrade <RELEASE_NAME> wso2/kubernetes-pipeline -f values-mgw.yaml
    This may take up to 10 minutes.



  7. Restart the Jenkins pod by deleting the existing pod. This will cause the cluster to spawn a new pod for Jenkins.

    $ POD_NAME=`kubectl get pods --selector=app=jenkins -n <NAMESPACE> -o json -o jsonpath='{ .items[0].metadata.name }'`
    $ kubectl delete pod $POD_NAME -n <NAMESPACE>

    Replace <NAMESPACE> with the namespace in your cluster.


  8. Commit and push the changes in your forked chart source repository.

    $ git add .
    
    $ git commit -m “Add health check test cases”
    
    $ git push origin master

Testing the added Testcase:

  1. If there are any manual judgments pending on an existing environment halt it, and watch the deployment of the setup with test cases being deployed in the Spinnaker dashboard.

  2. Once the deployment has been made to the Dev environment, continue the manual judgment into Staging.

  3. If the tests are successful, you will be prompted to continue the deployment into production.

    If the staging deployment prompts for a manual judgement for deployment into production,

    your tests have successfully passed!