testutil

package
v2.9.4 Latest Latest
Warning

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

Go to latest
Published: Apr 8, 2024 License: Apache-2.0 Imports: 46 Imported by: 0

Documentation

Index

Constants

View Source
const DefaultTransformImage = "ubuntu:20.04"
View Source
const DexMockConnectorEmail = `kilgore@kilgore.trout`

DexMockConnectorEmail is the identity returned for all requests to the mock Dex connector (see https://github.com/dexidp/dex/blob/c113df2730052e20881dd68561289f8ae121300b/connector/mock/connectortest.go#L21) Kilgore Trout is a recurring character of Kurt Vonnegut's

View Source
const (
	// RootToken is the hard-coded admin token used on all activated test clusters
	RootToken = "iamroot"
)

Variables

This section is empty.

Functions

func ActivateAuthClient

func ActivateAuthClient(tb testing.TB, c *client.APIClient, port ...string)

ActivateAuthClient activates the auth service in the test cluster, if it isn't already enabled

func ActivateEnterprise

func ActivateEnterprise(t testing.TB, c *client.APIClient, port ...string)

ActivateEnterprise activates enterprise in Pachyderm (if it's not on already.)

func ActivateLicense

func ActivateLicense(t testing.TB, c *client.APIClient, port string, expireTime ...time.Time)

func AuthenticateClient

func AuthenticateClient(tb testing.TB, c *client.APIClient, subject string) *client.APIClient

creates a new authenticated pach client, without re-activating

func AuthenticatedPachClient

func AuthenticatedPachClient(tb testing.TB, c *client.APIClient, subject string, port ...string) *client.APIClient

func BashCmd

func BashCmd(cmd string, subs ...string) *exec.Cmd

BashCmd is a convenience function that: 1. Performs a Go template substitution on 'cmd' using the strings in 'subs' 2. Returns a command that runs the result string from 1 as a Bash script

func BuildBindings

func BuildBindings(s ...string) *auth.RoleBinding

func BuildClusterBindings

func BuildClusterBindings(s ...string) *auth.RoleBinding

func Command

func Command(name string, args ...string) *exec.Cmd

Command is a convenience function that replaces exec.Command. It's both shorter and it uses the current process's stderr as output for the command, which makes debugging failures much easier (i.e. you get an error message rather than "exit status 1")

func CommitCnt

func CommitCnt(t *testing.T, c *client.APIClient, repo *pfs.Repo) int

CommitCnt uses 'c' to get the number of commits made to the repo 'repo'

func ConfigureOIDCProvider

func ConfigureOIDCProvider(t *testing.T, c *client.APIClient, unitTest bool) error

ConfigureOIDCProvider configures the identity service and the auth service to use a mock connector.

func CreateEphemeralDB

func CreateEphemeralDB(t testing.TB, db *pachsql.DB, dbName string)

CreateEphemeralDB creates a new database using db with a lifetime scoped to the test t.

func DebugFiles

func DebugFiles(t testing.TB, projectName, repoName string) (map[string]*globlib.Glob, []string)

func DeletePipelineRC

func DeletePipelineRC(t testing.TB, pipeline, namespace string)

DeletePipelineRC deletes the RC belonging to the pipeline 'pipeline'. This can be used to test PPS's robustness

func DexHost

func DexHost(c *client.APIClient) string

DexHost returns the address to access the identity server during tests

func DoOAuthExchange

func DoOAuthExchange(t testing.TB, pachClient, enterpriseClient *client.APIClient, loginURL string)

DoOAuthExchange does the OAuth dance to log in to the mock provider, given a login URL

func DoOAuthExchangeOnce added in v2.8.0

func DoOAuthExchangeOnce(t testing.TB, pachClient, enterpriseClient *client.APIClient, loginURL string) error

func GenerateEphemeralDBName

func GenerateEphemeralDBName(t testing.TB) string

GenerateEphemeralDBName generates a random name suitable for use as a Postgres identifier

func GetKubeClient

func GetKubeClient(t testing.TB) *kube.Clientset

GetKubeClient connects to the Kubernetes API server either from inside the cluster or from a test binary running on a machine with kubectl (it will connect to the same cluster as kubectl)

func GetOIDCTokenForTrustedApp

func GetOIDCTokenForTrustedApp(t testing.TB, testClient *client.APIClient, unitTest bool) string

func GetProjectRoleBinding

func GetProjectRoleBinding(t *testing.T, c *client.APIClient, project string) *auth.RoleBinding

func GetRepoRoleBinding

func GetRepoRoleBinding(t *testing.T, c *client.APIClient, projectName, repoName string) *auth.RoleBinding

func GetTestEnterpriseCode

func GetTestEnterpriseCode(t testing.TB) string

GetTestEnterpriseCode Pulls the enterprise code out of the env var stored in CI

func Group

func Group(group string) string

func Listen added in v2.8.0

func Listen(t testing.TB) net.Listener

Listen creates a new net.Listener on localhost and ensures the listener is closed when the test exits

func LogHttpResponse

func LogHttpResponse(t testing.TB, response *http.Response, msg string)

func NewLoggingHTTPClient added in v2.7.0

func NewLoggingHTTPClient(t testing.TB) *http.Client

func OIDCOIDCConfig

func OIDCOIDCConfig(host, issuerPort, redirectPort string, local bool) *auth.OIDCConfig

OIDCOIDCConfig is an auth config which can be used to connect to the identity service in tests

func OpenDB

func OpenDB(t testing.TB, opts ...dbutil.Option) *pachsql.DB

OpenDB connects to a database using opts and returns it. The database will be closed at the end of the test.

func OpenDBURL

func OpenDBURL(t testing.TB, u pachsql.URL, password string) *pachsql.DB

OpenDBURL connects to a database using u and returns it. The database will be closed at the end of the test.

func PachctlBashCmd

func PachctlBashCmd(t *testing.T, c *client.APIClient, scriptTemplate string, subs ...string) *exec.Cmd

func PachctlBashCmdCtx added in v2.8.0

func PachctlBashCmdCtx(ctx context.Context, t *testing.T, c *client.APIClient, scriptTemplate string, subs ...string) *exec.Cmd

func PipelineNames

func PipelineNames(t *testing.T, c *client.APIClient, project string) []string

PipelineNames returns the names of all pipelines that 'c' gets from ListPipeline in the specified project.

func Pl

func Pl(projectName, pipelineName string) string

func RandomRobot

func RandomRobot(t *testing.T, c *client.APIClient, name string) (string, *client.APIClient)

func RepoInfoToName

func RepoInfoToName(repoInfo interface{}) interface{}

func RewriteRedirect

func RewriteRedirect(t testing.TB, resp *http.Response, host string) string

RewriteRedirect rewrites the Location header to point to the returned path at `host`

func RewriteURL

func RewriteURL(t testing.TB, urlStr, host string) string

RewriteURL rewrites the host and scheme in urlStr

func Robot

func Robot(robot string) string

func TSProtoOrDie

func TSProtoOrDie(t testing.TB, ts time.Time) *timestamppb.Timestamp

func UnauthenticatedPachClient

func UnauthenticatedPachClient(tb testing.TB, c *client.APIClient) *client.APIClient

GetUnauthenticatedPachClient returns a copy of the testing pach client with no auth token

func UniqueString

func UniqueString(prefix string) string

UniqueString adds a UUID suffix to 'prefix'. This helps avoid name conflicts between tests that share the same Pachyderm cluster

func User

func User(email string) string

Types

type Cmd

type Cmd struct {
	*exec.Cmd
	// contains filtered or unexported fields
}

func (*Cmd) Run

func (cmd *Cmd) Run() error

func (Cmd) Stderr

func (cmd Cmd) Stderr() string

Stderr reads all of the command’s error output. It panics in case of an error.

func (Cmd) Stdout

func (cmd Cmd) Stdout() string

Stdout reads all of the command’s standard output. It panics in case of an error.

type Pachctl

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

func NewPachctl

func NewPachctl(ctx context.Context, c *client.APIClient, configPath string) (*Pachctl, error)

NewPachctl returns a new Pachctl object configured with the given client information, with the configuration stored in configPath.

func (Pachctl) Close

func (p Pachctl) Close() error

Close cleans up the pachctl config file. It does not delete its parent directory.

func (Pachctl) Command

func (p Pachctl) Command(ctx context.Context, script string) (Cmd, error)

Command provides a Cmd to execute script with Bash. If context is cancelled then the command will be terminated.

func (*Pachctl) CommandTemplate

func (p *Pachctl) CommandTemplate(ctx context.Context, scriptTemplate string, data any) (Cmd, error)

Command provides a Cmd to execute script with Bash. Script is interpreted as a Go template and provided with data. If context is cancelled then the command will be terminated.

func (Pachctl) RunCommand added in v2.9.0

func (p Pachctl) RunCommand(ctx context.Context, command string) (string, error)

RunCommand runs command in sh (rather than bash), returning the combined stdout & stderr.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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