api-testing

command module
v0.0.12 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 18, 2023 License: MIT Imports: 4 Imported by: 0

README

Codacy Badge Codacy Badge GitHub All Releases LinuxSuRen/open-source-best-practice

This is a API testing tool.

Features

  • Multiple test report formats: Markdown, HTML, Stdout
  • Response Body fields equation check
  • Response Body eval
  • Verify the Kubernetes resources
  • Validate the response body with JSON schema
  • Pre and post handle with the API request
  • Output reference between TestCase
  • Run in server mode, and provide the gRPC endpoint
  • VS Code extension support
  • HTTP API record

Get started

Install it via hd or download from releases:

hd install atest

or, you can install it in Kubernetes. See also the manifests.

see the following usage:

API testing tool

Usage:
  atest [command]

Available Commands:
  completion  Generate the autocompletion script for the specified shell
  func        Print all the supported functions
  help        Help about any command
  json        Print the JSON schema of the test suites struct
  run         Run the test suite
  sample      Generate a sample test case YAML file
  server      Run as a server mode
  service     Install atest as a Linux service

Flags:
  -h, --help      help for atest
  -v, --version   version for atest

Use "atest [command] --help" for more information about a command.

below is an example of the usage, and you could see the report as well:

atest run -p sample/testsuite-gitlab.yaml --duration 1m --thread 3 --report md

API Average Max Min Count Error
GET https://gitlab.com/api/v4/projects 1.152777167s 2.108680194s 814.928496ms 99 0
GET https://gitlab.com/api/v4/projects/45088772 840.761064ms 1.487285371s 492.583066ms 10 0
consume: 1m2.153686448s

Use in Docker

Use atest as server mode in Docker:

docker run -p 7070:7070 ghcr.io/linuxsuren/api-testing

Use atest-collector in Docker:

docker run -p 1234:8080 -v /var/tmp:/var/tmp \
  ghcr.io/linuxsuren/api-testing atest-collector \
  --filter-path /api \
  -o /var/tmp/sample.yaml
# you could find the test cases file from /var/tmp/sample
# cat /var/tmp/sample

Template

The following fields are templated with sprig:

  • API
  • Request Body
  • Request Header

Functions

You could use all the common functions which comes from sprig. Besides some specific functions are available:

Name Usage
randomKubernetesName {{randomKubernetesName}} to generate Kubernetes resource name randomly, the name will have 8 chars
sleep {{sleep(1)}} in the pre and post request handle

Verify against Kubernetes

It could verify any kinds of Kubernetes resources. Please set the environment variables before using it:

  • KUBERNETES_SERVER
  • KUBERNETES_TOKEN

See also the example.

TODO

  • Reduce the size of context
  • Support customized context

Limit

  • Only support to parse the response body when it's a map or array

Documentation

The Go Gopher

There is no documentation for this package.

Directories

Path Synopsis
Package cmd provides all the commands
Package cmd provides all the commands
extensions
collector Module
store-etcd Module
store-orm Module
store-s3 Module
operator module
pkg
render
Package render provides a simple way to render as template
Package render provides a simple way to render as template
runner
Package runner responsible for excute the test case
Package runner responsible for excute the test case
runner/kubernetes
Package kubernetes provides a low level client for small footprint consideration
Package kubernetes provides a low level client for small footprint consideration
server
Package server provides a GRPC based server
Package server provides a GRPC based server
testing
Package testing provide the test case functions
Package testing provide the test case functions
util
Package util provides a set of common functions
Package util provides a set of common functions
version
Package version provides the version access of this app
Package version provides the version access of this app

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL