Categorygithub.com/akash1729/apitester
repositorypackage
0.0.0-20200617170710-7b1308925180
Repository: https://github.com/akash1729/apitester.git
Documentation: pkg.go.dev

# Packages

No description provided by the author
No description provided by the author
No description provided by the author

# README

apitester : API testing package

Overview GoDoc

Package to unittest test golang API with json request and responses.

Install

go get github.com/akash1729/apitester

Example

package usage

import (
	"testing"

	"github.com/akash1729/apitester"
)

func GetUserTests(t *testing.T) {

	testCase := apitester.TestCase{
		TestName:    "CreateUser",
		TestDetail:  "Proper Implemetaion",
		Route:       "/User",
		Method:      "POST",
		HandlerFunc: CreateUser, //import and assign corresponding handler
		StatusCode:  200,
		AvoidKey:    []string{"token"},
		RequestHeader: map[string]string{
			"Authorization": "authorization key",
		},
		RequestMap: map[string]interface{}{
			"username": "nitya",
			"password": "password"},
		ResponseHeader: map[string]string{
			"Content-Type": "application/json",
		},
		ResponseMap: map[string]interface{}{
			"status":   "User Created succesfully",
			"userID":   88,
			"username": "nitya"},
		TypeCheck: map[string]interface{}{
			"token":    "stringType",
			"userID":   0,
			"username": "stringType",
		},
		RequestContextKey:   "requestID",
		RequestContextValue: 123,
	}

	apitester.RunTest(&testCase, t)

}

Only HandlerFunc Field is mandatory All other fields are optional during testing

Author

Akash Thomas

License

MIT.