Giter Site home page Giter Site logo

linuxsuren / api-testing Goto Github PK

View Code? Open in Web Editor NEW
219.0 10.0 50.0 3.01 MB

YAML based API testing tool. 开源接口调试、测试工具。Mock Server

Home Page: https://linuxsuren.github.io/api-testing/

License: Apache License 2.0

Dockerfile 0.75% Go 74.75% Makefile 4.48% HTML 0.51% JavaScript 1.70% TypeScript 5.19% Shell 0.51% Vue 10.15% CSS 0.25% Smarty 1.54% PureBasic 0.17%
api testing grpc http hacktoberfest api-testing graphql trpc mock-server mock

api-testing's Introduction

CLA assistant Codacy Badge Codacy Badge GitHub All Releases Docker Pulls LinuxSuRen/open-source-best-practice

English | 中文

This is a API testing tool. 🚀

Features

  • Supported protocols: HTTP, gRPC, tRPC
  • Multiple test report formats: Markdown, HTML, PDF, Stdout
  • Mock Server in simple configuration, and Open API support
  • Support converting to JMeter files
  • Response Body fields equation check or eval
  • Validate the response body with JSON schema
  • Pre and post handle with the API request
  • Run in server mode, and provide the gRPC and HTTP endpoint
  • VS Code extension support
  • Multiple storage backends supported(Local, ORM Database, S3, Git, Etcd, etc.)
  • HTTP API record
  • Install in multiple use cases(CLI, Container, Native-Service, Operator, Helm, etc.)
  • Monitoring integration with Prometheus, SkyWalking

Get started

Try in PWD

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, then you could visit the UI from 8080:

docker run --pull always -p 8080:8080 ghcr.io/linuxsuren/api-testing:master

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.

Community Exchange

Feel free to talk to us about any questions you may have about API Testing in the following ways.

Mailing List

[email protected], Feel free to discuss everything related to API Testing via this mailing list.

GitHub discussion

GitHub Discussion

api-testing's People

Contributors

acceleratorssr avatar agility6 avatar chan158 avatar dependabot[bot] avatar dshyjtdes8888 avatar dwj-squirtle avatar hahahashen avatar haiker2011 avatar hellojukay avatar im-jinxinwang avatar ink-33 avatar kuv2707 avatar linuxsuren avatar lizzy-0323 avatar samysf avatar setcy avatar slowdowno avatar wjsvec avatar wongearl avatar wt-goodluck avatar yjuns avatar yukicoco avatar yuluo-yx avatar zhouzhou1017 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

api-testing's Issues

Support converting test cases between atest and postman

We could add a new sub-command. Such as: atest convert --from postman --input example.json --to atest --output example.yaml.

In the future, we could consider supporting converting between any kind of data. And the atest format will play the middle role. It means A could to be converted to atest, then convert atest to your desired format.

References

Support sending test report to a HTTP server

Sometimes, we might want to send the test report to an HTTP server.

How to

It's easy to do this. Please implement the following interface first:

