How to track a test run progress

After a test starts, you need to follow up and validate if the test passed or why it failed. This guide covers how you can use the Operous GraphQL API to fetch the test data of one or multiples servers.

Track the status of a single test

Using the server query, provide a filter to its attribute testRun that gives the server specific test

Query:

{
  server(input:{value: "ubiquitous-chicken-8974", kind:NAME}){
    name
    testRun (number:2){
      number
      status
      time
      tests{
          id
          passed
          text
      }
    }
  }
}

The query on curl request:

curl -X POST \
-H 'Authorization: Token <Account access token>' \
-H 'Content-Type: application/json' \
-d '{"query":"{  server(input:{value: \"ubiquitous-chicken-8974\", kind:NAME}){    name    testRun (number:2){      number      status      time      tests{          id          passed       text      }    }  }}"}' \
'https://app.operous.dev/graphql'

Response:

{
  "data": {
    "server": {
      "name": "ubiquitous-chicken-8974",
      "testRun": {
        "number": 2,
        "status": "FAILED",
        "time": "2021-07-06T12:17:23.213Z",
        "tests": [
          {
              "id": "SSHD/DisableRootLogin",
              "passed": false,
              "text": "The SSHD Configuration PermitRootLogin should be \"no\" but the current value is \"yes\"\n"
          },
          {
              "id": "SSHD/CloseUnauthenticated",
              "passed": false,
              "text": "The SSHD Configuration LoginGraceTime should be a number between 1 and 60 but it is not configured explictly and it's using the default value\n"
          }
        ]
      }
    }
  }
}

Keep tracking of multiples test runs

Using the same query, use the attribute testRuns that returns all server tests

Query:

{
  server(input:{value: "ancient-rock-700", kind:NAME}){
    name
    testRuns{
     number
     status
     time
     tests{
         id
         passed
         text
     }
    }
  }
}

The query on curl request:

curl -X POST \
-H 'Authorization: Token <Account access token>' \
-H 'Content-Type: application/json' \
-d '{"query":"{  server(input:{value: \"ancient-rock-700\", kind:NAME}){    name    testRuns{     number     status     time     tests{         id         passed         text     }    }  }}"}' \
'https://app.operous.dev/graphql'

Response:

{
  "data": {
    "server": {
      "name": "ubiquitous-chicken-8974",
      "testRuns": [
        {
          "number": 1,
          "status": "FAILED",
          "time": "2021-07-06T12:17:23.213Z",
          "tests": [
            {
              "id": "SSHD/DisableRootLogin",
              "passed": false,
              "text": "The SSHD Configuration PermitRootLogin should be \"no\" but the current value is \"yes\"\n"
            },
            {
              "id": "SSHD/CloseUnauthenticated",
              "passed": false,
              "text": "The SSHD Configuration LoginGraceTime should be a number between 1 and 60 but it is not configured explictly and it's using the default value\n"
            }
          ]
        },
        {
          "number": 2,
          "status": "FAILED",
          "time": "2021-07-06T12:58:54.905Z",
          "tests": [
            {
              "id": "SSHD/DisableRootLogin",
              "passed": false,
              "text": "The SSHD Configuration PermitRootLogin should be \"no\" but the current value is \"yes\"\n"
            },
            {
              "id": "SSHD/CloseUnauthenticated",
              "passed": false,
              "text": "The SSHD Configuration LoginGraceTime should be a number between 1 and 60 but it is not configured explictly and it's using the default value\n"
            }
          ]
        }
      ]
    }
  }
}