utils

package
v0.0.0-...-949823d Latest Latest
Warning

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

Go to latest
Published: Nov 10, 2024 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// DefaultProbeTimeout is the a timeout used in HTTPGetNTimes() and
	// HTTPGetRawNTimes() to avoid cases where early requests hang and
	// block all subsequent requests.
	DefaultProbeTimeout = 30 * time.Second
)
View Source
const (
	// Environment variable for setting the target OS where tests are running on.
	TargetOsEnvVar = "TARGET_OS"
)

Variables

This section is empty.

Functions

func FormatDuration

func FormatDuration(d time.Duration) string

FormatDuration formats the duration in ms

func GetHTTPClient

func GetHTTPClient() *http.Client

GetHTTPClient returns the shared httpClient object.

func HTTPDelete

func HTTPDelete(url string) ([]byte, error)

HTTPDelete calls a given URL with the HTTP DELETE method.

func HTTPDeleteWithStatus

func HTTPDeleteWithStatus(url string) ([]byte, int, error)

HTTPDeleteWithStatus calls a given URL with the HTTP DELETE method.

func HTTPGet

func HTTPGet(url string) ([]byte, error)

HTTPGet is a helper to make GET request call to url.

func HTTPGetNTimes

func HTTPGetNTimes(url string, n int) ([]byte, error)

HTTPGetNTimes calls the url n times and returns the first success or last error.

func HTTPGetRaw

func HTTPGetRaw(url string) (*http.Response, error)

HTTPGetRaw is a helper to make GET request call to url.

func HTTPGetRawNTimes

func HTTPGetRawNTimes(url string, n int) (*http.Response, error)

HTTPGetRawNTimes calls the url n times and returns the first success or last error.

func HTTPGetRawWithHeaders

func HTTPGetRawWithHeaders(url string, header http.Header) (*http.Response, error)

func HTTPGetWithStatus

func HTTPGetWithStatus(url string) ([]byte, int, error)

HTTPGetWithStatus is a helper to make GET request call to url.

func HTTPGetWithStatusWithData

func HTTPGetWithStatusWithData(surl string, data []byte) ([]byte, int, error)

HTTPGetWithStatusWithData is a helper to make GET request call to url.

func HTTPGetWithStatusWithMetadata

func HTTPGetWithStatusWithMetadata(url string) ([]byte, int, http.Header, error)

HTTPGetWithStatusWithMetadata is a helper to make GET request call to url.

func HTTPPatch

func HTTPPatch(url string, data []byte) ([]byte, error)

HTTPPatch is a helper to make PATCH request call to url.

func HTTPPost

func HTTPPost(url string, data []byte) ([]byte, error)

HTTPPost is a helper to make POST request call to url.

func HTTPPostWithStatus

func HTTPPostWithStatus(url string, data []byte) ([]byte, int, error)

HTTPPostWithStatus is a helper to make POST request call to url.

func HealthCheckApps

func HealthCheckApps(urls ...string) error

HealthCheckApps performs healthchecks for multiple apps, waiting for them to be ready.

func InitHTTPClient

func InitHTTPClient(allowHTTP2 bool)

InitHTTPClient inits the shared httpClient object.

func NewHTTPClient

func NewHTTPClient(allowHTTP2 bool) *http.Client

NewHTTPClient initializes a new *http.Client. This should not be used except in rare circumstances. Developers should use the shared httpClient instead to re-use sockets as much as possible.

func SanitizeHTTPURL

func SanitizeHTTPURL(url string) string

SanitizeHTTPURL prepends the prefix "http://" to a URL if not present

func SetupLogs

func SetupLogs(testName string)

SetupLogs sets up the target for the built-in "log" package. Logs are always written to STDOUT. If the DAPR_TEST_LOG_PATH environmental variable is set, logs are also written to a file in that folder.

func TestTargetOS

func TestTargetOS() string

TestTargetOS returns the name of the OS that the tests are targeting (which could be different from the local OS).

Types

type SimpleKeyValue

type SimpleKeyValue struct {
	Key   any
	Value any
}

SimpleKeyValue can be used to simplify code, providing simple key-value pairs.

func GenerateRandomStringKeyValues

func GenerateRandomStringKeyValues(num int) []SimpleKeyValue

GenerateRandomStringKeyValues generates random string key-values pairs.

func GenerateRandomStringKeys

func GenerateRandomStringKeys(num int) []SimpleKeyValue

GenerateRandomStringKeys generates random string keys (values are nil).

func GenerateRandomStringValues

func GenerateRandomStringValues(keyValues []SimpleKeyValue) []SimpleKeyValue

GenerateRandomStringValues sets random string values for the keys passed in.

type StateTransactionKeyValue

type StateTransactionKeyValue struct {
	Key           string
	Value         string
	OperationType string
}

StateTransactionKeyValue is a key-value pair with an operation type.

Jump to

Keyboard shortcuts

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