type TestReporter interface {

then, add the corresponding CLI flag.

flags.StringVarP(&opt.pattern, "pattern", "p", "test-suite-*.yaml",

Use cases

  • Send test report to LinuxSuRen/gogit#35. So users could see the report from a Gitlab merge request.

Got error when running the sample grpc testsuite file

I got an error when trying the following command:

go run . run -p sample/grpc-sample.yaml

See the output:

sample/grpc-sample.yaml pattern 1
found suites: 1
routing end with 13.817028ms
API Average Max Min QPS Count Error
gRPC Runner.GetVersion 6.065096ms 6.065096ms 6.065096ms 0 1 0
gRPC Runner.FunctionsQuery 3.48314ms 3.48314ms 3.48314ms 0 1 0
gRPC Runner.FunctionsQueryStream 2.891849ms 2.891849ms 2.891849ms 0 1 1
consume: 14.054419ms
Error: failed to run 'FunctionsQueryStream', proto: syntax error (line 1:1): unexpected token [

By the way, I recommend adding the corresponding testing into the GitHub workflows. For instance, below might be a good place to add:

Support to generator code or commands base on the testcase

Sometimes, we might need to use the HTTP request in different cases. For instance, take the HTTP request as javascript code lines running in the browser. Or, use the curl command to run in Linux.

All the languages could send an HTTP request. But we could support some of the most popular ones:

  • curl command
  • JavaScript
  • Golang
  • Python
  • Java

A very important thing that we need to consider, is how to make sure the generated code lines work well.

Support download the extension files from OCI registry

Consider we could push any arbitrary files into an image registry (such as Docker hub). So, we could push the extension files into it, and then download it once it is required.

There are some benefits if we do this:

  • The GitHub release is not anymore the only place for saving extension files.
  • There are many image registries we could use. For instance, dockerhub, aliyun registry, quay.io

Below is an example of how to pull files from an OCI registry.

https://pkg.go.dev/oras.land/oras-go/v2#example-package-PullFilesFromRemoteRepository

Support to install atest in Docker and Kubernetes

atest could install as a Linux or macOS service according to the OS until v0.0.12. See also the following output. See the code lines of this sub-command

# atest service
Error: not support action: ''
Usage:
  atest service [flags]

Aliases:
  service, s

Flags:
  -a, --action string        The action of service, support actions: install, start, stop, restart, status
  -h, --help                 help for service
      --script-path string   The service script file path

atest could run in Docker or Kubernetes as well. So, it's good to support installing in Docker and Kubernetes. You could find the Kubernetes manifest files.

In order to specify the target environment, we could add a new flag --target. For example:

atest service install --target (os | docker | kubernetes)

Considering the compatibility, we could make the default value of --target to be os.

Support sending HTTP request through unix socket

Some services provide the HTTP through unix socket. For instance:

Below is a sample code:

package main

import (
	"bufio"
	"fmt"
	"io"
	"net"
)

func main() {
	conn, err := net.Dial("unix", "/run/podman/podman.sock")
	if err != nil {
		panic(err)
	}

	fmt.Fprintf(conn, "GET /v4.0.0/libpod/secrets/name/json?showsecret=true HTTP/1.0\r\n\r\n")
	reader := bufio.NewReader(conn)

	var status string
	if status, err = reader.ReadString('\n'); err == nil {
		fmt.Println(status)
	} else {
		fmt.Println(err)
	}

	var header string
	if header, err = reader.ReadString('\n'); err == nil {
		fmt.Println(header)
	} else {
		fmt.Println(err)
	}

	var body []byte
	if body, err = io.ReadAll(reader); err == nil {
		fmt.Println(string(body))
	} else {
		fmt.Println(err)
	}
}

Add more samples

add more samples, like how to write post, put and delete test

Command "atest service action" is not support in CentOS

OS: CentOS 7.9
Version: 0.0.11
Install Mode: Install it via hd

I try the command atest service --action start|stop|restart|status, and print the error information. Like this:
image
Then I see the code in the programs is systemctl start atest, I tried to run it, and the result is :
image

Making the UI as an extension point as well

Now, we have serval extension points:

  • storage
  • secret

Actually, providing UI extension is also very important. Different protocals have different elements, it's better to load the corresponding page instead of putting all things together. For example, gRPC, HTTP, and webSocket might be very different with each other.

Suggested extension points might be:

  • [UI] Store editing and creating page
  • [UI] TestCase page

There are some potential solutions:

Support loading test cases from git repository

Expected usage: atest run -p https://github.com/LinuxSuRen/api-testing/tree/master/sample --auth personal-token

We need to consider the git branch and auth. Usually, the branch name could found from the URL. We could manipulate the git repository via jenkins-x/go-scm.

UI

In many cases, people will deploy a private Gitlab, and provide it to the team. Having an oauth integration might be a good idea for the users. They could login with their own account. So, we don't need to consider the user management.

See also the similar issue #94

Add a mapping between Go and JMeter template functions

#170 could convert the API Testing file into a JMeter file. But there're some issues that we need to fix. For instance, they have different template functions. As I mentioned in the title, we could have a mapping. See below:

atest JMeter
{{randAlpha 6}} ${__RandomString(6,abcdefghijksf,)}

Support run command set item name

I have a test yaml have many items, like create, list, update and delete. I want to only run create by item name.

command like

atest run -p test-suite-demo.yaml   --report md --name "create demo"

Support before/after at the test suite level

It could be similar with #69. See the following example:

name: Gitlab
before:
  items:
    - "waitPod('default-ns', 'app=gitlab', '2m')"
items:
- name: projects
  request:
    api: https://gitlab.com/api/v4/projects
  before:
    items:
      - "sleep(1)"

There are some desired functions needed:

  • waitPod: wait until the pod is ready
  • createK3d
  • delK3d: delete a k3d cluster

References

Support set different image registry server

This project publishes images to the following container registries:

  • docker.io
  • ghcr.io

And, the following is kind of the proxy image address. So linuxsuren.docker.scarf.sh is an available container registry as well.

linuxsuren.docker.scarf.sh/linuxsuren/api-testing

You could add it to the following section

Expect

Users could use the following flags to choose different container registry:

helm install atest oci://docker.io/linuxsuren/api-testing \
    --version image.registry=ghcr.io

Support to take the user-defined test report template

Currently, all the test reports are embed in the code lines. But it's quite normal that uesrs want a new test report style. A simple solution is that allowing pass a user-defined template.

A suggestion is adding a flag to the following command:

atest run --report-template (my-template.md | my-template.html | https://foo/my-template.html)

References

Feature: Request for Executing an API Request after Another API Request and Supporting Delayed Execution

大佬您好:
我希望请求在特定的API端点上增加延迟功能,某个api 在另外一个api之后进行,并运行延迟一段时间(比如某个 api先create,然后多一段时间执行另外一个api请求)。这个功能将极大地提升处理API调用的灵活性和控制性。

目前,在向API端点发送请求后需要引入延迟,以模拟特定情景或确保与外部系统的同步。然而,现有的实现缺乏将这种延迟纳入考虑的能力。

提议的解决方案是扩展API测试框架,以在每个API端点上包含可配置的延迟选项。此外,支持后续执行操作将非常有益,允许用户定义在请求发送后立即执行的特定任务。

整合这些功能将使用户能够创建更全面的测试场景,包括涉及延迟和后续操作的情景,最终提高框架的整体测试能力。

感谢您考虑这个请求。比如 增加after:xxApi; delay;1minute; 表示该api 在xxApi 1分钟后执行

Provide the UI page of gRPC testing

Thanks to @Ink-33, this project has the gRPC feature. But the web UI is still very important. Please see also the following ideas if anyone is interested in it:

  • Having the similar UI style of the HTTP feature

We will have a release after this issue.

References

Provide a gRPC endpoint to getting the version

Currently, we only have one endpoint for running the test cases. The VS Code extension could communicate with it. It would be great if the VS Code side could get the version and prompt users if they upgrade atest according to the version comparison.

Please feel free to read the following references before trying to fix this issue:

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.