Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[CLI Improvements] Migrate Tests to resource manager architecture - CLI #2352

Closed
danielbdias opened this issue Apr 11, 2023 · 0 comments
Closed

Comments

@danielbdias
Copy link
Contributor

danielbdias commented Apr 11, 2023

As the new changes are applied to the backend to move tests to the resources framework

A part of the migration is to include the CLI changes to support the test verbs, this includes:

  • Apply
  • Get
  • List
  • Export
  • Delete

With the update of the run existing method to work as it currently does, without behavioral changes

Verb Definition

tracetest get test --id [the id]

Description: Get a test by ID
Required flags: --id
Optional Flags: none
Pretty Output Example:

ID Name Version Trigger Type Runs Last Run Time Last Run Successes Last Run Fails URL
WZGNTOBVg Pokeshop - List 1 http 5 2hs ago 1 0 http://localhost:11633/test/WZGNTOBVg

JSON Output Example:

{
	"type": "Test",
	"spec": {
		"id": "uivSWYf4g",
		"name": "Pokeshop - List",
		"description": "Get a Pokemon",
		"version": 1,
		"createdAt": "2023-03-27T20:08:14.171787Z",
		"serviceUnderTest": {
			"triggerType": "http",
			"triggerSettings": {
				"http": {
					"url": "http://demo-pokemon-api.demo.svc.cluster.local/not-exists",
					"method": "GET",
					"headers": [{
						"key": "Content-Type",
						"value": "application/json"
					}]
				}
			}
		},
		"specs": {
			"specs": [{
				"name": "",
				"selector": {
					"query": "span[tracetest.span.type=\"general\" name=\"Tracetest trigger\"]",
					"structure": [{
						"filters": [{
								"property": "tracetest.span.type",
								"operator": "=",
								"value": "general"
							},
							{
								"property": "name",
								"operator": "=",
								"value": "Tracetest trigger"
							}
						]
					}]
				},
				"assertions": [
					"attr:tracetest.response.status = 200"
				]
			}]
		},
		"summary": {
			"runs": 5,
			"lastRun": {
				"time": "2023-03-27T20:08:14.366933Z",
				"passes": 1
			}
		}
	}
}

YAML Output example:

---
type: Test
spec:
  id: uivSWYf4g
  name: Pokeshop - List
  description: Get a Pokemon
  trigger:
    type: http
    http:
    	url: http://demo-pokemon-api.demo.svc.cluster.local/not-exists
      method: GET
      headers:
      - key: Content-Type
      value: application/json
  specs:
    - selector: span[tracetest.span.type="general" name="Tracetest trigger"]
      assertions:
      - attr:tracetest.response.status = 200

tracetest list test

Description: List Tests
Required flags: none
Optional Flags:

  • --all Get all results, not paginated. If passed, --take and --skip do nothing
  • --take N take N records [default: 20]
  • --skip N skip the first N records [default: 0]
  • --query get resources matching the given query string

Pretty Output Example:

Total avialable Tests: 2

ID Name Version Trigger Type Runs Last Run Time Last Run Successes Last Run Fails URL
WZGNTOBVg Pokeshop - List 1 http 5 2hs ago 1 0 http://localhost:11633/test/WZGNTOBVg
WZGNTOBVg Pokeshop - List 1 http 5 2hs ago 1 0 http://localhost:11633/test/WZGNTOBVg

JSON Output Example:

