helper

package
v0.9.1 Latest Latest
Warning

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

Go to latest
Published: Aug 19, 2025 License: Apache-2.0 Imports: 36 Imported by: 0

Documentation

Overview

Simple copy file

Simplifies work with file testing

Simplifies work with ssh testing

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CompareDirFiles added in v0.7.6

func CompareDirFiles(dir1, dir2 string) error

func CopyFile

func CopyFile(src, dst string) error

CopyFile will copy files around

func CreateRandomFiles added in v0.7.6

func CreateRandomFiles(dir string, amount int) ([]string, error)

CreateRandomFiles will take directory and put there as much random files as you want

func ExpectFailure

func ExpectFailure(t *testing.T, f func(tt testing.TB))

xpectFailure when failure expected

func MockSSHPortServer added in v0.7.6

func MockSSHPortServer(t *testing.T, user, pass, key string) (string, string)

func MockSSHPtyServer added in v0.7.6

func MockSSHPtyServer(t *testing.T, user, pass, key string) (string, string)

func MockSSHServer added in v0.7.6

func MockSSHServer(t *testing.T, sshSrv *sshd.Server, user, pass, key string) (string, string)

Base ssh server with no handler

func MockSSHSftpServer added in v0.7.6

func MockSSHSftpServer(t *testing.T, user, pass, key string) (string, string)

func NewRPCClient added in v0.9.0

func NewRPCClient(username, password string, clientType RPCClientType, caPool *x509.CertPool) (*http.Client, []connect.ClientOption)

NewRPCClient creates a new HTTP client and returns it along with the appropriate connect options for the specified client type and authentication credentials.

func Retry

func Retry(r Retryer, t Failer, f func(r *R))

Retry again

func RunCmdPtySSH added in v0.7.6

func RunCmdPtySSH(addr, username, password, cmd string) ([]byte, error)

func RunSftp added in v0.7.6

func RunSftp(addr, username, password string, files []string, toPath string, toRemote bool) error

SCP nowadays uses sftp subsystem with no need for scp binary on the target, so use it directly

Types

type AFInstance added in v0.7.5

type AFInstance struct {
	// contains filtered or unexported fields
}

AFInstance saves state of the running Aquarium Fish for particular test

func NewAfInstance

func NewAfInstance(tb testing.TB, name, cfg string) *AFInstance

NewAfInstance helpful if you need to create instance without starting it up right away

func NewAquariumFish

func NewAquariumFish(tb testing.TB, name, cfg string, args ...string) *AFInstance

NewAquariumFish simple creates and run the fish node

func NewStoppedAquariumFish added in v0.9.0

func NewStoppedAquariumFish(tb testing.TB, name, cfg string) *AFInstance

NewStoppedAquariumFish creates the fish node

func (*AFInstance) APIAddress added in v0.7.5

func (afi *AFInstance) APIAddress(path string) string

APIAddress will return url to access API of AquariumFish

func (*AFInstance) APIEndpoint added in v0.7.6

func (afi *AFInstance) APIEndpoint() string

APIEndpoint will return IP:PORT

func (*AFInstance) AdminToken added in v0.7.5

func (afi *AFInstance) AdminToken() string

AdminToken returns admin token

func (*AFInstance) Cleanup added in v0.7.5

func (afi *AFInstance) Cleanup(tb testing.TB)

Cleanup after the test execution You don't need to call it if you use NewAfInstance(), NewAquariumFish() or NewStoppedAquariumFish()

func (*AFInstance) GetCA added in v0.9.0

func (afi *AFInstance) GetCA(tb testing.TB) *x509.CertPool

GetCA will return the node CA pool for secure communication

func (*AFInstance) IsRunning added in v0.7.5

func (afi *AFInstance) IsRunning() bool

IsRunning checks the fish instance is running

func (*AFInstance) NewAfInstanceCluster added in v0.7.5

func (afi *AFInstance) NewAfInstanceCluster(tb testing.TB, name, cfg string) *AFInstance

NewAfInstanceCluster just creates the node based on the existing cluster node

func (*AFInstance) NewClusterNode added in v0.7.5

func (afi *AFInstance) NewClusterNode(tb testing.TB, name, cfg string, args ...string) *AFInstance

NewClusterNode starts another node of cluster It will automatically add cluster_join parameter to the config

func (*AFInstance) PrintMemUsage added in v0.8.0

func (afi *AFInstance) PrintMemUsage(tb testing.TB)

func (*AFInstance) Restart added in v0.7.5

