Documentation
¶
Index ¶
- func AuthHeaders(requestID string) map[string]string
- func AuthenticateFromEnv() error
- func CreateUSDAsset(ctx context.Context, client *HTTPClient, orgID, ledgerID string, ...) error
- func DockerAction(action, container string, extraArgs ...string) error
- func DockerExec(container string, args ...string) (string, error)
- func DockerLogsSince(container, since string, tail int) (string, error)
- func DockerNetwork(action, network, container string) error
- func EnableDefaultBalance(ctx context.Context, trans *HTTPClient, orgID, ledgerID, alias string, ...) error
- func EnsureDefaultBalanceRecord(ctx context.Context, trans *HTTPClient, orgID, ledgerID, accountID string, ...) error
- func GetAvailableSumByAlias(ctx context.Context, trans *HTTPClient, orgID, ledgerID, alias, asset string, ...) (decimal.Decimal, error)
- func OrgPayload(name, legalDocument string) map[string]any
- func RandHex(n int) string
- func RandString(n int) string
- func RestartWithWait(container string, wait time.Duration) error
- func RunTestsWithAuth(m *testing.M)
- func StartLogCapture(containers []string, testName string) func()
- func URLHostPort(raw string) (string, error)
- func WaitForAvailableSumByAlias(ctx context.Context, trans *HTTPClient, orgID, ledgerID, alias, asset string, ...) (decimal.Decimal, error)
- func WaitForHTTP200(fullURL string, timeout time.Duration) error
- func WaitForTCP(hostPort string, timeout time.Duration) error
- func WriteTextFile(path string, content string) error
- type Environment
- type HTTPClient
- func (c *HTTPClient) Request(ctx context.Context, method, path string, headers map[string]string, body any) (int, []byte, error)
- func (c *HTTPClient) RequestFull(ctx context.Context, method, path string, headers map[string]string, body any) (int, []byte, http.Header, error)
- func (c *HTTPClient) RequestFullWithRetry(ctx context.Context, method, path string, headers map[string]string, body any, ...) (int, []byte, http.Header, error)
- func (c *HTTPClient) RequestRaw(ctx context.Context, method, path string, headers map[string]string, ...) (int, []byte, http.Header, error)
- func (c *HTTPClient) RequestWithHeaderValues(ctx context.Context, method, path string, headers map[string][]string, ...) (int, []byte, http.Header, error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AuthHeaders ¶
AuthHeaders returns default headers including Authorization and X-Request-Id. If TEST_AUTH_HEADER is set, its value is used for Authorization.
func AuthenticateFromEnv ¶
func AuthenticateFromEnv() error
AuthenticateFromEnv obtains a Bearer token using env vars and exports TEST_AUTH_HEADER. Inputs via env:
TEST_AUTH_URL: OAuth token endpoint (e.g., https://auth.../v1/login/oauth/access_token) TEST_AUTH_USERNAME: username TEST_AUTH_PASSWORD: password
If TEST_AUTH_URL is empty, no-op. On success sets TEST_AUTH_HEADER to "Bearer <token>".
func CreateUSDAsset ¶
func CreateUSDAsset(ctx context.Context, client *HTTPClient, orgID, ledgerID string, headers map[string]string) error
CreateUSDAsset posts a minimal USD asset to the onboarding API; ignores if already exists.
func DockerAction ¶
DockerAction performs a docker container action like stop/start/restart/pause/unpause.
func DockerExec ¶
DockerExec runs a command inside a running container and returns its combined output.
func DockerLogsSince ¶
DockerLogsSince returns docker logs for a container since the provided RFC3339 timestamp. If tail > 0, limits the number of lines returned.
func DockerNetwork ¶
DockerNetwork connects or disconnects a container to/from a Docker network. action should be "connect" or "disconnect".
func EnableDefaultBalance ¶
func EnableDefaultBalance(ctx context.Context, trans *HTTPClient, orgID, ledgerID, alias string, headers map[string]string) error
EnableDefaultBalance sets AllowSending/AllowReceiving to true on the default balance for an account alias.
func EnsureDefaultBalanceRecord ¶
func EnsureDefaultBalanceRecord(ctx context.Context, trans *HTTPClient, orgID, ledgerID, accountID string, headers map[string]string) error
EnsureDefaultBalanceRecord waits until the default balance exists for the given account ID. It no longer attempts to create the default, as the system creates it asynchronously upon account creation.
func GetAvailableSumByAlias ¶
func GetAvailableSumByAlias(ctx context.Context, trans *HTTPClient, orgID, ledgerID, alias, asset string, headers map[string]string) (decimal.Decimal, error)
GetAvailableSumByAlias returns the sum of Available across all balances for the given alias and asset code.
func OrgPayload ¶
OrgPayload returns a minimal valid organization payload including a valid country code.
func RandString ¶
func RestartWithWait ¶
RestartWithWait restarts a container and waits a bit for it to come back.
func RunTestsWithAuth ¶
RunTestsWithAuth authenticates using env (if configured) and runs tests, failing fast on auth errors. Usage in each package's TestMain:
func TestMain(m *testing.M) { helpers.RunTestsWithAuth(m) }
func StartLogCapture ¶
StartLogCapture marks a start timestamp and returns a function that writes docker logs for the given containers since that timestamp to ./reports/logs/<container>_<testName>.log. Intended for use within tests; paths are relative to the package CWD (e.g., tests/chaos).
func URLHostPort ¶
URLHostPort extracts host:port from a base URL string. If no port is specified, it defaults based on scheme (https=443, http=80).
func WaitForAvailableSumByAlias ¶
func WaitForAvailableSumByAlias(ctx context.Context, trans *HTTPClient, orgID, ledgerID, alias, asset string, headers map[string]string, expected decimal.Decimal, timeout time.Duration) (decimal.Decimal, error)
WaitForAvailableSumByAlias polls until the available sum for alias equals expected, or timeout.
func WaitForHTTP200 ¶
WaitForHTTP200 polls a URL until it returns HTTP 200 or timeout elapses.
func WaitForTCP ¶
WaitForTCP waits until the given host:port is accepting connections or timeout elapses.
func WriteTextFile ¶
WriteTextFile ensures the directory exists and writes content to path, overwriting any existing file.
Types ¶
type Environment ¶
type Environment struct {
OnboardingURL string
TransactionURL string
ManageStack bool // if true, tests may start/stop stack via Makefile
HTTPTimeout time.Duration
}
Environment holds base URLs for Midaz services and behavior flags.
func LoadEnvironment ¶
func LoadEnvironment() Environment
LoadEnvironment loads environment configuration with sensible defaults matching the local docker-compose setup.
type HTTPClient ¶
type HTTPClient struct {
// contains filtered or unexported fields
}
HTTPClient wraps a standard http.Client with base URL handling.
func NewHTTPClient ¶
func NewHTTPClient(base string, timeout time.Duration) *HTTPClient
NewHTTPClient constructs a client with given base URL and timeout.
func (*HTTPClient) Request ¶
func (c *HTTPClient) Request(ctx context.Context, method, path string, headers map[string]string, body any) (int, []byte, error)
Request executes an HTTP request with optional JSON body and returns status code and response body.
func (*HTTPClient) RequestFull ¶
func (c *HTTPClient) RequestFull(ctx context.Context, method, path string, headers map[string]string, body any) (int, []byte, http.Header, error)
RequestFull executes an HTTP request and returns status, body, and headers.
func (*HTTPClient) RequestFullWithRetry ¶
func (c *HTTPClient) RequestFullWithRetry(ctx context.Context, method, path string, headers map[string]string, body any, attempts int, baseBackoff time.Duration) (int, []byte, http.Header, error)
RequestFullWithRetry performs RequestFull with simple retry/backoff for transient statuses. Retries on 429, 502, 503, 504 or network errors up to attempts with exponential backoff.
func (*HTTPClient) RequestRaw ¶
func (c *HTTPClient) RequestRaw(ctx context.Context, method, path string, headers map[string]string, contentType string, raw []byte) (int, []byte, http.Header, error)
RequestRaw sends a request with an arbitrary raw body and explicit Content-Type.
func (*HTTPClient) RequestWithHeaderValues ¶
func (c *HTTPClient) RequestWithHeaderValues(ctx context.Context, method, path string, headers map[string][]string, body any) (int, []byte, http.Header, error)
RequestWithHeaderValues executes an HTTP request with explicit header values including duplicates. The map value is a slice; each value is added using Header.Add in order. Content-Type is NOT auto-set.