Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/warrant-dev/apirunner
A lightweight test runner for testing http APIs
https://github.com/warrant-dev/apirunner
apis go golang json testing
Last synced: about 4 hours ago
JSON representation
A lightweight test runner for testing http APIs
- Host: GitHub
- URL: https://github.com/warrant-dev/apirunner
- Owner: warrant-dev
- License: apache-2.0
- Created: 2022-10-04T01:15:25.000Z (about 2 years ago)
- Default Branch: master
- Last Pushed: 2024-09-09T23:33:52.000Z (about 2 months ago)
- Last Synced: 2024-09-10T03:48:00.112Z (about 2 months ago)
- Topics: apis, go, golang, json, testing
- Language: Go
- Homepage:
- Size: 58.6 KB
- Stars: 33
- Watchers: 3
- Forks: 0
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# API Runner
[![Go Report Card](https://goreportcard.com/badge/github.com/warrant-dev/apirunner)](https://goreportcard.com/report/github.com/warrant-dev/apirunner)
A lightweight test runner for testing http APIs. Define test cases as json and execute them against any server (local or over the network).
Written in Go. Built by the [Warrant](https://warrant.dev/) team.
## Usage
### Install
```shell
go get github.com/warrant-dev/apirunner
```### Define API tests as json
Sample test file:
```json
{
"ignoredFields": [
"internalId"
],
"tests": [
{
"name": "createUser",
"request": {
"method": "POST",
"url": "/users",
"body": {
"email": "[email protected]"
}
},
"expectedResponse": {
"statusCode": 200,
"body": {
"userId": "{{ createUser.userId }}",
"email": "[email protected]"
}
}
},
{
"name": "getUserById",
"request": {
"method": "GET",
"url": "/users/{{ createUser.userId }}"
},
"expectedResponse": {
"statusCode": 200,
"body": {
"userId": "{{ createUser.userId }}",
"email": "[email protected]"
}
}
},
{
"name": "deleteUser",
"request": {
"method": "DELETE",
"url": "/users/{{ createUser.userId }}"
},
"expectedResponse": {
"statusCode": 200
}
}
]
}
```### Execute tests
```go
import (
"github.com/warrant-dev/apirunner"
)// Execute all tests in 'mytestfile.json' and print results
func main() {
runner, err := apirunner.NewRunner(apirunner.Config{
TestFileName: "mytestfile.json",
BaseUrl: "http://localhost:8000",
CustomHeaders: nil,
})
if err != nil {
panic(err)
}
runner.Execute()
}
```## Features
- Supports all HTTP operations (`GET`, `POST`, `PUT`, `DELETE` etc.)
- Deep comparison of json responses (objects and arrays)
- Inject custom headers via config (useful for passing auth tokens)
- `ignoredFields` to ignore specific attributes during comparison (ex. non-deterministic ids, timestamps)
- Memoization of response attributes to support request chaining. For example, this test references an id of a resource created by a previous request:```json
{
"name": "updateResourceTest",
"request": {
"method": "PUT",
"url": "/resources/{{ createResourceTest.Id }}",
"body": {
"email": "[email protected]"
}
},
"expectedResponse": {
"statusCode": 200,
"body": {
"id": "{{ createResourceTest.Id }}",
"email": "[email protected]"
}
}
}
```## Development
PRs welcome! Clone and develop locally:
```shell
git clone [email protected]:warrant-dev/apirunner.git
cd apirunner
go test
```## About Warrant
[Warrant](https://warrant.dev/) provides APIs and infrastructure for implementing authorization and access control.