utils

package
v7.0.1+incompatible Latest Latest
Warning

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

Go to latest
Published: Aug 25, 2022 License: Apache-2.0, BSD-2-Clause, BSD-3-Clause, + 1 more Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Compare

func Compare(t *testing.T, expected []string, alertsStrs []string)

func CreateV3Session

func CreateV3Session(t *testing.T, TrafficOpsURL string, username string, password string, toReqTimeout int) *v3client.Session

CreateV3Session creates a session for client v4 using the passed in username and password.

func CreateV4Session

func CreateV4Session(t *testing.T, TrafficOpsURL string, username string, password string, toReqTimeout int) *v4client.Session

CreateV4Session creates a session for client v4 using the passed in username and password.

func ErrorsToStrings

func ErrorsToStrings(errs []error) []string

func FindNeedle

func FindNeedle(needle string, haystack []string) bool

Types

type CkReqFunc

type CkReqFunc func(*testing.T, toclientlib.ReqInf, interface{}, tc.Alerts, error)

CkReqFunc defines the reusable signature for all other functions that perform checks. Common parameters that are checked include the request's info, response, alerts, and errors.

func CkRequest

func CkRequest(c ...CkReqFunc) []CkReqFunc

CkRequest wraps CkReqFunc functions, to be concise and reduce lexical tokens i.e. Instead of `[]CkReqFunc {` we can use `CkRequest(` in test case declarations.

func HasError

func HasError() CkReqFunc

HasError checks that an error was returned (i.e. not `nil`).

func HasStatus

func HasStatus(expectedStatus int) CkReqFunc

HasStatus checks that the status code from the request is as expected.

func NoError

func NoError() CkReqFunc

NoError checks that no error was returned (i.e. `nil`).

func ResponseHasLength

func ResponseHasLength(expected int) CkReqFunc

ResponseHasLength checks that the length of the response is as expected. Determines that response is a slice before checking the length of the reflected value.

func ResponseLengthGreaterOrEqual

func ResponseLengthGreaterOrEqual(expected int) CkReqFunc

ResponseLengthGreaterOrEqual checks that the response is greater or equal to the expected length. Determines that response is a slice before checking the length of the reflected value.

type ErrorAndMessage

type ErrorAndMessage struct {
	Error   error
	Message string
}

type V3TestCase

type V3TestCase map[string]map[string]V3TestData

V3TestCase is the type of the V3TestData struct. Uses nested map to represent the method being tested and the test's description.

type V3TestData

type V3TestData struct {
	EndpointId     func() int
	ClientSession  *v3client.Session
	RequestParams  url.Values
	RequestHeaders http.Header
	RequestBody    map[string]interface{}
	Expectations   []CkReqFunc
}

V3TestData represents the data needed for testing the v3 api endpoints.

type V4TestCase

type V4TestCase map[string]map[string]V4TestData

V4TestCase is the type of the V4TestData struct. Uses nested map to represent the method being tested and the test's description.

type V4TestData

type V4TestData struct {
	EndpointId    func() int
	ClientSession *v4client.Session
	RequestOpts   v4client.RequestOptions
	RequestBody   map[string]interface{}
	Expectations  []CkReqFunc
}

V4TestData represents the data needed for testing the v4 api endpoints.

Jump to

Keyboard shortcuts

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