func (afi *AFInstance) Restart(tb testing.TB, args ...string)

Restart the application

func (*AFInstance) Start added in v0.7.5

func (afi *AFInstance) Start(tb testing.TB, args ...string)

Start the fish node executable

func (*AFInstance) Stop added in v0.7.5

func (afi *AFInstance) Stop(tb testing.TB)

Stop the fish node executable

func (*AFInstance) WaitForLog added in v0.8.0

func (afi *AFInstance) WaitForLog(substring string, call func(string, string) bool)

WaitForLog stores substring to be looked in the Fish log to execute call function with substring & found line

func (*AFInstance) WaitForLogDelete added in v0.9.0

func (afi *AFInstance) WaitForLogDelete(substring string)

WaitForLog stores substring to be looked in the Fish log to execute call function with substring & found line

func (*AFInstance) Workspace added in v0.7.5

func (afi *AFInstance) Workspace() string

Workspace will return workspace of the AquariumFish

type Counter

type Counter struct {
	Count int
	Wait  time.Duration
	// contains filtered or unexported fields
}

Counter repeats an operation a given number of times and waits between subsequent operations.

func (*Counter) Continue

func (r *Counter) Continue() bool

Continue counter

type Failer

type Failer interface {
	Helper()

	// Log is called for the final test output
	Log(args ...any)

	// FailNow is called when the retrying is abandoned.
	FailNow()
}

Failer is an interface compatible with testing.T.

type MockT

type MockT struct {
	testing.T

	FailNowCalled bool
	// contains filtered or unexported fields
}

MockT is useful to capture the failed test

func (*MockT) FailNow

func (m *MockT) FailNow()

FailNow when it's the right time

func (*MockT) Fatal

func (m *MockT) Fatal(args ...any)

Fatal message

func (*MockT) Fatalf

func (m *MockT) Fatalf(format string, args ...any)

Fatalf message

func (*MockT) Log

func (m *MockT) Log(args ...any)

Log message

func (*MockT) Logf

func (m *MockT) Logf(format string, args ...any)

Logf message

type NotificationBuffer added in v0.9.0

type NotificationBuffer struct {
	// contains filtered or unexported fields
}

NotificationBuffer stores recent notifications in a circular buffer

func NewNotificationBuffer added in v0.9.0

func NewNotificationBuffer(size int) *NotificationBuffer

NewNotificationBuffer creates a new circular buffer for notifications

func (*NotificationBuffer) Add added in v0.9.0

Add stores a notification in the circular buffer

func (*NotificationBuffer) FindMatching added in v0.9.0

FindMatching searches the buffer for a notification matching the filter

type R

type R struct {
	// contains filtered or unexported fields
}

R provides context for the retryer.

func (*R) Check

func (r *R) Check(err error)

Check check if everything is ok

func (*R) Error

func (r *R) Error(args ...any)

Error log error

func (*R) Errorf

func (r *R) Errorf(format string, args ...any)

Errorf log error

func (*R) FailNow

func (r *R) FailNow()

FailNow will fail the retry

func (*R) Fatal

func (r *R) Fatal(args ...any)

Fatal fail and log

func (*R) Fatalf

func (r *R) Fatalf(format string, args ...any)

Fatalf fail and log

func (*R) Helper

func (*R) Helper()

Helper shows this struct as helper

func (*R) Stop

func (r *R) Stop(err error)

Stop retrying, and fail the test with the specified error.

type RPCClientType added in v0.9.0

type RPCClientType int

RPCClientType represents the type of ConnectRPC client to create

const (
	// RPCClientREST creates a REST-like client using HTTP GET
	RPCClientREST RPCClientType = iota
	// RPCClientGRPC creates a gRPC client
	RPCClientGRPC
	// RPCClientGRPCWeb creates a gRPC-Web client
	RPCClientGRPCWeb
)

type Retryer

type Retryer interface {
	// Continue returns true if the operation should be repeated, otherwise it
	// returns false to indicate retrying should stop.
	Continue() bool
}

Retryer provides an interface for repeating operations until they succeed or an exit condition is met.

type StreamingClient added in v0.9.0

type StreamingClient struct {
	// contains filtered or unexported fields
}

StreamingClient provides a high-level interface for streaming operations

func NewStreamingClient added in v0.9.0

func NewStreamingClient(ctx context.Context, t *testing.T, name string, client aquariumv2connect.StreamingServiceClient) *StreamingClient

