Coder Social home page Coder Social logo

apirunner's Introduction

API Runner

Go Report Card

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 team.

Usage

Install

go get github.com/warrant-dev/apirunner

Define API tests as json

Sample test file:

{
    "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

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:
{
    "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:

git clone [email protected]:warrant-dev/apirunner.git
cd apirunner
go test

About Warrant

Warrant provides APIs and infrastructure for implementing authorization and access control.

apirunner's People

Contributors

akajla09 avatar dependabot[bot] avatar kkajla12 avatar

Watchers

 avatar

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.