test_utils

package
v0.0.0-...-824a282 Latest Latest
Warning

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

Go to latest
Published: May 1, 2026 License: Apache-2.0 Imports: 34 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FileOwner

func FileOwner(t *testing.T, path string) (uid, gid uint32)

FileOwner returns the UID and GID of the file at path.

func GenerateJWK

func GenerateJWK() (jwk.Key, jwk.Set, string, error)

GenerateJWK generates a JWK private key and a corresponding JWKS public key, and the string representation of the public key

func GenerateJWKS

func GenerateJWKS() (string, error)

func GetTmpStoragePrefixDir

func GetTmpStoragePrefixDir(t *testing.T) string

Helper function for other tests who call server_utils.GetOriginExports() internally. This function gets a temp dir for export StoragePrefixes, whose existence is validated by server_utils.GetOriginExports(). The directory is created with 0777 permissions so the XRootD daemon user (which is "others" relative to the test process owner) has the read, write, and execute permissions needed for all origin capabilities.

func GetUniqueAvailablePorts

func GetUniqueAvailablePorts(count int) ([]int, error)

getUniqueAvailablePorts returns `count` unique, available ports. **WARNING**: There is a small race condition between getting the list of available ports and actually binding to them in whatever service uses these values. Be warned they may (but are hopefully unlikely to) disappear before you can use them!

func InitClient

func InitClient(t *testing.T, initCfg map[param.Param]any)

Initialize the client for a unit test

Will set the configuration to a temporary directory (to avoid pulling in global configuration) and set some arbitrary param configurations. The initCfg map uses typed param constants as keys; each value is set via the param's typed Set method where possible (StringParam, BoolParam, etc.), falling back to param.Set for OpaqueParam or unknown types. Panics from type mismatches are caught and reported as test failures.

func MockFederationRoot

func MockFederationRoot(t *testing.T, fInfo *pelican_url.FederationDiscovery, kSet *jwk.Set)

Create a mock federation root that can respond to requests for metadata and federation keys

func MockIssuer

func MockIssuer(t *testing.T, kSet *jwk.Set) string

Create a mock issuer that responds to request for /.well-known/openid-configuration and /.well-known/issuer.jwks

func RegistryMockup

func RegistryMockup(t *testing.T, prefix string) *httptest.Server

For these tests, we only need to lookup key locations. Create a dummy registry that only returns the jwks_uri location for the given key. Once a server is instantiated, it will only return locations for the provided prefix. To change prefixes, create a new registry mockup.

func SetupGlobalTestLogging

func SetupGlobalTestLogging() func()

SetupGlobalTestLogging silences logrus output for an entire package's tests (for use in TestMain). It preserves existing logger settings and restores them when the returned cleanup is called.

func SetupTestLogging

func SetupTestLogging(t *testing.T) func()

SetupTestLogging configures logrus to write to the test's log buffer. This should be called at the beginning of tests to ensure clean output. Returns a cleanup function that should be called with defer.

func SkipUnlessPrivileged

func SkipUnlessPrivileged(t *testing.T)

SkipUnlessPrivileged skips the test if the process lacks CAP_SETUID or CAP_SETGID in its effective capability set.

func SkipUnlessTestUsers

func SkipUnlessTestUsers(t *testing.T, usernames ...string)

SkipUnlessTestUsers skips the test if any of the given usernames cannot be resolved via the system user database.

func TestContext

func TestContext(ictx context.Context, t *testing.T) (ctx context.Context, cancel context.CancelFunc, egrp *errgroup.Group)

func WriteBigBuffer

func WriteBigBuffer(t *testing.T, fp io.WriteCloser, sizeMB int) (size int)

Writes a file at least the specified size in MB

Types

type TestLogHook

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

TestLogHook forwards log entries to the test log buffer so they appear under the test's output (visible with -v or on failure) and never hit stdout/stderr directly.

func NewTestLogHook

func NewTestLogHook(t *testing.T) *TestLogHook

NewTestLogHook creates a new TestLogHook that writes to testing.T's log buffer

func (*TestLogHook) Fire

func (hook *TestLogHook) Fire(entry *logrus.Entry) error

Fire is called on every log entry

func (*TestLogHook) Levels

func (hook *TestLogHook) Levels() []logrus.Level

Levels defines which log levels this hook applies to

Jump to

Keyboard shortcuts

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