gotest

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Feb 3, 2024 License: MIT Imports: 11 Imported by: 0

README

Still under development

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ContentTypeJson  = "application/json"                  // ContentTypeJson is for APIs with Json content.
	ContentTypeXml   = "application/xml"                   // ContentTypeXml is for APIs with Xml content.
	ContentTypeForm  = "application/x-www-form-urlencoded" // ContentTypeForm is for APIs with Form content.
	ContentTypeText  = "text/plain"                        // ContentTypeText is for APIs with Text content.
	ContentTypeHtml  = "text/html"                         // ContentTypeHtml is for APIs with Html content.
	ContentTypePdf   = "application/pdf"                   // ContentTypePdf is for APIs with Pdf content.
	ContentTypeZip   = "application/zip"                   // ContentTypeZip is for APIs with Zip content.
	ContentTypePng   = "image/png"                         // ContentTypePng is for APIs with Png content.
	ContentTypeJpg   = "image/jpeg"                        // ContentTypeJpg is for APIs with Jpg content.
	ContentTypeGif   = "image/gif"                         // ContentTypeGif is for APIs with Gif content.
	ContentTypeSvg   = "image/svg+xml"                     // ContentTypeSvg is for APIs with Svg content.
	ContentTypeBmp   = "image/bmp"                         // ContentTypeBmp is for APIs with Bmp content.
	ContentTypeTiff  = "image/tiff"                        // ContentTypeTiff is for APIs with Tiff content.
	ContentTypePpt   = "application/vnd.ms-powerpoint"     // ContentTypePpt is for APIs with Ppt content.
	ContentTypeDoc   = "application/msword"                // ContentTypeDoc is for APIs with Doc content.
	ContentTypeXls   = "application/vnd.ms-excel"          // ContentTypeXls is for APIs with Xls content.
	ContentTypeCsv   = "text/csv"                          // ContentTypeCsv is for APIs with Csv content.
	ContentTypeXml2  = "application/xml; charset=utf-8"    // ContentTypeXml2 is for APIs with Xml2 content.
	ContentTypeHtml2 = "text/html; charset=utf-8"          // ContentTypeHtml2 is for APIs with Html2 content.
)

Functions

func GeneratePathParam

func GeneratePathParam(getParam map[string]string) string

GeneratePathParam function generates a query string from a map of path parameters.

Types

type ApiTest

type ApiTest struct {
	Tests       int64                   // Tests is the count fo total test cases.
	PassedTests int64                   // PassedTests is the count of passed test cases.
	FailedTests int64                   // FailedTests is the count of failed test cases.
	Result      map[int64]ApiTestResult // Result is the result of the test cases.
	Server      *httptest.Server        // Server is the server for the test cases.
	ServerMux   *http.ServeMux          // ServerMux is the mux for the server.
}

ApiTest is a struct that contains the test cases for an API.

func InitApiTest

func InitApiTest() *ApiTest

InitApiTest function initializes an instance of the ApiTest struct and returns a pointer to it.

Example usage:

``` var T *ApiTest T = InitApiTest() // Initialize main route // More process... T.DumpApiTestResult(true) ```

func (*ApiTest) CreateTest

func (h *ApiTest) CreateTest(httpReq ApiTestRequest)

CreateTest function creates a new test case for an API call.

func (*ApiTest) DumpApiTestResult

func (h *ApiTest) DumpApiTestResult(needExit bool)

DumpApiTestResult function prints the result of the API test cases in to the terminal.

type ApiTestRequest

type ApiTestRequest struct {
	Details        string      // Details is the details like case of the API call.
	ReqParam       interface{} // ReqParam is the path parameters of the API call.
	ReqBody        interface{} // ReqBody is the body parameters of the API call.
	ApiUrl         string      // ApiUrl is the endpoint URL of the API call.
	ApiMethod      string      // ApiMethod is the method of the API call.
	ContentType    interface{} // ContentType is the content type of the API call.
	BearerToken    interface{} // BearerToken is the bearer token (like JWT token) of the API call.
	ExpectedStatus interface{} // ExpectedStatus is the expected status code of the response.
}

ApiTestRequest is the request for a test case.

type ApiTestResult

type ApiTestResult struct {
	TestStatus      bool          // TestStatus is the status of the test case.
	TestDescription string        // TestDescription is the description of the test case.
	TestError       interface{}   // TestError is the error of the test case, if available.
	TestTime        time.Duration // TestTime is the time of the test case.
}

ApiTestResult is the result of a test case.

Jump to

Keyboard shortcuts

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