Documentation ¶
Index ¶
- Variables
- func AssertAPIRequest(t testing.TB, mockStorage storage.OCPRecommendationsStorage, ...)
- func GetHandlersMapForMockConsumer(t testing.TB, mockBroker *sarama.MockBroker, topicName string) map[string]sarama.MockResponse
- func MustCloseConsumer(t *testing.T, mockConsumer consumer.Consumer)
- func MustCloseMockDBWithExpects(t *testing.T, db *sql.DB, expects sqlmock.Sqlmock)
- func MustCloseMockStorageWithExpects(t *testing.T, mockStorage storage.OCPRecommendationsStorage, ...)
- func MustCloseMockStorageWithExpectsDVO(t *testing.T, mockStorage storage.DVORecommendationsStorage, ...)
- func MustCloseStorage(tb testing.TB, s storage.Storage)
- func MustGetMockDBWithExpects(t *testing.T) (*sql.DB, sqlmock.Sqlmock)
- func MustGetMockStorageWithExpects(t *testing.T) (storage.OCPRecommendationsStorage, sqlmock.Sqlmock)
- func MustGetMockStorageWithExpectsForDriver(t *testing.T, driverType types.DBDriver) (storage.OCPRecommendationsStorage, sqlmock.Sqlmock)
- func MustGetMockStorageWithExpectsForDriverDVO(t *testing.T, driverType types.DBDriver) (storage.DVORecommendationsStorage, sqlmock.Sqlmock)
- func MustGetPostgresStorage(tb testing.TB, init bool) (storage.OCPRecommendationsStorage, func())
- func MustGetPostgresStorageDVO(tb testing.TB, init bool) (storage.DVORecommendationsStorage, func())
- func PrepareDB(t *testing.T) (*storage.OCPRecommendationsDBStorage, func())
- func PrepareDBAndInfo(t *testing.T) (*sql.DB, types.DBDriver, migration.Schema, func())
- func PrepareDBDVO(t *testing.T) (*storage.DVORecommendationsDBStorage, func())
- func WaitForMockConsumerToHaveNConsumedMessages(mockConsumer *MockKafkaConsumer, nMessages uint64)
- type APIRequest
- type APIResponse
- type MockKafkaConsumer
- func GetMockDVOConsumerWithExpectedMessages(t testing.TB, topic string, orgAllowlist mapset.Set, messages []string) (*MockKafkaConsumer, func(), error)
- func GetMockOCPRulesConsumerWithExpectedMessages(t testing.TB, topic string, orgAllowlist mapset.Set, messages []string) (*MockKafkaConsumer, func(), error)
- func MustGetMockDVOConsumerWithExpectedMessages(t testing.TB, topic string, orgAllowlist mapset.Set, messages []string) (*MockKafkaConsumer, func())
- func MustGetMockOCPRulesConsumerWithExpectedMessages(t testing.TB, topic string, orgAllowlist mapset.Set, messages []string) (*MockKafkaConsumer, func())
Constants ¶
This section is empty.
Variables ¶
var ( // ExecuteRequest executes request ExecuteRequest = helpers.ExecuteRequest // CheckResponseBodyJSON checks response body CheckResponseBodyJSON = helpers.CheckResponseBodyJSON // AssertReportResponsesEqual fails if report responses aren't equal AssertReportResponsesEqual = helpers.AssertReportResponsesEqual // AssertReportResponsesEqualCustomElementsChecker fails if report responses aren't equal AssertReportResponsesEqualCustomElementsChecker = helpers.AssertReportResponsesEqualCustomElementsChecker // AssertRuleResponsesEqual fails if rule responses aren't equal AssertRuleResponsesEqual = helpers.AssertRuleResponsesEqual // NewGockRequestMatcher returns a new matcher for github.com/h2non/gock to match requests // with provided method, url and jsonBody NewGockRequestMatcher = helpers.NewGockRequestMatcher // GockExpectAPIRequest makes gock expect the request with the baseURL and sends back the response GockExpectAPIRequest = helpers.GockExpectAPIRequest // MakeXRHTokenString converts types.Token to a token string(base64 encoded) MakeXRHTokenString = helpers.MakeXRHTokenString )
var AssertStringsAreEqualJSON = helpers.AssertStringsAreEqualJSON
AssertStringsAreEqualJSON fails if strings represent different jsons
var CleanAfterGock = helpers.CleanAfterGock
CleanAfterGock cleans after gock library and prints all unmatched requests
var DefaultServerConfig = server.Configuration{ Address: ":8080", APIPrefix: "/api/test/", APISpecFile: "openapi.json", Debug: true, Auth: false, MaximumFeedbackMessageLength: 255, OrgOverviewLimitHours: 2, }
DefaultServerConfig is a default config used by AssertAPIRequest
var DefaultServerConfigAuth = server.Configuration{ Address: ":8080", APIPrefix: "/api/test/", APISpecFile: "openapi.json", Debug: true, Auth: true, AuthType: "xrh", MaximumFeedbackMessageLength: 255, OrgOverviewLimitHours: 2, }
DefaultServerConfigAuth is a default config used by AssertAPIRequest with authentication set to true
var FailOnError = helpers.FailOnError
FailOnError fails on error
var IsStringJSON = helpers.IsStringJSON
IsStringJSON checks if a string is a valid JSON
var RunTestWithTimeout = helpers.RunTestWithTimeout
RunTestWithTimeout runs test with timeout
var ToJSONString = helpers.ToJSONString
ToJSONString converts anything to JSON or panics if it's not possible isOutputPretty makes output indented
Functions ¶
func AssertAPIRequest ¶
func AssertAPIRequest( t testing.TB, mockStorage storage.OCPRecommendationsStorage, serverConfig *server.Configuration, request *helpers.APIRequest, expectedResponse *helpers.APIResponse, )
AssertAPIRequest creates new server with provided mockStorage (which you can keep nil so it will be created automatically) and provided serverConfig(you can leave it empty to use the default one) sends api request and checks api response (see docs for APIRequest and APIResponse)
func GetHandlersMapForMockConsumer ¶
func GetHandlersMapForMockConsumer(t testing.TB, mockBroker *sarama.MockBroker, topicName string) map[string]sarama.MockResponse
GetHandlersMapForMockConsumer returns handlers for mock broker to successfully create a new consumer
func MustCloseConsumer ¶
MustCloseConsumer closes consumer and raises error if it wasn't successful
func MustCloseMockDBWithExpects ¶
MustCloseMockDBWithExpects closes mock db with expects and panics if it wasn't successful
func MustCloseMockStorageWithExpects ¶
func MustCloseMockStorageWithExpects( t *testing.T, mockStorage storage.OCPRecommendationsStorage, expects sqlmock.Sqlmock, )
MustCloseMockStorageWithExpects closes mock storage with expects and panics if it wasn't successful
func MustCloseMockStorageWithExpectsDVO ¶ added in v1.4.0
func MustCloseMockStorageWithExpectsDVO( t *testing.T, mockStorage storage.DVORecommendationsStorage, expects sqlmock.Sqlmock, )
MustCloseMockStorageWithExpectsDVO same asMustCloseMockStorageWithExpects
func MustCloseStorage ¶
MustCloseStorage closes the storage and calls t.Fatal on error
func MustGetMockDBWithExpects ¶
MustGetMockDBWithExpects returns mock db with a driver "github.com/DATA-DOG/go-sqlmock" which requires you to write expect before each query, so first try to use MustGetPostgresStorage don't forget to call MustCloseMockDBWithExpects
func MustGetMockStorageWithExpects ¶
func MustGetMockStorageWithExpects(t *testing.T) (storage.OCPRecommendationsStorage, sqlmock.Sqlmock)
MustGetMockStorageWithExpects returns mock db storage with a driver "github.com/DATA-DOG/go-sqlmock" which requires you to write expect before each query, so first try to use MustGetPostgresStorage don't forget to call MustCloseMockStorageWithExpects
func MustGetMockStorageWithExpectsForDriver ¶
func MustGetMockStorageWithExpectsForDriver( t *testing.T, driverType types.DBDriver, ) (storage.OCPRecommendationsStorage, sqlmock.Sqlmock)
MustGetMockStorageWithExpectsForDriver returns mock db storage with specified driver type and with a driver "github.com/DATA-DOG/go-sqlmock" which requires you to write expect before each query, so first try to use MustGetPostgresStorage don't forget to call MustCloseMockStorageWithExpects
func MustGetMockStorageWithExpectsForDriverDVO ¶ added in v1.4.0
func MustGetMockStorageWithExpectsForDriverDVO( t *testing.T, driverType types.DBDriver, ) (storage.DVORecommendationsStorage, sqlmock.Sqlmock)
MustGetMockStorageWithExpectsForDriverDVO same as MustGetMockStorageWithExpectsForDriver but for DVO
func MustGetPostgresStorage ¶
func MustGetPostgresStorage(tb testing.TB, init bool) (storage.OCPRecommendationsStorage, func())
MustGetPostgresStorage creates test postgres storage with credentials from config-devel
func MustGetPostgresStorageDVO ¶ added in v1.4.0
func MustGetPostgresStorageDVO(tb testing.TB, init bool) (storage.DVORecommendationsStorage, func())
MustGetPostgresStorageDVO creates test postgres storage with credentials from config-devel for DVO storage
func PrepareDB ¶ added in v1.4.0
func PrepareDB(t *testing.T) (*storage.OCPRecommendationsDBStorage, func())
PrepareDB prepares mock OCPRecommendationsDBStorage
func PrepareDBAndInfo ¶ added in v1.4.0
PrepareDBAndInfo prepares mock OCPRecommendationsDBStorage and info table
func PrepareDBDVO ¶ added in v1.4.0
func PrepareDBDVO(t *testing.T) (*storage.DVORecommendationsDBStorage, func())
PrepareDBDVO prepares mock DVORecommendationsDBStorage
func WaitForMockConsumerToHaveNConsumedMessages ¶
func WaitForMockConsumerToHaveNConsumedMessages(mockConsumer *MockKafkaConsumer, nMessages uint64)
WaitForMockConsumerToHaveNConsumedMessages waits until mockConsumer has at least N consumed(either successfully or not) messages
Types ¶
type MockKafkaConsumer ¶
type MockKafkaConsumer struct { KafkaConsumer consumer.KafkaConsumer // contains filtered or unexported fields }
MockKafkaConsumer is mock consumer
func GetMockDVOConsumerWithExpectedMessages ¶ added in v1.4.0
func GetMockDVOConsumerWithExpectedMessages( t testing.TB, topic string, orgAllowlist mapset.Set, messages []string, ) (*MockKafkaConsumer, func(), error)
GetMockDVOConsumerWithExpectedMessages same as GetMockOCPRulesConsumerWithExpectedMessages but for DVO
func GetMockOCPRulesConsumerWithExpectedMessages ¶ added in v1.4.0
func GetMockOCPRulesConsumerWithExpectedMessages( t testing.TB, topic string, orgAllowlist mapset.Set, messages []string, ) (*MockKafkaConsumer, func(), error)
GetMockOCPRulesConsumerWithExpectedMessages creates mocked OCP rules consumer which produces list of messages automatically
func MustGetMockDVOConsumerWithExpectedMessages ¶ added in v1.4.0
func MustGetMockDVOConsumerWithExpectedMessages( t testing.TB, topic string, orgAllowlist mapset.Set, messages []string, ) (*MockKafkaConsumer, func())
MustGetMockDVOConsumerWithExpectedMessages same as MustGetMockOCPRulesConsumerWithExpectedMessages but for DVO
func MustGetMockOCPRulesConsumerWithExpectedMessages ¶ added in v1.4.0
func MustGetMockOCPRulesConsumerWithExpectedMessages( t testing.TB, topic string, orgAllowlist mapset.Set, messages []string, ) (*MockKafkaConsumer, func())
MustGetMockOCPRulesConsumerWithExpectedMessages creates mocked OCP rules consumer which produces list of messages automatically calls t.Fatal on error
func (*MockKafkaConsumer) Close ¶
func (mockKafkaConsumer *MockKafkaConsumer) Close(t testing.TB)
Close closes mock consumer
func (*MockKafkaConsumer) Serve ¶
func (mockKafkaConsumer *MockKafkaConsumer) Serve()
Serve simulates sending messages