{
  "items": [
    {
      "type": "Test",
      "spec": {
        "id": "uivSWYf4g",
        "name": "Pokeshop - List",
        "description": "Get a Pokemon",
        "version": 1,
        "createdAt": "2023-03-27T20:08:14.171787Z",
        "serviceUnderTest": {
          "triggerType": "http",
          "triggerSettings": {
            "http": {
              "url": "http://demo-pokemon-api.demo.svc.cluster.local/not-exists",
              "method": "GET",
              "headers": [{
                "key": "Content-Type",
                "value": "application/json"
              }]
            }
          }
        },
        "specs": {
          "specs": [{
            "name": "",
            "selector": {
              "query": "span[tracetest.span.type=\"general\" name=\"Tracetest trigger\"]",
              "structure": [{
                "filters": [{
                    "property": "tracetest.span.type",
                    "operator": "=",
                    "value": "general"
                  },
                  {
                    "property": "name",
                    "operator": "=",
                    "value": "Tracetest trigger"
                  }
                ]
              }]
            },
            "assertions": [
              "attr:tracetest.response.status = 200"
            ]
          }]
        },
        "summary": {
          "runs": 5,
          "lastRun": {
            "time": "2023-03-27T20:08:14.366933Z",
            "passes": 1
          }
        }
      }
    },
    {
      "type": "Test",
      "spec": {
        "id": "uivSWYf4g",
        "name": "Pokeshop - List",
        "description": "Get a Pokemon",
        "version": 1,
        "createdAt": "2023-03-27T20:08:14.171787Z",
        "serviceUnderTest": {
          "triggerType": "http",
          "triggerSettings": {
            "http": {
              "url": "http://demo-pokemon-api.demo.svc.cluster.local/not-exists",
              "method": "GET",
              "headers": [{
                "key": "Content-Type",
                "value": "application/json"
              }]
            }
          }
        },
        "specs": {
          "specs": [{
            "name": "",
            "selector": {
              "query": "span[tracetest.span.type=\"general\" name=\"Tracetest trigger\"]",
              "structure": [{
                "filters": [{
                    "property": "tracetest.span.type",
                    "operator": "=",
                    "value": "general"
                  },
                  {
                    "property": "name",
                    "operator": "=",
                    "value": "Tracetest trigger"
                  }
                ]
              }]
            },
            "assertions": [
              "attr:tracetest.response.status = 200"
            ]
          }]
        },
        "summary": {
          "runs": 5,
          "lastRun": {
            "time": "2023-03-27T20:08:14.366933Z",
            "passes": 1
          }
        }
      }
    }
  ],

}

YAML Output example:

---
type: Test
spec:
  id: uivSWYf4g
  name: Pokeshop - List
  description: Get a Pokemon
  trigger:
    type: http
    http:
    	url: http://demo-pokemon-api.demo.svc.cluster.local/not-exists
      method: GET
      headers:
      - key: Content-Type
      value: application/json
  specs:
    - selector: span[tracetest.span.type="general" name="Tracetest trigger"]
      assertions:
      - attr:tracetest.response.status = 200
---
type: Test
spec:
  id: uivSWYf4g
  name: Pokeshop - List
  description: Get a Pokemon
  trigger:
    type: http
    http:
    	url: http://demo-pokemon-api.demo.svc.cluster.local/not-exists
      method: GET
      headers:
      - key: Content-Type
      value: application/json
  specs:
    - selector: span[tracetest.span.type="general" name="Tracetest trigger"]
      assertions:
      - attr:tracetest.response.status = 200

tracetest delete test --id [the id]

Description: Delete a test by ID
Required flags: --id
Optional Flags: none
Pretty Output Example:

Test successfully deleted

JSON Output Example:

{
  "success": true,
  "errors": [],
  "message": "Test successfully deleted"
}

YAML Output Example:

---
sucess: true
message: Test successfully deleted
errors: []

tracetest apply test --file [path]

Description: Save a test to the server. If it does not yet exists on the server, it is created. Otherwise it is updated.
Input can be a file with one or more documents, or a directory with files with one or more documents. This is not transactional, so if an error happens, all changes to resources applied until the error are kept.
Required flags: --file|-f input file or directory
Optional Flags: none
Validation:

  • if the given file does not have a spec.id set: The resource file does not have a ID defined in the "spec" object. Please provide a unique one. For example, you can use [SHOW A RANDOM VALID ID]
  • if a document's type is not Test: Invalid type [actual type]. Expected Test

Pretty Output Example:

Test successfully applied

JSON Output Example:

{
  "success": true,
  "errors": [],
  "message": "Test successfully applied"
}

YAML Output Example:

---
sucess: true
message: Test successfully applied
errors: []

tracetest run test --id [the id] or tracetest run test --file [path]

Description: Run a test by ID or from a definition file
Required flags: one of --id or --file|-f
Optional Flags:

  • --environment|-e [the id] environment ID to use
  • --wait-for-results|-w wait for results
  • --junit [path] save the results as junit in the given path. Requires --wait-for-results|-w

Validation:

  • if running from --file
    • if the given file does not have a spec.id set: The resource file does not have a ID defined in the "spec" object. Please provide a unique one. For example, you can use [SHOW A RANDOM VALID ID]

Output
Keep current behavior

@danielbdias danielbdias changed the title [CLI Improvements] Migrate DataStores to resource manager architecture - CLI [CLI Improvements] Migrate Tests to resource manager architecture - CLI Apr 11, 2023
@xoscar xoscar closed this as completed Jun 5, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants