common

package
v0.0.0-...-9b598c7 Latest Latest
Warning

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

Go to latest
Published: Jun 28, 2023 License: Apache-2.0 Imports: 27 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CheckMetric

func CheckMetric(h *test.Helper, t *testing.T, metric string, exist bool)

CheckMetric - check if the given metric exists in the metrics data

func CheckMetricExposed

func CheckMetricExposed(h *test.Helper, t *testing.T, metric string)

CheckMetricExposed - checks whether metric is exposed in the metrics URL

func GetOSDClusterID

func GetOSDClusterID(h *test.Helper, t *testing.T, expectedStatus *api.ClusterStatus) (string, *ocmErrors.ServiceError)

GetOSDClusterID - is used by tests to get a ClusterID value of an existing OSD cluster. If executed against real OCM client, content of internal/kafka/test/integration/test_cluster.json file (if present) is read to determine if there is a cluster running and new entry is added to the clusters table. If no such file is present, new cluster is created and its clusterID is retrieved. If expectedStatus is not nil then it will wait until expectedStatus is reached.

func GetOSDClusterIDAndWaitForStatus

func GetOSDClusterIDAndWaitForStatus(h *test.Helper, t *testing.T, expectedStatus api.ClusterStatus) (string, *ocmErrors.ServiceError)

func GetRunningOsdClusterID

func GetRunningOsdClusterID(h *test.Helper, t *testing.T) (string, *ocmErrors.ServiceError)

GetRunningOsdClusterID - is used by tests to get a ClusterID value of an existing OSD cluster in a 'ready' state. If executed against real OCM client, content of internal/kafka/test/integration/test_cluster.json file (if present) is read to determine if there is a cluster running and new entry is added to the clusters table. If no such file is present, new cluster is created and its clusterID is retrieved.

func IsMetricExposedWithValue

func IsMetricExposedWithValue(t *testing.T, metric string, values ...string) bool

IsMetricExposedWithValue - checks whether metric is exposed in the metrics URL and the metric value(s) match values param

func PersistClusterStruct

func PersistClusterStruct(cluster api.Cluster, status api.ClusterStatus) error

PersistClusterStruct to json file to be reused by tests that require a running cluster

func RemoveClusterFile

func RemoveClusterFile(t *testing.T)

func WaitForClusterIDToBeAssigned

func WaitForClusterIDToBeAssigned(db *db.ConnectionFactory, clusterService *services.ClusterService, criteria *services.FindClusterCriteria) (string, error)

WaitForClusterIDToBeAssigned - Awaits for clusterID to be assigned to the designed cluster

func WaitForClusterStatus

func WaitForClusterStatus(db *db.ConnectionFactory, clusterService *services.ClusterService, clusterId string, desiredStatus api.ClusterStatus) (cluster *api.Cluster, err error)

WaitForClusterStatus - Awaits for the cluster to reach the desired status

func WaitForClusterToBeDeleted

func WaitForClusterToBeDeleted(db *db.ConnectionFactory, clusterService *services.ClusterService, clusterId string) error

WaitForClusterToBeDeleted - Awaits for the specified cluster to be deleted

func WaitForClustersMatchCriteriaToBeGivenCount

func WaitForClustersMatchCriteriaToBeGivenCount(db *db.ConnectionFactory, clusterService *services.ClusterService, clusterCriteria *services.FindClusterCriteria, count int) error

WaitForClustersMatchCriteriaToBeGivenCount - Awaits for the number of clusters with an assigned cluster id to be exactly `count`

func WaitForKafkaClusterIDToBeAssigned

func WaitForKafkaClusterIDToBeAssigned(dbFactory *db.ConnectionFactory, kafkaRequestName string) (*dbapi.KafkaRequest, error)

func WaitForKafkaCreateToBeAccepted

func WaitForKafkaCreateToBeAccepted(ctx context.Context, db *db.ConnectionFactory, client *public.APIClient, k public.KafkaRequestPayload) (kafka public.KafkaRequest, resp *http.Response, err error)

WaitForKafkaCreateToBeAccepted - Creates a kafka and awaits for the request to be accepted

func WaitForKafkaToBeDeleted

func WaitForKafkaToBeDeleted(ctx context.Context, db *db.ConnectionFactory, client *public.APIClient, kafkaId string) error

WaitForKafkaToBeDeleted - Awaits for a kafka to be deleted

func WaitForKafkaToReachStatus

func WaitForKafkaToReachStatus(ctx context.Context, db *db.ConnectionFactory, client *public.APIClient, kafkaId string, status constants.KafkaStatus) (kafka public.KafkaRequest, err error)

WaitForKafkaToReachStatus - Awaits for a kafka to reach a specified status

func WaitForMetricToBePresent

func WaitForMetricToBePresent(h *test.Helper, t *testing.T, metric string, values ...string) error

func WaitForNumberOfKafkaToBeGivenCount

func WaitForNumberOfKafkaToBeGivenCount(ctx context.Context, db *db.ConnectionFactory, client *public.APIClient, count int32, customize ...func(builder PollerBuilder) PollerBuilder) error

WaitForNumberOfKafkaToBeGivenCount - Awaits for the number of kafkas to be exactly X

Types

type LogFunctionType

type LogFunctionType func(pattern string, args ...interface{})

type OnFinishFunc

type OnFinishFunc func(attempt int, maxRetries int, err error)

type OnRetryFunc

type OnRetryFunc func(attempt int, maxRetries int) (done bool, err error)

type OnStartFunc

type OnStartFunc func(maxRetries int) error

type Poller

type Poller interface {
	// Poll - starts the polling
	Poll() error
}

Poller - This is the actual poller

type PollerBuilder

type PollerBuilder interface {
	// OnStart - The passed in function is executed before starting the polling. Useful for setting things up or logging the start of the polling
	OnStart(onStart OnStartFunc) PollerBuilder
	// OnRetry - The passed in function is executed at each retry. This function should contain the desired logic.
	OnRetry(onRetry OnRetryFunc) PollerBuilder
	// OnFinish - The passed in function is executed after the polling has ended.
	// Polling can end if the desired event has occurred, if the `OnRetry` function has failed or if the maximum number of retries has been reached
	OnFinish(onFinish OnFinishFunc) PollerBuilder
	// IntervalAndTimeout - Sets the interval between each retry and the timeout after which the polling will end
	// This method can be used as alternative of IntervalAndRetries
	IntervalAndTimeout(interval time.Duration, timeout time.Duration) PollerBuilder
	// IntervalAndRetries - Sets the interval between each retry and the maximum number of attempt to perform before giving up
	// This method can be used as alternative of IntervalAndTimeout
	IntervalAndRetries(interval time.Duration, maxRetries int) PollerBuilder
	// DisableRetryLog - Call this if you don't want the poller to log the polling
	DisableRetryLog() PollerBuilder
	// RetryLogMessage - Message to be shown on each retry. For more advanced logging, use RetryLogFunction
	RetryLogMessage(msg string) PollerBuilder
	// RetryLogMessagef - Message to be shown on each retry. The message is formatted according to a format specifie.
	// For more advanced logging, use RetryLogFunction
	RetryLogMessagef(format string, params ...interface{}) PollerBuilder
	// RetryLogFunction - The function to be called each time the poller desires to show some log. Default: 'Retrying...'
	RetryLogFunction(logFunction func(retry int, maxRetry int) string) PollerBuilder
	// OutputFunction - Useful only if RetryLogFunction is not used. Sets the function the poller must use to
	// output the log. Defaults to fmt.Printf
	OutputFunction(logFunction LogFunctionType) PollerBuilder
	// MaxRetryLogs - Sets the maximum number of log statements we want to be showed. They are evenly divided by the
	// maximum number of attempts
	MaxRetryLogs(maxRetryLogs int) PollerBuilder
	// ShouldLog - To be used to customise when a log should be shown or not. The default function tries to respect the
	// MaxRetryLogs value.
	ShouldLog(shouldLog ShouldLogFunc) PollerBuilder
	DumpCluster(id string) PollerBuilder
	DumpDB(name string, filter string, columns ...string) PollerBuilder
	// Build - Builds the poller
	Build() Poller
}

PollerBuilder is to be used to create a poller to check for an event to happens

func NewPollerBuilder

func NewPollerBuilder(db *db.ConnectionFactory) PollerBuilder

type ShouldLogFunc

type ShouldLogFunc func(attempt int, maxRetries int, maxRetryLogs int) bool

Jump to

Keyboard shortcuts

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