1.1.9 • Published 7 years ago

rest-script-runner v1.1.9

Weekly downloads
2
License
MIT
Repository
github
Last release
7 years ago

Why do we need to use the engine?

  • Unify the way we would write and run our rest api integration tests.
  • Technology independent.
  • Easy to decoratively write our tests without redeploying any code changes.
  • None technical person can write a simple or complex test.
  • No duplication per technology.
  • The engine by default will run all the tests in parallel unless one test depending on the other implicitly or explicitly by set the waitFor with $id dependency.
  • Test anytime we would like to test with the same scripts that we integrate with the CI pipelines (GO, Jenkins and so on.)

The syntax requirement

  • Every command and script object must have a valid id and the id must start with '$id'
  • There are two addressing reference concepts which are the static and the dynamic but all references must start with the '$id' representing the address of object following by its property.
    For instance, '$id1.response.statusCode' and you can also access to an array item of the object like this '$id1.response.data.events0.eventId.
  • The url can be shareable and replaceable by having it at the script object level then replace each command's request url with $id0.url like the following script.
  • Every command must have a request object which must contain url, path, and method. The body is optional based on the method.
  • Expectancies is a list of the string which should have 3 parts. The left, comparison operator, and the right, for instance, $id1.response.statusCode == 200
  • The $id.response is the special property that you can access after the test runs and the response object will always contains 'statusCode' and 'data' property which you can use to write the expectancies as below script.

The report data will be report as the following structure.

  • The suite test level which will tell you the test suite was failed or passed with the reasons.
  • The command level which will tell you the status of the remotely service call, again failed or passed with the reasons.
  • The expectancy level which will tell you the status of the comparison.

For developers.

  • In es6 syntax:
    import engine from 'rest-script-runner';
    engine
    .verifyScriptSyntax()
    .runTests()
    .verifyExpectencies()
    .generateReport(req.body)
    .then((report:SuiteTestReport) => {
      res.json(report);
      next();
    })
    .catch((report:SuiteTestReport) => {
      res.json(report);
      next();
    });

For dockerized testing

  • We already build an docker image that you can run it in any kubernetes environment and the following is how you can run your test in the kubernetes cluster.

    kubectl --namespace=${TEST_NAMESPACE} --token=${KUBE_TOKEN} --server=${KUBE_SERVER} run -i ${POD_NAME} --image=${IMAGE_NAME} --restart=Never --limits=memory=1500Mi --rm

  • The variables need to be replaced with the following (if you have clusters or contexts defined in your kube config, you can use those instead via set-context or --cluster):

    TEST_NAMESPACE - the namespace you would like to use for running the tests. This can be your existing application namespace as long as you have sufficient resources available.
    KUBE_TOKEN - the token with access to the namespace.  If this is the same token defined in your kube config, you can omit it.
    KUBE_SERVER - the master server for the Kubernetes cluster you would like to target (i.e. https://kubeapi-aws-stage.acomcloud.int).
    POD_NAME - a unique name for the Pod that will be created.  The name only needs to be unique to the namespace and could be as simple as "tests".
    IMAGE_NAME - the full image name and tag for the Docker image you want to run.
    This command will execute your tests to completion, watch the output until the container finishes executing, and then delete it.

The following is an example of the json decorative script syntax for a test suite.

{
"id": "$id0",
"name": "PPS Integration Tests",
"description": "PPS test suite",
"url": "http://personprovider.awapi.mfsbestage.com",
"treeName":"Gunnell Family Tree",
"fullName":"Ruth Hawkins Gunnell",
"gender": 0,
"userId": "000709be-e004-0000-0000-000000000000",
"treeId":"648880",
"personId":"24004508805",
"commands": [{
  "id": "$id1",
  "name": "GetPersonStoryWithPersonCard",
  "description": "Verify the GetPersonStoryWithPersonCard function.",
  "request": {
    "url": "$id0.url",
    "path": "/v1/userid/$id0.userId/tree/$id0.treeId/person/$id0.personId/person/getpersonstory?mapHeight=200&mapWidth=1024&historicalEpisodeTypes=episode&useCassandraDB=False",
    "method": "GET"
  },
  "expectancies": [
    "$id1.response.data.hasTreeContributionRights == true",
    "$id1.response.data.hasTreeEditRights == true",
    "$id1.response.data.events.length > 0"
  ]
},{
  "waitFor": "$id1",
  "id": "$id2",
  "name": "GetPersonResearchWithPersonCard.",
  "description": "Verify the GetPersonResearchWithPersonCard function.",
  "request": {
    "url": "$id0.url",
    "path": "/v1/userid/$id0.userId/tree/$id0.treeId/person/$id0.personId/person/getpersonresearchwithpersoncard?mapHeight=200&mapWidth=1024",
    "method": "GET"
  },
  "expectancies": [
    "$id2.response.data.personCard.fullName == $id0.fullName",
    "$id2.response.data.personCard.treeName==$id0.treeName",
    "$id2.response.data.personCard.gender==$id0.gender"]
}]

}

How to integrate with the CI pipelines like GO and Jenkins.

  • curl command.

    	$ curl -v -H "Content-Type: application/json" POST --data "@path/script.json" http://kubernetes-hack.acomcloud.int:31016/runIntegration -H 'connection: close'
1.1.9

7 years ago

1.1.8

7 years ago

1.1.7

7 years ago

1.1.6

7 years ago

1.1.5

7 years ago

1.1.4

7 years ago

1.1.3

7 years ago

1.1.2

7 years ago

1.1.1

7 years ago

1.0.7

7 years ago

1.0.6

7 years ago

1.0.5

7 years ago

1.0.4

7 years ago

1.0.3

7 years ago

1.0.2

7 years ago

1.0.1

7 years ago

1.0.0

7 years ago