nktest

package module
v0.12.4 Latest Latest
Warning

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

Go to latest
Published: Jan 26, 2024 License: MIT Imports: 41 Imported by: 0

README

About

Package nktest provides a Nakama test runner that makes it easy to build and test Nakama module plugins with complex or advanced game logic using nothing but go test.

See also github.com/ascii8/nakama-go package for a web/realtime Nakama Go client.

Tests Go Report Card [![Reference](https://pkg.go.dev/badge/github.com/ascii8/nktest Releases

Overview

This package uses Podman to create "rootless" containers (specifically, docker.io/heroiclabs/nakama-pluginbuilder and docker.io/heroiclabs/nakama) to build Nakama's Go plugins and launch the necessary server components (PostgreSQL and Nakama).

Provides a stable, repeatable, and quick mechanism for launching testable end-to-end Nakama servers for game modules (Go, Lua, or Javascript).

Provides additional transport and logger types for use with Go clients to readily aid in debugging Nakama's API calls.

Quickstart

Add to package/module:

go get github.com/ascii8/nktest

From Go's TestMain, use nktest.Main to build Go modules, and to setup/teardown PostgreSQL and Nakama server containers:

import "github.com/ascii8/nktest"

// TestMain handles setting up and tearing down the postgres and nakama
// containers.
func TestMain(m *testing.M) {
	ctx := context.Background()
	ctx = nktest.WithAlwaysPullFromEnv(ctx, "PULL")
	ctx = nktest.WithHostPortMap(ctx)
	nktest.Main(ctx, m,
		nktest.WithDir("./testdata"),
		nktest.WithBuildConfig("./nksample", nktest.WithDefaultGoEnv(), nktest.WithDefaultGoVolumes()),
	)
}

Then, from within a Test* func, create a cancelable test context, and a proxy:

import "github.com/ascii8/nktest"

func TestNakamaHealthcheck(t *testing.T) {
	ctx, cancel, nk := nktest.WithCancel(context.Background(), t)
	defer cancel()
	urlstr, err := nktest.RunProxy(ctx)
	if err != nil {
		t.Fatalf("expected no error, got: %v", err)
	}
	t.Logf("proxy: %s", urlstr)
	req, err := http.NewRequestWithContext(ctx, "GET", urlstr+"/healthcheck", nil)
	if err != nil {
		t.Fatalf("expected no error, got: %v", err)
	}
	// create a client with compression disabled (makes debugging the API
	// requests/responses easier)
	cl := &http.Client{
		Transport: &http.Transport{
			DisableCompression: true,
		},
	}
	// execute the request
	res, err := cl.Do(req)
	if err != nil {
		t.Fatalf("expected no error, got: %v", err)
	}
	defer res.Body.Close()
	// check response
	if res.StatusCode != http.StatusOK {
		t.Errorf("expected %d, got: %d", http.StatusOK, res.StatusCode)
	}
	t.Logf("healthcheck status: %d", res.StatusCode)
	// display connection information
	t.Logf("grpc: %s", nk.GrpcLocal())
	t.Logf("http: %s", nk.HttpLocal())
	t.Logf("console: %s", nk.ConsoleLocal())
	t.Logf("http_key: %s", nk.HttpKey())
	t.Logf("server_key: %s", nk.ServerKey())
}

Use the WithHostPortMap() option, to publish the Postgres and Nakama server's default ports on the host, and making it easy to write Example* tests.

For more advanced testing scenarios, see the github.com/ascii8/nakama-go package for a full featured Go Nakama client.

Examples

See the Go package documentation for package level examples.

Why

While Nakama provides a number of different languages with which to build out game modules, building large-scale, complex logic for Nakama is best done using Go. For experienced (and even inexperienced!) Go developers, the go test command is simple, efficient and well understood, and works across platforms.

And, for fully automated deployments of Nakama and game modules, a large amount of quick and reliable testing is needed to ensure rapid application development, and continuous integration/deployment (CI/CD).

As such, there was clear motivation to make it easy and repeatable to test entirely from go test,

Why Podman

The first version of nktest used Docker, but builds and tests were slow as it was not possible to mount the user's Go build/mod cache directories without stomping on the local UID/GID and subsequently affecting the read/write permissions. Thus the change to Podman, which is able to run containers without root permissions, and can keep user UID/GID's on files.

Notes

macOS:

# update homebrew formulas and upgrade packages
brew update && brew upgrade

# install podman
brew install podman

# install gpgme (needed for podman's Go binding dependenices)
brew install gpgme

# if unable to do `go test -v` out of the box, re-init the podman machine
podman machine stop podman-machine-default
podman machine rm podman-machine-default
podman machine init -v $HOME:$HOME
podman machine start

# if receiving a "too many open files" error on M1 macs, try:
podman machine stop && ulimit -n unlimited && podman machine start

Documentation

Overview

Package nktest provides a Nakama test runner that makes it easy to build and test Nakama module plugins with complex, advanced game logic using nothing but "go test".

See also github.com/ascii8/nakama-go package for a web/realtime Nakama Go client.

Example
package main

import (
	"bytes"
	"context"
	"fmt"
	"io"
	"log"
	"net/http"
	"strconv"
)

func main() {
	// create context
	ctx, cancel := context.WithCancel(context.Background())
	defer cancel()
	urlstr := "http://127.0.0.1:7350/healthcheck"
	req, err := http.NewRequestWithContext(ctx, "GET", urlstr, nil)
	if err != nil {
		log.Fatal(err)
	}
	// create client and execute request
	cl := &http.Client{
		Transport: &http.Transport{
			DisableCompression: true,
		},
	}
	res, err := cl.Do(req)
	if err != nil {
		log.Fatal(err)
	}
	defer res.Body.Close()
	// check response
	if res.StatusCode != http.StatusOK {
		log.Fatalf("status %d != 200", res.StatusCode)
	}
	// read response
	buf, err := io.ReadAll(res.Body)
	if err != nil {
		log.Fatal(err)
	}
	fmt.Println("healthcheck:", strconv.Itoa(res.StatusCode), http.StatusText(res.StatusCode), string(bytes.TrimSpace(buf)))
}
Output:

healthcheck: 200 OK {}

Index

Examples

Constants

This section is empty.

Variables

View Source
var (
	DefaultPrefixOut            = "-> "
	DefaultPrefixIn             = "<- "
	DefaultAlwaysPull           = false
	DefaultUnderCI              = false
	DefaultPostgresImageId      = "docker.io/library/postgres"
	DefaultNakamaImageId        = "docker.io/heroiclabs/nakama"
	DefaultPluginbuilderImageId = "docker.io/heroiclabs/nakama-pluginbuilder"
	DefaultPostgresVersion      = "latest"
	DefaultDockerRegistryURL    = "https://registry-1.docker.io"
	DefaultDockerTokenURL       = "https://auth.docker.io/token"
	DefaultDockerAuthName       = "registry.docker.io"
	DefaultDockerAuthScope      = "repository:%s:pull"
	DefaultVersionCacheTTL      = 96 * time.Hour
	DefaultPodRemoveTimeout     = 200 * time.Millisecond
	DefaultBuildTimeout         = 5 * time.Minute
	DefaultBackoffConfig        = BackoffConfig{50 * time.Millisecond, 1 * time.Second, 30 * time.Second, 1.2}
	DefaultConfigFilename       = "config.yml"
	//go:embed config.yml.tpl
	DefaultConfigTemplate string
)

Defaults.

View Source
var ContainerEmptyValue = "--------"

ContainerEmptyValue is the container empty value.

View Source
var ContainerIdFieldName = "container_id"

ContainerIdFieldName is the container field name used for logs.

View Source
var DefaultProxyReadSize = 10 * 1024 * 1024

DefaultProxyReadSize is the default websocket proxy read size.

View Source
var DefaultProxyWriteSize = 10 * 1024 * 1024

DefaultProxyWriteSize is the default websocket proxy write size.

View Source
var DefaultTransport http.RoundTripper = &http.Transport{
	DisableCompression: true,
}

DefaultTranpsort is the default http transport.

View Source
var NakamaBuilderContainerShortName = "bd"

NakamaBuilderContainerShortName is the nakama builder short name.

View Source
var NakamaContainerShortName = "nk"

NakamaContainerShortName is the nakama short name.

View Source
var NktestRunnerShortName = "xx"

NktestRunnerShortName is the nktest short name.

View Source
var PostgresContainerShortName = "pg"

PostgresContainerShortName is the postgres short name.

View Source
var TimeFormatValue = "2006-01-02 15:04:05"

TimeFormatValue is the time format.

Functions

func AlwaysPull added in v0.5.0

func AlwaysPull(ctx context.Context) bool

AlwaysPull returns whether or not to always pull an image.

func Backoff added in v0.5.0

func Backoff(ctx context.Context, f func(context.Context) error) error

Backoff executes f until backoff conditions are met or until f returns nil, or the context is closed.

func BuildTimeout added in v0.9.8

func BuildTimeout(ctx context.Context) time.Duration

BuildTimeout returns the build timeout.

func Cancel added in v0.5.0

func Cancel() error

Cancel cancels the current context.

func ConfigFilename added in v0.5.0

func ConfigFilename(ctx context.Context) string

ConfigFilename returns the config filename.

func ConfigTemplate added in v0.5.0

func ConfigTemplate(ctx context.Context) string

ConfigTemplate returns the config template.

func ConsoleWriter added in v0.7.0

func ConsoleWriter(ctx context.Context) io.Writer

ConsoleWriter returns the consoleWriter from the context.

func Debug added in v0.7.0

func Debug(ctx context.Context) *zerolog.Event

Debug returns a debug logger from the context.

func DockerAuthName added in v0.5.0

func DockerAuthName(ctx context.Context) string

DockerAuthName returns the docker token auth name.

func DockerAuthScope added in v0.5.0

func DockerAuthScope(ctx context.Context, id string) string

DockerAuthScope returns the docker token auth scope for a image id.

func DockerImageTags added in v0.5.0

func DockerImageTags(ctx context.Context, id string) ([]string, error)

DockerImageTags gets the docker registry tags for a image id.

func DockerRegistryURL added in v0.5.0

func DockerRegistryURL(ctx context.Context) string

DockerRegistryURL returns the docker registry url.

func DockerToken added in v0.5.0

func DockerToken(ctx context.Context, id string) (string, error)

DockerToken generates a docker auth token for the repo id.

func DockerTokenURL added in v0.5.0

func DockerTokenURL(ctx context.Context) string

DockerTokenURL returns the docker token url.

func Err added in v0.7.0

func Err(ctx context.Context, err error) *zerolog.Event

Err returns a err logger from the context.

func GoEnvVar

func GoEnvVar(goPath, name string) (string, error)

GoEnvVar reads the go env variable from `go env <name>`.

func HostPortMap added in v0.5.0

func HostPortMap(ctx context.Context, id, svc string, containerPort, hostPort uint16) uint16

HostPortMap returns the host port for the provided container id and service from the context.

func HttpClient added in v0.5.0

func HttpClient(ctx context.Context) *http.Client

HttpClient returns the http client from the context.

func Info added in v0.7.0

func Info(ctx context.Context) *zerolog.Event

Info returns a info logger from the context.

func IsSubDir

func IsSubDir(a, b string) error

IsSubDir determines if b is subdir of a.

func Logger

func Logger(ctx context.Context) zerolog.Logger

Logger returns the logger from the context.

func Main added in v0.5.0

func Main(parent context.Context, m TestRunner, opts ...Option)

Main is the main entry point that should be called from TestMain.

func NakamaImageId added in v0.5.0

func NakamaImageId(ctx context.Context) string

NakamaImageId returns the nakama image id.

func NakamaVersion added in v0.5.0

func NakamaVersion(ctx context.Context) (string, error)

NakamaVersion loads and caches the nakama version.

func New

func New(ctx, conn context.Context, opts ...Option)

New creates a new context.

func NewConsoleWriter added in v0.7.1

func NewConsoleWriter(w io.Writer, field, shortId, shortName string) io.Writer

NewConsoleWriter creates a zerolog console writer.

func NoopWriter added in v0.5.0

func NoopWriter() io.Writer

NoopWriter creates a no op writer.

func ParsePortMapping added in v0.3.4

func ParsePortMapping(s string) (pntypes.PortMapping, error)

ParsePortMapping creates a port mapping from s.

func PluginbuilderImageId added in v0.5.0

func PluginbuilderImageId(ctx context.Context) string

PluginbuilderImageId returns the pluginbuilder image id.

func PodRemoveTimeout added in v0.6.1

func PodRemoveTimeout(ctx context.Context) time.Duration

PodRemoveTimeout returns the pod remove timeout.

func PodmanBuildMounts

func PodmanBuildMounts(mounts ...string) ([]pspec.Mount, error)

PodmanBuildMounts creates mount specs for a container.

func PodmanConn added in v0.5.0

func PodmanConn(ctx context.Context) context.Context

PodmanConn returns the podman connection on the context.

func PodmanCreatePod

func PodmanCreatePod(ctx context.Context, podName string, ids ...string) (string, string, error)

PodmanCreatePod creates a pod network.

func PodmanFollowLogs

func PodmanFollowLogs(ctx context.Context, id, shortName string) error

PodmanFollowLogs follows the logs for a container.

func PodmanGetAddr

func PodmanGetAddr(ctx context.Context, id, svc string) (string, string, error)

PodmanGetAddr inspects id and returns the local and remote addresses.

func PodmanOpen added in v0.4.2

func PodmanOpen(ctx context.Context) (context.Context, context.Context, error)

PodmanOpen opens a podman context. 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 PodmanPodKill added in v0.6.1

func PodmanPodKill(ctx context.Context, name string) error

PodmanPodKill kills pod with matching name.

func PodmanPullImages

func PodmanPullImages(ctx context.Context, ids ...string) error

PodmanPullImages grabs image ids when not present on the host or when AlwaysPull returns true.

func PodmanRun

func PodmanRun(ctx context.Context, id, podId string, env map[string]string, mounts []string, entrypoint ...string) (string, error)

PodmanRun runs a container image id.

func PodmanStopAndRemove added in v0.11.0

func PodmanStopAndRemove(ctx context.Context, id, containerId string)

PodmanStopAndRemove stops and removes a container.

func PodmanWait

func PodmanWait(parent context.Context, id string) error

PodmanWait waits until a container has stopped.

func PodmanWaitService added in v0.11.0

func PodmanWaitService(ctx context.Context, id, svc string, f func(context.Context, string, string) error) error

PodmanWaitService waits for a container service to be available.

func PortMap added in v0.5.0

func PortMap(ctx context.Context) map[string]uint16

PortMap returns the port map from the context.

func PostgresImageId added in v0.5.0

func PostgresImageId(ctx context.Context) string

PostgresImageId returns the postgres image id.

func PostgresVersion added in v0.5.0

func PostgresVersion(ctx context.Context) string

PostgresVersion returns the postgres version.

func PrefixedWriter

func PrefixedWriter(w io.Writer, prefix string) io.Writer

PrefixedWriter creates a new prefixed writer.

func QualifiedId

func QualifiedId(id string) string

QualifiedId fully qualifies a container image id.

func ReadCachedFile

func ReadCachedFile(name string, ttl time.Duration) ([]byte, error)

ReadCachedFile reads a cached file from disk, returns error if the file name on disk is past the ttl.

func Run added in v0.6.0

func Run() error

Run runs the global context runner.

func RunProxy added in v0.5.1

func RunProxy(ctx context.Context, opts ...ProxyOption) (string, error)

RunProxy creates and runs a http proxy until the context is closed.

func SetLevel added in v0.9.0

func SetLevel(level zerolog.Level)

SetLevel sets the global log level.

func ShortId

func ShortId(id string) string

ShortId truncates id to 16 characters.

func Stdout added in v0.5.0

func Stdout(ctx context.Context) io.Writer

Stdout returns the stdout from the context.

func Trace added in v0.9.0

func Trace(ctx context.Context) *zerolog.Event

Trace returns a trace logger from the context.

func Transport

func Transport(ctx context.Context, transport http.RoundTripper) http.RoundTripper

Transport creates a transport from the context.

func UnderCI added in v0.9.8

func UnderCI(ctx context.Context) bool

UnderCI returns whether or not to always pull an image.

func VersionCacheTTL added in v0.5.0

func VersionCacheTTL(ctx context.Context) time.Duration

VersionCacheTTL returns the version cache ttl.

func WithAlwaysPull

func WithAlwaysPull(parent context.Context, alwaysPull bool) context.Context

WithAlwaysPull sets the always pull flag on the context. When true, causes container images to be pulled regardless of if they are available on the host or not.

func WithAlwaysPullFromEnv added in v0.5.0

func WithAlwaysPullFromEnv(parent context.Context, name string) context.Context

WithAlwaysPullFromEnv sets the always pull flag from an environment variable on the context.

func WithBackoff added in v0.9.9

func WithBackoff(parent context.Context, min, max, timeout time.Duration, factor float64) context.Context

WithBackoff sets the backoff min, max, timeout, and factor on the context. Used when waiting for services (ie, postgres, nakama) to become available.

func WithBackoffConfig added in v0.9.9

func WithBackoffConfig(parent context.Context, backoffConfig BackoffConfig) context.Context

WithBackoffConfig sets the backoff config on the context. Used when waiting for services (ie, postgres, nakama) to become available.

func WithBuildTimeout added in v0.9.8

func WithBuildTimeout(parent context.Context, buildTimeout time.Duration) context.Context

WithBuildTimeout sets the pod remove timeout on the context.

func WithConfigFilename

func WithConfigFilename(parent context.Context, configFilename string) context.Context

WithConfigFilename sets the config filename on the context.

func WithConfigTemplate

func WithConfigTemplate(parent context.Context, configTemplate string) context.Context

WithConfigTemplate sets the config template on the context.

func WithConsoleWriter added in v0.7.1

func WithConsoleWriter(parent context.Context, consoleWriter io.Writer) context.Context

WithConsoleWriter sets the console writer out on the context.

func WithDockerAuthName

func WithDockerAuthName(parent context.Context, dockerAuthName string) context.Context

WithDockerAuthName sets the docker token auth name on the context. Used when generating auth tokens for the docker registry.

func WithDockerAuthScope

func WithDockerAuthScope(parent context.Context, dockerAuthScope string) context.Context

WithDockerAuthScope sets a docker token auth scope mask on the context. Must include "%s" to interpolate the image id.

func WithDockerRegistryURL

func WithDockerRegistryURL(parent context.Context, dockerRegistryURL string) context.Context

WithDockerRegistryURL sets the docker registry url on the context. Used for retrieving images.

func WithDockerTokenURL

func WithDockerTokenURL(parent context.Context, dockerTokenURL string) context.Context

WithDockerTokenURL sets the docker token url on the context. Used for generating auth tokens when pulling images.

func WithHostPortMap added in v0.3.4

func WithHostPortMap(parent context.Context) context.Context

WithHostPortMap adds host port mappings for the postgres and nakama services (5432/tcp, 7349/tcp, 7350/tcp, 7351/tcp) to the context.

func WithHttpClient

func WithHttpClient(parent context.Context, httpClient *http.Client) context.Context

WithHttpClient sets the http client used on the context. Used for generating auth tokens for image repositories.

func WithNakamaImageId

func WithNakamaImageId(parent context.Context, nakamaImageId string) context.Context

WithNakamaImageId sets the nakama image id on the context.

func WithNakamaVersion

func WithNakamaVersion(parent context.Context, nakamaVersion string) context.Context

WithNakamaVersion sets the nakama image tag on the context.

func WithPluginbuilderImageId

func WithPluginbuilderImageId(parent context.Context, pluginbuilderImageId string) context.Context

WithPluginbuilderImageId sets the pluginbuilder image id on the context.

func WithPodRemoveTimeout added in v0.6.1

func WithPodRemoveTimeout(parent context.Context, podRemoveTimeout time.Duration) context.Context

WithPodRemoveTimeout sets the pod remove timeout on the context.

func WithPodmanConn added in v0.5.0

func WithPodmanConn(parent, conn context.Context) context.Context

WithPodmanConn sets the podman conn used on the context.

func WithPortMap added in v0.3.4

func WithPortMap(parent context.Context, id, svc string, port uint16) context.Context

WithPortMap adds a host port mapping for a service to the context.

func WithPostgresImageId

func WithPostgresImageId(parent context.Context, postgresImageId string) context.Context

WithPostgresImageId sets the postgres image id on the context.

func WithPostgresVersion

func WithPostgresVersion(parent context.Context, postgresVersion string) context.Context

WithPostgresVersion sets the postgres image tag on the context.

func WithStdout

func WithStdout(parent context.Context, stdout io.Writer) context.Context

WithStdout sets the stdout on the context.

func WithUnderCIFromEnv added in v0.9.8

func WithUnderCIFromEnv(parent context.Context, name string) context.Context

WithUnderCIFromEnv sets the under CI flag from an environment variable on the context.

func WithVersionCacheTTL

func WithVersionCacheTTL(parent context.Context, versionCacheTTL time.Duration) context.Context

WithVersionCacheTTL sets the version cache TTL on the context.

Types

type BackoffConfig added in v0.9.9

type BackoffConfig struct {
	Min     time.Duration
	Max     time.Duration
	Timeout time.Duration
	Factor  float64
}

BackoffConfig holds the backoff configuration.

func (BackoffConfig) Next added in v0.9.9

Next calculates the next backoff duration.

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 WithGoBuildOptions added in v0.9.8

func WithGoBuildOptions(buildOpts ...string) BuildConfigOption

WithGoBuildOptions is a nakama module build config option to add additional command-line options to Go build.

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

type EnvVolumeInfo struct {
	Key    string
	Target string
	Sub    string
}

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 Option

type Option func(*Runner)

Option is a nakama test runner option.

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 WithDir

func WithDir(dir string) Option

WithDir is a nakama test runner option to set the project root dir.

func WithRunEnv added in v0.10.1

func WithRunEnv(runEnv map[string]string) Option

WithRunEnv is a nakama test runner option to set run environment variables.

func WithVolumeDir

func WithVolumeDir(volumeDir string) Option

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 PodmanConnInfo added in v0.4.2

type PodmanConnInfo struct {
	Name     string `json:"Name"`
	URI      string `json:"URI"`
	Identity string `json:"Identity"`
	Default  bool   `json:"Default"`
	Insecure bool   `json:"Insecure"`
}

PodmanConnInfo holds information about a podman connection.

func BuildPodmanConnInfo added in v0.4.2

func BuildPodmanConnInfo(ctx context.Context) ([]PodmanConnInfo, error)

BuildPodmanConnInfo builds a list of potential podman connection info.

func PodmanSystemConnectionList added in v0.4.2

func PodmanSystemConnectionList(ctx context.Context) ([]PodmanConnInfo, error)

PodmanSystemConnectionList executes podman system connection list to retrieve the remote socket list.

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) Addr

func (p *Proxy) Addr() string

Addr returns the listening address.

func (Proxy) DialError added in v0.3.0

func (p Proxy) DialError(ctx context.Context, inWriter io.Writer, w http.ResponseWriter, req *http.Request, res *http.Response, err error)

func (*Proxy) Run

func (p *Proxy) Run(ctx context.Context, urlstr string) (string, error)

Run proxies requests to the url until the context is closed.

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 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 RoundTripper added in v0.5.0

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

RoundTripper is a logging transport.

func NewRoundTripper added in v0.5.0

func NewRoundTripper(req, res io.Writer, transport http.RoundTripper) *RoundTripper

NewRoundTripper creates a logging transport.

func (*RoundTripper) DisableReqBody added in v0.5.0

func (t *RoundTripper) DisableReqBody()

DisableReqBody disables logging the request body.

func (*RoundTripper) DisableResBody added in v0.5.0

func (t *RoundTripper) DisableResBody()

DisableResBody disables logging the response body.

func (*RoundTripper) RoundTrip added in v0.5.0

func (t *RoundTripper) RoundTrip(req *http.Request) (*http.Response, error)

RoundTrip satisfies the http.RoundTripper interface.

type Runner

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

Runner is a nakama test runner.

func NewRunner added in v0.5.0

func NewRunner(opts ...Option) *Runner

NewRunner creates a new nakama test runner.

func WithCancel added in v0.5.0

func WithCancel(parent context.Context, t TestLogger) (context.Context, context.CancelFunc, *Runner)

WithCancel creates a new context for use within Test* funcs.

func (*Runner) BuildModule

func (r *Runner) BuildModule(ctx context.Context, id string, bc *BuildConfig) error

BuildModule builds a nakama plugin module.

func (*Runner) BuildModules

func (r *Runner) BuildModules(ctx context.Context, id string) error

BuildModules builds the nakama modules.

func (*Runner) ConsoleLocal added in v0.4.0

func (r *Runner) ConsoleLocal() string

ConsoleLocal returns the console local address.

func (*Runner) ConsoleRemote added in v0.4.0

func (r *Runner) ConsoleRemote() string

ConsoleRemote returns the console remote address.

func (*Runner) GrpcLocal

func (r *Runner) GrpcLocal() string

GrpcLocal returns the grpc local address.

func (*Runner) GrpcRemote

func (r *Runner) GrpcRemote() string

GrpcRemote returns the grpc remote address.

func (*Runner) HttpKey added in v0.4.0

func (r *Runner) HttpKey() string

HttpKey returns the http key.

func (*Runner) HttpLocal

func (r *Runner) HttpLocal() string

HttpLocal returns the http local address.

func (*Runner) HttpRemote

func (r *Runner) HttpRemote() string

HttpRemote returns the http remote address.

func (*Runner) Name

func (r *Runner) Name() string

Name returns the name.

func (*Runner) PodContainerId added in v0.6.0

func (r *Runner) PodContainerId() string

PodContainerId returns the pod infrastructure container id.

func (*Runner) PodId

func (r *Runner) PodId() string

PodId returns the pod id.

func (*Runner) PostgresLocal

func (r *Runner) PostgresLocal() string

PostgresLocal returns the postgres local address.

func (*Runner) PostgresRemote

func (r *Runner) PostgresRemote() string

PostgresRemote returns the postgres remote address.

func (*Runner) Run

func (r *Runner) Run(ctx context.Context) error

Run handles building the nakama plugin and starting the postgres and nakama server containers.

func (*Runner) RunNakama

func (r *Runner) RunNakama(ctx context.Context, id string) error

RunNakama runs the nakama server.

func (*Runner) RunPostgres

func (r *Runner) RunPostgres(ctx context.Context, id string) error

RunPostgres runs the postgres server.

func (*Runner) RunProxy

func (r *Runner) RunProxy(ctx context.Context, opts ...ProxyOption) (string, error)

RunProxy creates and runs a http proxy until the context is closed.

func (*Runner) ServerKey added in v0.3.0

func (r *Runner) ServerKey() string

ServerKey returns the server key.

type TestLogger added in v0.5.0

type TestLogger interface {
	Logf(string, ...interface{})
}

TestLogger is the test log interface. Compatible with stdlib's testing.T.

type TestRunner added in v0.5.0

type TestRunner interface {
	Run() int
}

TestRunner is the test runner interface. Compatible with stdlib's testing.M.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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