Documentation
¶
Overview ¶
Package nktest provides a nakama test runner.
Index ¶
- Variables
- func GenDockerToken(ctx context.Context, h Handler, id string) (string, error)
- func GetImageTags(ctx context.Context, h Handler, id string) ([]string, error)
- func GoEnvVar(goPath, name string) (string, error)
- func IsSubDir(a, b string) error
- func LocalAddr(l net.Listener) string
- func NewPrefixedWriter(w io.Writer, prefix string) io.Writer
- func ParsePortMapping(s string) (pntypes.PortMapping, error)
- func PodmanBuildMounts(mounts ...string) ([]pspec.Mount, error)
- func PodmanContext(ctx context.Context) (context.Context, context.Context, error)
- func PodmanCreatePod(ctx, conn context.Context, h Handler, ids ...string) (string, error)
- func PodmanFollowLogs(ctx context.Context, h Handler, id string) error
- func PodmanGetAddr(ctx context.Context, h Handler, id, svc string) (string, string, error)
- func PodmanPullImages(ctx, conn context.Context, h Handler, ids ...string) error
- func PodmanRun(ctx, conn context.Context, h Handler, id string, env map[string]string, ...) (string, error)
- func PodmanServiceWait(ctx context.Context, h Handler, id, svc string, f func(string, string) error) error
- func PodmanWait(ctx context.Context, h Handler, id string) error
- func QualifiedId(id string) string
- func ReadCachedFile(name string, ttl time.Duration) ([]byte, error)
- func ShortId(id string) string
- type BuildConfig
- type BuildConfigOption
- func WithDefaultGoEnv() BuildConfigOption
- func WithDefaultGoVolumes() BuildConfigOption
- func WithEnv(env map[string]string) BuildConfigOption
- func WithGoEnv(env ...string) BuildConfigOption
- func WithGoEnvVolumes(volumes ...EnvVolumeInfo) BuildConfigOption
- func WithMounts(mounts ...string) BuildConfigOption
- func WithOut(out string) BuildConfigOption
- type EnvVolumeInfo
- type Handler
- type Logger
- type Option
- func WithAlwaysPull(alwaysPull bool) Option
- func WithBackoffMaxElapsedTime(backoffMaxElapsedTime time.Duration) Option
- func WithBackoffMaxInterval(backoffMaxInterval time.Duration) Option
- func WithBuildConfig(modulePath string, opts ...BuildConfigOption) Option
- func WithConfigFilename(configFilename string) Option
- func WithConfigTemplate(configTemplate string) Option
- func WithContainerRemoveDelay(containerRemoveDelay time.Duration) Option
- func WithDir(dir string) Option
- func WithDockerAuthName(dockerAuthName string) Option
- func WithDockerAuthScope(dockerAuthScope string) Option
- func WithDockerRegistryURL(dockerRegistryURL string) Option
- func WithDockerTokenURL(dockerTokenURL string) Option
- func WithHostPortMap() Option
- func WithHttpClient(httpClient *http.Client) Option
- func WithNakamaImageId(nakamaImageId string) Option
- func WithNakamaVersion(nakamaVersion string) Option
- func WithName(name string) Option
- func WithNetworkRemoveDelay(networkRemoveDelay time.Duration) Option
- func WithPluginbuilderImageId(pluginbuilderImageId string) Option
- func WithPortMap(id, svc string, port uint16) Option
- func WithPostgresImageId(postgresImageId string) Option
- func WithPostgresVersion(postgresVersion string) Option
- func WithStderr(stderr io.Writer) Option
- func WithStdout(stdout io.Writer) Option
- func WithVersionCacheTTL(versionCacheTTL time.Duration) Option
- func WithVolumeDir(volumeDir string) Option
- type PrefixedWriter
- type Proxy
- type ProxyOption
- type Runner
- func (t *Runner) AlwaysPull() bool
- func (t *Runner) Backoff(ctx context.Context, f func() error) error
- func (t *Runner) BuildModule(ctx, conn context.Context, bc *BuildConfig) error
- func (t *Runner) BuildModules(ctx, conn context.Context) error
- func (t *Runner) ContainerRemoveDelay() time.Duration
- func (t *Runner) DockerAuthName() string
- func (t *Runner) DockerAuthScope(id string) string
- func (t *Runner) DockerRegistryURL() string
- func (t *Runner) DockerTokenURL() string
- func (t *Runner) Errf(s string, v ...interface{})
- func (t *Runner) GetNakamaVersion(ctx context.Context) error
- func (t *Runner) GrpcLocal() string
- func (t *Runner) GrpcRemote() string
- func (t *Runner) HostPortMap(id, svc string, containerPort, hostPort uint16) uint16
- func (t *Runner) HttpClient() *http.Client
- func (t *Runner) HttpLocal() string
- func (t *Runner) HttpRemote() string
- func (t *Runner) Init() error
- func (t *Runner) Logf(s string, v ...interface{})
- func (t *Runner) Name() string
- func (t *Runner) NetworkRemoveDelay() time.Duration
- func (t *Runner) PodId() string
- func (t *Runner) PostgresLocal() string
- func (t *Runner) PostgresRemote() string
- func (t *Runner) Run(ctx context.Context) error
- func (t *Runner) RunNakama(ctx, conn context.Context) error
- func (t *Runner) RunPostgres(ctx, conn context.Context) error
- func (t *Runner) RunProxy(ctx context.Context, opts ...ProxyOption) (string, error)
- func (t *Runner) ServerKey() string
- func (t *Runner) Stderr(prefix string) io.Writer
- func (t *Runner) Stdout(prefix string) io.Writer
- func (t *Runner) Transport(transport http.RoundTripper) http.RoundTripper
- func (t *Runner) Write(buf []byte) (int, error)
- type Transport
Constants ¶
This section is empty.
Variables ¶
var DefaultInPrefix = "<- "
DefaultInPrefix is the default in prefix.
var DefaultOutPrefix = "-> "
DefaultOutPrefix is the default out prefix.
var DefaultProxyReadSize = 10 * 1024 * 1024
DefaultProxyReadSize is the default websocket proxy read size.
var DefaultProxyWriteSize = 10 * 1024 * 1024
DefaultProxyWriteSize is the default websocket proxy write size.
var DefaultTransport = &http.Transport{ DisableCompression: true, }
DefaultTransport is the default http transport used by the log transport.
Functions ¶
func GenDockerToken ¶
GenDockerToken generates a docker auth token for the repo id.
func GetImageTags ¶
GetImageTags gets the docker registry tags for a image id.
func NewPrefixedWriter ¶
NewPrefixedWriter creates a new prefixed writer.
func ParsePortMapping ¶ added in v0.3.4
func ParsePortMapping(s string) (pntypes.PortMapping, error)
ParsePortMapping creates a port mapping from s.
func PodmanBuildMounts ¶
PodmanBuildMounts creates mount specs for a container.
func PodmanContext ¶
PodmanContext creates a podman client. If no client exists in the current context, then a new context is created and merged with the parent context, otherwise ctx is passed through unchanged.
func PodmanCreatePod ¶
PodmanCreatePod creates a pod network.
func PodmanFollowLogs ¶
PodmanFollowLogs follows the logs for a container.
func PodmanGetAddr ¶
PodmanGetAddr inspects id and returns the local and remote addresses.
func PodmanPullImages ¶
PodmanPullImages grabs image ids when not present on the host or when the handler's always pull is true.
func PodmanRun ¶
func PodmanRun(ctx, conn context.Context, h Handler, id string, env map[string]string, mounts []string, entrypoint ...string) (string, error)
PodmanRun runs a container image id.
func PodmanServiceWait ¶
func PodmanServiceWait(ctx context.Context, h Handler, id, svc string, f func(string, string) error) error
PodmanServiceWait waits for a container service to be available.
func PodmanWait ¶
PodmanWait waits until a container has stopped.
func QualifiedId ¶
QualifiedId fully qualifies a container image id.
func ReadCachedFile ¶
ReadCachedFile reads a cached file from disk, returns error if the file name on disk is past the ttl.
Types ¶
type BuildConfig ¶
type BuildConfig struct {
// contains filtered or unexported fields
}
BuildConfig is a nakama module build config.
type BuildConfigOption ¶
type BuildConfigOption func(*BuildConfig) error
BuildConfigOption is nakama module build config option.
func WithDefaultGoEnv ¶
func WithDefaultGoEnv() BuildConfigOption
WithDefaultGoEnv is a nakama module build config option to copy default host environment variables for Go.
Copies:
GONOPROXY GONOSUMDB GOPRIVATE GOPROXY GOSUMDB
func WithDefaultGoVolumes ¶
func WithDefaultGoVolumes() BuildConfigOption
WithGoVolumes is a nakama module build config option to mount the host's Go directories (GOCACHE, GOMODCACHE, and GOPATH) to the plugin builder container. Significantly speeds up build times.
func WithEnv ¶
func WithEnv(env map[string]string) BuildConfigOption
WithEnv is a nakama module build config option to set additional env variables used during builds.
func WithGoEnv ¶
func WithGoEnv(env ...string) BuildConfigOption
WithGoEnv is a nakama module build config option to copy the host Go environment variables.
func WithGoEnvVolumes ¶
func WithGoEnvVolumes(volumes ...EnvVolumeInfo) BuildConfigOption
WithGoVolumes is a nakama module build config option to mount the host's Go directories (ie, the Go environment's GOCACHE, GOMODCACHE, and GOPATH locations) to the plugin builder container. Significantly speeds up build times.
Note: use WithDefaultGoVolumes (see below).
func WithMounts ¶
func WithMounts(mounts ...string) BuildConfigOption
WithMounts is a nakama module build config option to set additional mounts used during builds.
func WithOut ¶
func WithOut(out string) BuildConfigOption
WithOut is a nakama module build config option to set the out name. When not specified, the name will be derived from the directory name of the module.
type EnvVolumeInfo ¶
EnvVolumeInfo holds information about an environment variable derived volume.
func NewEnvVolume ¶
func NewEnvVolume(key, target, sub string) EnvVolumeInfo
NewEnvVolume creates a new environment volume.
type Handler ¶
type Handler interface {
Name() string
HttpClient() *http.Client
DockerAuthName() string
DockerAuthScope(string) string
DockerRegistryURL() string
DockerTokenURL() string
AlwaysPull() bool
PodId() string
HostPortMap(string, string, uint16, uint16) uint16
Stdout(string) io.Writer
Stderr(string) io.Writer
Logf(string, ...interface{})
Errf(string, ...interface{})
Backoff(context.Context, func() error) error
ContainerRemoveDelay() time.Duration
NetworkRemoveDelay() time.Duration
}
Handler is a handler.
type Logger ¶
type Logger interface {
io.Writer
Logf(string, ...interface{})
Errf(string, ...interface{})
Stdout(string) io.Writer
Stderr(string) io.Writer
Transport(http.RoundTripper) http.RoundTripper
}
Logger is the interface for a logger/writer.
func TruncatedLogger ¶
func TruncatedLogger() Logger
TruncatedLogger creates a truncating logger/writer.
type Option ¶
type Option func(*Runner)
Option is a nakama test runner option.
func WithAlwaysPull ¶
WithAlwaysPull is a nakama test runner option to set the always pull flag. When true, causes container images to be pulled regardless of if they are available on the host or not.
func WithBackoffMaxElapsedTime ¶
WithBackoffMaxElapsedTime is a nakama test runner option to set the backoff max elapsed time for waiting for services (ie, postgres, nakama) to start/become available.
func WithBackoffMaxInterval ¶
WithBackoffMaxInterval is a nakama test runner option to set the backoff max interval for waiting for services (ie, postres, nakama) to start/become available.
func WithBuildConfig ¶
func WithBuildConfig(modulePath string, opts ...BuildConfigOption) Option
WithBuildConfig is a nakama test runner option to add a module path, and extra options to the build config.
func WithConfigFilename ¶
WithConfigFilename is a nakama test runner option to set the config filename.
func WithConfigTemplate ¶
WithConfigTemplate is a nakama test runner option to set the config template.
func WithContainerRemoveDelay ¶
WithContainerRemoveDelay is a nakama test runner option to set the container remove delay.
func WithDockerAuthName ¶
WithDockerAuthName is a nakama test runner option to set the docker token auth name used when generating auth tokens for the docker registry.
func WithDockerAuthScope ¶
WithDockerAuthScope is a nakama test runner option to set a docker token auth scope mask. Must include "%s" to interpolate the image id.
func WithDockerRegistryURL ¶
WithDockerRegistryURL is a nakama test runner option to set the docker registry url used for retrieving images.
func WithDockerTokenURL ¶
WithDockerTokenURL is a nakama test runner option to set the docker token url, used for generating auth tokens when pulling images.
func WithHostPortMap ¶ added in v0.3.4
func WithHostPortMap() Option
WithHostPortMap is a nakama test runner option to add host port mapping for the postgres and nakama services (5432/tcp, 7349/tcp, 7350/tcp, 7351/tcp).
func WithHttpClient ¶
WithHttpClient is a nakama test runner option to set a http client used. Used for generating auth tokens for image repositories.
func WithNakamaImageId ¶
WithNakamaImageId is a nakama test runner option to set the nakama image id.
func WithNakamaVersion ¶
WithNakamaVersion is a nakama test runner option to set the nakama image tag.
func WithNetworkRemoveDelay ¶
WithNetworkRemoveDelay is a nakama test runner option to set the container network remove delay.
func WithPluginbuilderImageId ¶
WithPluginbuilderImageId is a nakama test runner option to set the pluginbuilder image id.
func WithPortMap ¶ added in v0.3.4
WithPortMap is a nakama test runner option to add a host port mapping for a service.
func WithPostgresImageId ¶
WithPostgresImageId is a nakama test runner option to set the postgres image id.
func WithPostgresVersion ¶
WithPostgresVersion is a nakama test runner option to set the postgres image tag.
func WithStderr ¶
WithStderr is a nakama test runner option to set the stderr.
func WithStdout ¶
WithStdout is a nakama test runner option to set the stdout.
func WithVersionCacheTTL ¶
WithVersionCacheTTL is a nakama test runner option to set the version cache TTL.
func WithVolumeDir ¶
WithVolumeDir is a nakama test runner option to set the volume dir, where nakama and postgres data/configs are written. Default is <project root>/.cache. Must be a sub dir of the project root.
type PrefixedWriter ¶
type PrefixedWriter struct {
// contains filtered or unexported fields
}
PrefixedWriter is a prefixed writer.
type Proxy ¶
type Proxy struct {
// contains filtered or unexported fields
}
Proxy is a http and websocket logging proxy.
func NewProxy ¶
func NewProxy(opts ...ProxyOption) *Proxy
NewProxy creates a new http and websocket logging proxy.
func (Proxy) InternalError ¶ added in v0.3.0
func (p Proxy) InternalError(res http.ResponseWriter, s string, v ...interface{})
InternalError handles internal errors.
type ProxyOption ¶
type ProxyOption func(*Proxy)
ProxyOption is a proxy option.
func WithAddr ¶
func WithAddr(addr string) ProxyOption
WithAddr is a proxy option to set the listen address.
func WithDialer ¶
func WithDialer(dialer websocket.Dialer) ProxyOption
WithDialer is a proxy option to set the websocket dialer.
func WithLogf ¶
func WithLogf(f func(string, ...interface{})) ProxyOption
WithLogf is a proxy option to set a wrapped logger. Useful with *testing.T.
func WithLogger ¶
func WithLogger(logger Logger) ProxyOption
WithLogger is a proxy option to set logger.
func WithUpgrader ¶
func WithUpgrader(upgrader websocket.Upgrader) ProxyOption
WithUpgrader is a proxy option to set the websocket upgrader.
func WithWsPath ¶
func WithWsPath(wsPath string) ProxyOption
WithWsPath is a proxy option to set the websocket remote path.
type Runner ¶
type Runner struct {
// contains filtered or unexported fields
}
Runner is a nakama test runner.
func (*Runner) AlwaysPull ¶
AlwaysPull returns whether or not to always pull an image.
func (*Runner) Backoff ¶
Backoff executes f until backoff conditions are met or until f returns nil.
func (*Runner) BuildModule ¶
func (t *Runner) BuildModule(ctx, conn context.Context, bc *BuildConfig) error
BuildModule builds a nakama plugin module.
func (*Runner) BuildModules ¶
BuildModules builds the nakama modules.
func (*Runner) ContainerRemoveDelay ¶
ContainerRemoveDelay returns the container remove delay.
func (*Runner) DockerAuthName ¶
DockerAuthName returns the docker token auth name.
func (*Runner) DockerAuthScope ¶
DockerAuthScope returns the docker token auth scope for a image id.
func (*Runner) DockerRegistryURL ¶
DockerRegistryURL returns the docker registry url.
func (*Runner) DockerTokenURL ¶
DockerTokenURL returns the docker token url.
func (*Runner) GetNakamaVersion ¶
GetNakamaVersion loads and caches the nakama version.
func (*Runner) GrpcRemote ¶
GrpcRemote returns the grpc remote address.
func (*Runner) HostPortMap ¶ added in v0.3.4
HostPortMap returns the host port for the provided container id and service.
func (*Runner) HttpClient ¶
HttpClient returns the http client for the test runner.
func (*Runner) HttpRemote ¶
HttpRemote returns the http remote address.
func (*Runner) Init ¶
Init initializes the environment for running nakama-pluginbuilder and nakama images.
func (*Runner) NetworkRemoveDelay ¶
NetworkRemoveDelay returns the network remove delay.
func (*Runner) PostgresLocal ¶
PostgresLocal returns the postgres local address.
func (*Runner) PostgresRemote ¶
PostgresRemote returns the postgres remote address.
func (*Runner) Run ¶
Run handles building the nakama plugin and starting the postgres and nakama server containers.
func (*Runner) RunPostgres ¶
RunPostgres runs the postgres server.
func (*Runner) Transport ¶
func (t *Runner) Transport(transport http.RoundTripper) http.RoundTripper
Transport satisfies the logger interface.
type Transport ¶
type Transport struct {
// contains filtered or unexported fields
}
Transport is a logging transport.
func NewTransport ¶
func NewTransport(req, res io.Writer, transport http.RoundTripper) *Transport
NewTransport creates a logging transport.
func (*Transport) DisableReqBody ¶
func (t *Transport) DisableReqBody()
DisableReqBody disables logging the request body.
func (*Transport) DisableResBody ¶
func (t *Transport) DisableResBody()
DisableResBody disables logging the response body.