Documentation ¶
Overview ¶
Package helpers contains constants, variables, functions, and structures used in unit tests. At this moment, just basic HTTP/REST API-based unit tests needs such helpers.
Index ¶
- Variables
- func AMSClientWithOrgResults(orgID types.OrgID, clusters []types.ClusterInfo) amsclient.AMSClient
- func AssertAPIRequest(t testing.TB, serverConfig *server.Configuration, ...)
- func AssertAPIv2Request(t testing.TB, serverConfig *server.Configuration, ...)
- func CreateHTTPServer(serverConfig *server.Configuration, servicesConfig *services.Configuration, ...) *server.HTTPServer
- func GetMockRedis() (mockClient services.RedisClient, mockServer redismock.ClientMock)
- func RedisExpectationsMet(t *testing.T, mock redismock.ClientMock)
- type APIRequest
- type APIResponse
Constants ¶
This section is empty.
Variables ¶
var ( // ExecuteRequest function executes specified HTTP request ExecuteRequest = helpers.ExecuteRequest // CheckResponseBodyJSON function checks response body. It is supposed // that the body is represented in JSON format CheckResponseBodyJSON = helpers.CheckResponseBodyJSON // AssertReportResponsesEqual function fails if report responses aren't // equal to each other AssertReportResponsesEqual = helpers.AssertReportResponsesEqual // NewGockAPIEndpointMatcher function creates a matcher for a given // endpoint for gock NewGockAPIEndpointMatcher = helpers.NewGockAPIEndpointMatcher // GockExpectAPIRequest function makes gock expect the request with the // baseURL and sends back the response GockExpectAPIRequest = helpers.GockExpectAPIRequest // CleanAfterGock function cleans after gock library and prints all // unmatched requests CleanAfterGock = helpers.CleanAfterGock // MustGobSerialize function serializes an object using gob or panics // if serialize oparation fails for any reason MustGobSerialize = helpers.MustGobSerialize )
var ( // DefaultServerConfig is data structure that represents default HTTP // server configuration (with CORS disabled) DefaultServerConfig = server.Configuration{ Address: ":8081", APIdbgPrefix: "/api/dbg/", APIv1Prefix: "/api/v1/", APIv2Prefix: "/api/v2/", APIv1SpecFile: "server/api/v1/openapi.json", APIv2SpecFile: "server/api/v2/openapi.json", Debug: true, Auth: true, AuthType: "jwt", UseHTTPS: false, EnableCORS: false, EnableInternalRulesOrganizations: false, } // DefaultServerConfigXRH is data structure that represents default HTTP // server configuration with XRH auth type. XRH type is used in all pre-prod/prod environments. DefaultServerConfigXRH = server.Configuration{ Address: ":8081", APIdbgPrefix: "/api/dbg/", APIv1Prefix: "/api/v1/", APIv2Prefix: "/api/v2/", APIv1SpecFile: "server/api/v1/openapi.json", APIv2SpecFile: "server/api/v2/openapi.json", Debug: true, Auth: true, AuthType: "xrh", UseHTTPS: false, EnableCORS: false, EnableInternalRulesOrganizations: false, } // DefaultServerConfigCORS is data structure that represents default // server configuration with CORS enabled DefaultServerConfigCORS = server.Configuration{ Address: ":8081", APIdbgPrefix: "/api/dbg/", APIv1Prefix: "/api/v1/", APIv2Prefix: "/api/v2/", APIv1SpecFile: "server/api/v1/openapi.json", APIv2SpecFile: "server/api/v2/openapi.json", Debug: true, Auth: true, AuthType: "xrh", UseHTTPS: false, EnableCORS: true, } // DefaultServicesConfig is data structure that represents default // services configuration DefaultServicesConfig = services.Configuration{ AggregatorBaseEndpoint: "http://localhost:8080/", ContentBaseEndpoint: "http://localhost:8082/", GroupsPollingTime: 1 * time.Minute, ContentDirectoryTimeout: 100 * time.Millisecond, } )
var ( // DefaultRedisConf is the default Redis configuration used in tests DefaultRedisConf services.RedisConfiguration )
var FailOnError = helpers.FailOnError
FailOnError function fails on any error detected in tests
var RunTestWithTimeout = helpers.RunTestWithTimeout
RunTestWithTimeout function runs test with specified timeToRun timeout and fails if it wasn't finished in time
var ToJSONString = helpers.ToJSONString
ToJSONString function converts any value or data structure to JSON string
Functions ¶
func AMSClientWithOrgResults ¶
AMSClientWithOrgResults creates a mock of AMSClient interface that returns the results defined by orgID and clusters parameters
func AssertAPIRequest ¶
func AssertAPIRequest( t testing.TB, serverConfig *server.Configuration, servicesConfig *services.Configuration, groupsChannel chan []groups.Group, errorFoundChannel chan bool, errorChannel chan error, request *helpers.APIRequest, expectedResponse *helpers.APIResponse, )
AssertAPIRequest function creates new server with provided serverConfig, servicesConfig (you can leave them nil to use the default ones), groupsChannel and errorChannel (can be set to nil as well) sends api request and checks api response (see docs for APIRequest and APIResponse)
func AssertAPIv2Request ¶
func AssertAPIv2Request( t testing.TB, serverConfig *server.Configuration, servicesConfig *services.Configuration, groupsChannel chan []groups.Group, errorFoundChannel chan bool, errorChannel chan error, request *helpers.APIRequest, expectedResponse *helpers.APIResponse, )
AssertAPIv2Request function is exactly the same as AssertAPIResponse, but intended to use with API v2 endpoints
func CreateHTTPServer ¶
func CreateHTTPServer( serverConfig *server.Configuration, servicesConfig *services.Configuration, amsClient amsclient.AMSClient, redis services.RedisInterface, groupsChannel chan []groups.Group, errorFoundChannel chan bool, errorChannel chan error, ) *server.HTTPServer
CreateHTTPServer creates an instance of the REST API server with provided or default configuration
func GetMockRedis ¶
func GetMockRedis() ( mockClient services.RedisClient, mockServer redismock.ClientMock, )
GetMockRedis is used to get a mocked Redis client to expect and respond to queries
func RedisExpectationsMet ¶
RedisExpectationsMet helper function used to ensure mock expectations were met
Types ¶
type APIResponse ¶
type APIResponse = helpers.APIResponse
APIResponse data type represents APIResponse