goapitester

package module
v0.0.0-...-3583424 Latest Latest
Warning

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

Go to latest
Published: Apr 6, 2020 License: MIT Imports: 7 Imported by: 0

README

Go API Tester

A simple helper that makes your life easier

Usage

package test

import (
    "testing"
    goapitester "github.com/timokoenig/go-api-tester"
)

func TestCreate(t *testing.T) {
    tester := goapitester.NewAPITester("<request-body>")
    tester.Authorize("<auth-token>")
    tester.Run(func(req *restful.Request, rsp *restful.Response) {
        sut := Calendar{}
        sut.Create(req, rsp)
    })
    tester.CompareBody(t, "<expected-response-body>")
    tester.CompareStatus(t, <expected-response-status>)
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type APITester

type APITester struct {
	// contains filtered or unexported fields
}

APITester helps you testing go-micro APIs

func NewAPITester

func NewAPITester(requestBody string) *APITester

NewAPITester creates a new helper that makes your life easier

func (*APITester) Authorize

func (a *APITester) Authorize(token string)

Authorize sets the given bearer authorization token for the current request

func (*APITester) CompareBody

func (a *APITester) CompareBody(t *testing.T, expected string)

CompareBody compares the exepcted body with the response body

func (*APITester) CompareHeader

func (a *APITester) CompareHeader(t *testing.T, key string, expected string)

CompareHeader compares the header value of the given key with the response header

func (*APITester) CompareStatus

func (a *APITester) CompareStatus(t *testing.T, extected int)

CompareStatus compares the expected status with the response status

func (*APITester) Run

func (a *APITester) Run(handler func(req *restful.Request, rsp *restful.Response))

Run the requset with the given handler

Jump to

Keyboard shortcuts

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