helpers

package
v3.0.0-...-55b81f4 Latest Latest
Warning

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

Go to latest
Published: Apr 7, 2025 License: Apache-2.0 Imports: 30 Imported by: 0

Documentation

Overview

Copyright (c) F5, Inc.

This source code is licensed under the Apache License, Version 2.0 license found in the LICENSE file in the root directory of this source tree.

Index

Constants

This section is empty.

Variables

View Source
var GoLeakOptions = []goleak.Option{
	goleak.IgnoreTopFunction("go.opencensus.io/stats/view.(*worker).start"),
}

Functions

func CreateDirWithErrorCheck

func CreateDirWithErrorCheck(t testing.TB, dirName string)

func CreateFileWithErrorCheck

func CreateFileWithErrorCheck(t testing.TB, dir, fileName string) *os.File

func CreateNginxPlusStreamServer

func CreateNginxPlusStreamServer(t *testing.T) client.StreamUpstreamServer

func CreateNginxPlusUpstreamServer

func CreateNginxPlusUpstreamServer(t *testing.T) client.UpstreamServer

func CreateTestIDs

func CreateTestIDs(t testing.TB) (correlationID, instanceID uuid.UUID)

func Env

func Env(tb testing.TB, envKey string) string

func GenerateConfig

func GenerateConfig(t testing.TB, outputFile string, targetSize int64) (fs.FileInfo, error)

func GenerateSelfSignedCert

func GenerateSelfSignedCert(t testing.TB) (keyBytes, certBytes []byte)

func GetRandomPort

func GetRandomPort(t *testing.T) (int, error)

GetRandomPort generates a random port for testing and checks if a port is available by attempting to bind to it

func GoVersion

func GoVersion(t testing.TB, level int) (string, error)

func LogAndTerminateContainers

func LogAndTerminateContainers(
	ctx context.Context,
	tb testing.TB,
	mockManagementPlaneContainer testcontainers.Container,
	agentContainer testcontainers.Container,
	expectNoErrorsInLogs bool,
)

nolint: revive

func NewMockNGINXPlusAPIServer

func NewMockNGINXPlusAPIServer(t *testing.T) *httptest.Server

nolint: gocyclo,revive,cyclop,maintidx

func RemoveASCIIControlSignals

func RemoveASCIIControlSignals(t testing.TB, input string) string

RemoveASCIIControlSignals removes all non-printable ASCII control characters from a string.

func RemoveFileWithErrorCheck

func RemoveFileWithErrorCheck(t testing.TB, fileName string)

func RequiredModuleVersion

func RequiredModuleVersion(t testing.TB, moduleName string, level int) (string, error)

func StartAgentlessContainer

func StartAgentlessContainer(
	ctx context.Context,
	tb testing.TB,
	parameters *Parameters,
) testcontainers.Container

func StartContainer

func StartContainer(
	ctx context.Context,
	tb testing.TB,
	containerNetwork *testcontainers.DockerNetwork,
	parameters *Parameters,
) testcontainers.Container

func StartMockManagementPlaneGrpcContainer

func StartMockManagementPlaneGrpcContainer(
	ctx context.Context,
	tb testing.TB,
	containerNetwork *testcontainers.DockerNetwork,
) testcontainers.Container

func StartNginxLessContainer

func StartNginxLessContainer(
	ctx context.Context,
	tb testing.TB,
	containerNetwork *testcontainers.DockerNetwork,
	parameters *Parameters,
) testcontainers.Container

func ToPtr

func ToPtr[T any](value T) *T

func ValidateLog

func ValidateLog(t *testing.T, expectedLog string, logBuf *bytes.Buffer)

ValidateLog checks if the expected log message is present in the provided log buffer. If the expected log message is not found, it reports an error to the testing framework.

Parameters:

  • t (*testing.T): The testing object used to report errors.
  • expectedLog (string): The expected log message to validate against the log buffer. If empty, no validation is performed.
  • logBuf (*bytes.Buffer): The log buffer that contains the actual log messages.

Behavior: - If the expected log message is not an empty string:

  • The function checks whether the log buffer contains the expected log message.
  • If the log message is missing, an error is reported using t.Errorf.

Usage: - Use this function within test cases to validate that a specific log message was produced.

Example:

var logBuffer bytes.Buffer
logBuffer.WriteString("App started successfully")
ValidateLog(t, "App started successfully", &logBuffer)

func WriteCertFiles

func WriteCertFiles(t *testing.T, location string, cert Cert) string

Types

type Cert

type Cert struct {
	Name     string
	Type     string
	Contents []byte
}

type Parameters

type Parameters struct {
	NginxConfigPath      string
	NginxAgentConfigPath string
	LogMessage           string
}

Jump to

Keyboard shortcuts

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