NewStreamingClient creates a new streaming client with clean abstractions

func (*StreamingClient) Close added in v0.9.0

func (sc *StreamingClient) Close()

Close gracefully closes all streaming connections

func (*StreamingClient) EstablishBidirectionalStreaming added in v0.9.0

func (sc *StreamingClient) EstablishBidirectionalStreaming() error

EstablishBidirectionalStreaming sets up bidirectional streaming for request/response operations

func (*StreamingClient) EstablishSubscriptionStreaming added in v0.9.0

func (sc *StreamingClient) EstablishSubscriptionStreaming(subscriptionTypes []aquariumv2.SubscriptionType) error

EstablishSubscriptionStreaming sets up server-side streaming for real-time notifications

func (*StreamingClient) GetResourceNotifications added in v0.9.0

func (sc *StreamingClient) GetResourceNotifications() <-chan *aquariumv2.StreamingServiceSubscribeResponse

GetResourceNotifications returns the channel for application resource notifications

func (*StreamingClient) GetStateNotifications added in v0.9.0

func (sc *StreamingClient) GetStateNotifications() <-chan *aquariumv2.StreamingServiceSubscribeResponse

GetStateNotifications returns the channel for application state notifications

func (*StreamingClient) GetTaskNotifications added in v0.9.0

func (sc *StreamingClient) GetTaskNotifications() <-chan *aquariumv2.StreamingServiceSubscribeResponse

GetTaskNotifications returns the channel for application task notifications

func (*StreamingClient) SendRequest added in v0.9.0

func (sc *StreamingClient) SendRequest(requestID, requestType string, requestData proto.Message) (*aquariumv2.StreamingServiceConnectResponse, error)

SendRequest sends a request through bidirectional streaming and waits for response

func (*StreamingClient) WaitForApplicationResource added in v0.9.0

func (sc *StreamingClient) WaitForApplicationResource(timeout time.Duration) (*aquariumv2.ApplicationResource, error)

WaitForApplicationResource waits for an application resource notification

func (*StreamingClient) WaitForApplicationState added in v0.9.0

func (sc *StreamingClient) WaitForApplicationState(applicationUID string, expectedState aquariumv2.ApplicationState_Status, timeout time.Duration) (*aquariumv2.ApplicationState, error)

WaitForApplicationState waits for a specific application state notification for a specific application UID

func (*StreamingClient) WaitForApplicationTask added in v0.9.0

func (sc *StreamingClient) WaitForApplicationTask(timeout time.Duration) (*aquariumv2.ApplicationTask, error)

WaitForApplicationTask waits for an application task notification

func (*StreamingClient) WaitForNotification added in v0.9.0

WaitForNotification waits for a specific notification type with optional filtering

type StreamingTestHelper added in v0.9.0

type StreamingTestHelper struct {
	// contains filtered or unexported fields
}

StreamingTestHelper provides an even higher-level interface for common test patterns

func NewStreamingTestHelper added in v0.9.0

func NewStreamingTestHelper(ctx context.Context, t *testing.T, name string, client aquariumv2connect.StreamingServiceClient) *StreamingTestHelper

NewStreamingTestHelper creates a new test helper with streamlined setup

func (*StreamingTestHelper) Close added in v0.9.0

func (sth *StreamingTestHelper) Close()

Close closes all streaming connections

func (*StreamingTestHelper) GetStreamingClient added in v0.9.0

func (sth *StreamingTestHelper) GetStreamingClient() *StreamingClient

GetStreamingClient returns the underlying streaming client for advanced operations

func (*StreamingTestHelper) SendRequestAndExpectSuccess added in v0.9.0

func (sth *StreamingTestHelper) SendRequestAndExpectSuccess(requestID, requestType string, requestData proto.Message, expectedResponseType string) (*aquariumv2.StreamingServiceConnectResponse, error)

SendRequestAndExpectSuccess sends a request and expects a successful response

func (*StreamingTestHelper) SetupFullStreaming added in v0.9.0

func (sth *StreamingTestHelper) SetupFullStreaming(subscriptionTypes []aquariumv2.SubscriptionType) error

SetupFullStreaming establishes both bidirectional and subscription streaming

type Timer

type Timer struct {
	Timeout time.Duration
	Wait    time.Duration
	// contains filtered or unexported fields
}

Timer repeats an operation for a given amount of time and waits between subsequent operations.

func (*Timer) Continue

func (r *Timer) Continue() bool

Continue the timer

Jump to

Keyboard shortcuts

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