Documentation
¶
Index ¶
- Constants
- func ChownToDaemon(t testing.TB, paths ...string)
- func FailLookupsOf(t *testing.T, host string)
- func FileOwner(t *testing.T, path string) (uid, gid uint32)
- func GenerateJWK() (jwk.Key, jwk.Set, string, error)
- func GenerateJWKS() (string, error)
- func GetPelicanBinary(t testing.TB) string
- func GetPelicanServerBinary(t testing.TB) string
- func GetSampleMetadataServerBinary(t testing.TB) string
- func GetTmpStoragePrefixDir(t *testing.T) string
- func GetUniqueAvailablePorts(count int) ([]int, error)
- func InitClient(t *testing.T, initCfg map[param.Param]any)
- func MockFederationRoot(t *testing.T, fInfo *pelican_url.FederationDiscovery, kSet *jwk.Set)
- func MockIssuer(t *testing.T, kSet *jwk.Set) string
- func RegistryMockup(t *testing.T, prefix string) *httptest.Server
- func RemoveTestBinaries()
- func SetupGlobalTestLogging() func()
- func SetupTestLogging(t testing.TB) func()
- func SkipIfNoMinio(t *testing.T)
- func SkipIfShort(t testing.TB, reason string)
- func SkipUnlessPrivileged(t *testing.T)
- func SkipUnlessTestUsers(t *testing.T, usernames ...string)
- func StartMinio(t *testing.T, bucket string) (endpoint, accessKey, secretKey string)
- func TestContext(ictx context.Context, t testing.TB) (ctx context.Context, cancel context.CancelFunc, egrp *errgroup.Group)
- func WriteBigBuffer(t *testing.T, fp io.WriteCloser, sizeMB int) (size int)
- func WriteJWKSFile(t testing.TB, dir, name string, keys ...jwk.Key) string
- type StubFederation
- type StubFederationOptions
- type TestLogHook
Constants ¶
const UnresolvableHost = "noserverexists.invalid"
UnresolvableHost is a name under the reserved .invalid TLD (RFC 6761), which can never resolve.
Variables ¶
This section is empty.
Functions ¶
func ChownToDaemon ¶
ChownToDaemon changes ownership of the given paths to the XRootD daemon user. When not running as root this is a no-op (the daemon user is the current user).
func FailLookupsOf ¶
FailLookupsOf makes connections through the global transport (config.GetTransport and the clients built on it) to host fail the way a lookup of a nonexistent name does -- "dial tcp: lookup <host>: no such host" -- without asking a resolver. A real lookup depends on the network and can take longer than a test is prepared to wait. Connections to any other host are dialed normally. The real dialer is restored when the test ends.
func GenerateJWK ¶
GenerateJWK generates a JWK private key and a corresponding JWKS public key, and the string representation of the public key
func GenerateJWKS ¶
func GetPelicanBinary ¶
GetPelicanBinary returns the path to a `pelican` binary. If $TEST_PELICAN_BINARY is set, it must be the absolute path to an existing binary, which is used as is.
func GetPelicanServerBinary ¶
GetPelicanServerBinary returns the path to a `pelican-server` binary. If $TEST_PELICAN_SERVER_BINARY is set, it must be the absolute path to an existing binary, which is used as is.
func GetSampleMetadataServerBinary ¶
GetSampleMetadataServerBinary returns the path to a `sample_metadata_server` binary. If $TEST_PELICAN_SAMPLE_METADATA_SERVER_BINARY is set, it must be the absolute path to an existing binary, which is used as is.
func GetTmpStoragePrefixDir ¶
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 ¶
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 ¶
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 ¶
Create a mock issuer that responds to request for /.well-known/openid-configuration and /.well-known/issuer.jwks
func RegistryMockup ¶
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 RemoveTestBinaries ¶
func RemoveTestBinaries()
RemoveTestBinaries removes the binaries built by this test process. Call it from TestMain after m.Run returns.
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 ¶
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 SkipIfNoMinio ¶
SkipIfNoMinio skips the test if the minio binary is not available on PATH, or fails it if requireMinioEnv is set.
func SkipIfShort ¶
SkipIfShort skips the calling test when "go test -short" is in effect.
Reserve this for tests that measurement shows are not worth their time on every run, or that need something esoteric (HTCondor, rclone, minio, root). AGENTS.md describes the criteria. Call it as the first statement of the test, before any setup starts.
func SkipUnlessPrivileged ¶
SkipUnlessPrivileged skips the test if the process lacks CAP_SETUID or CAP_SETGID in its effective capability set.
func SkipUnlessTestUsers ¶
SkipUnlessTestUsers skips the test if any of the given usernames cannot be resolved via the system user database.
func StartMinio ¶
StartMinio launches a minio server bound to 127.0.0.1:0 (OS-assigned port), parses the actual listening port from minio's log output, and returns the endpoint URL, access key, and secret key. The server is killed when the test completes.
This avoids the TOCTOU race inherent in picking a free port first and then passing it to minio.
func TestContext ¶
func WriteBigBuffer ¶
Writes a file at least the specified size in MB
Types ¶
type StubFederation ¶
type StubFederation struct {
// URL is the federation's discovery URL, which is also where its
// director and object server answer.
URL string
// CAFile is the CA that signed the server's certificate.
CAFile string
// DirectorQueries counts the questions put to the director.
DirectorQueries atomic.Int64
// contains filtered or unexported fields
}
StubFederation is one TLS server playing every federation role a client transfer touches: the discovery document, the director, and the object server the director redirects to. Every object under the namespace /test exists and holds the same contents.
It is for exercising the client against a federation without starting one. MockFederationRoot covers discovery alone and turns certificate verification off to do it; this covers the director and the object server as well, and is verified the way a client verifies a production federation.
func NewStubFederation ¶
func NewStubFederation(t *testing.T, opts StubFederationOptions) *StubFederation
NewStubFederation starts a stub federation for the duration of t.
func (*StubFederation) InitClient ¶
InitClient initializes the client against the stub, discovering through it and trusting the CA that signed its certificate. extra adds the test's own parameters.
type StubFederationOptions ¶
type StubFederationOptions struct {
// Contents is what every object holds.
Contents string
// RequireToken makes the director say the namespace wants a credential.
RequireToken bool
// OnFetch, if set, is called on each object fetch with the object's
// federation path, before anything is written. A non-zero return fails
// the fetch with that status; zero lets it succeed. Fetches run
// concurrently, so it must be safe for concurrent use.
OnFetch func(objectPath string) int
}
StubFederationOptions configures a StubFederation.
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.TB) *TestLogHook
NewTestLogHook creates a new TestLogHook that writes to testing.TB'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