envtest

package
v0.27.2 Latest Latest
Warning

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

Go to latest
Published: Oct 18, 2023 License: Apache-2.0 Imports: 32 Imported by: 0

README

Starport Integration Tests

The Starport integration tests build a new application and run all Starport commands to check the Starport code integrity. The runners and helper methods are located in this current folder. The test commands are split into folders, for better concurrency, each folder is a parallel job into the CI workflow. To create a new one, we only need to create a new folder. This will be automatically detected and added into the PR CI checks, or we can only create new tests into an existing folder or file.

Running synchronously all integration tests can be very slow. The command below can run everything:

go test -v -timeout 120m ./integration

Or you can just run a specific test folder, like the list types test

go test -v -timeout 120m ./integration/list

Usage

  • Create a new env and scaffold an empty chain:
var (
 env  = envtest.New(t)
 path = env.Scaffold("github.com/test/blog")
)
  • Now, you can use the env to run the starport commands and check the success status:
env.Must(env.Exec("create a list with bool",
    step.NewSteps(step.New(
        step.Exec(envtest.IgniteApp, "s", "list", "--yes", "document", "signed:bool"),
        step.Workdir(path),
    )),
))
env.EnsureAppIsSteady(path)
  • To check if the command returns an error, you can add the envtest.ExecShouldError() step:
env.Must(env.Exec("should prevent creating a list with duplicated fields",
    step.NewSteps(step.New(
        step.Exec(envtest.IgniteApp, "s", "list", "--yes", "company", "name", "name"),
        step.Workdir(path),
    )),
    envtest.ExecShouldError(),
))
env.EnsureAppIsSteady(path)

Documentation

Index

Constants

View Source
const (
	ConfigYML = "config.yml"
)
View Source
const ServeTimeout = time.Minute * 15

Variables

View Source
var (
	// IgniteApp hold the location of the ignite binary used in the integration
	// tests. The binary is compiled the first time the env.New() function is
	// invoked.
	IgniteApp = path.Join(os.TempDir(), "ignite-tests", "ignite")
)

Functions

func Contains added in v0.24.0

func Contains(s, partial string) bool

func HasTestVerboseFlag added in v0.24.0

func HasTestVerboseFlag() bool

Types

type App added in v0.24.0

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

func (App) Binary added in v0.24.0

func (a App) Binary() string

Binary returns the binary name of the app. Can be executed directly w/o any path after app.Serve is called, since it should be in the $PATH.

func (App) Config added in v0.25.0

func (a App) Config() chainconfig.Config

func (App) EditConfig added in v0.24.0

func (a App) EditConfig(apply func(*chainconfig.Config))

func (App) EnableFaucet added in v0.24.0

func (a App) EnableFaucet(coins, coinsMax []string) (faucetAddr string)

EnableFaucet enables faucet by finding a random port for the app faucet and update config.yml with this port and provided coins options.

func (App) EnsureSteady added in v0.24.0

func (a App) EnsureSteady()

EnsureSteady ensures that app living at the path can compile and its tests are passing.

func (App) GenerateTSClient added in v0.25.0

func (a App) GenerateTSClient() bool

GenerateTSClient runs the command to generate the Typescript client code.

func (App) RandomizeServerPorts added in v0.24.0

func (a App) RandomizeServerPorts() Hosts

RandomizeServerPorts randomizes server ports for the app at path, updates its config.yml and returns new values.

func (App) RunClientTests added in v0.25.0

func (a App) RunClientTests(options ...ClientOption) bool

RunClientTests runs the Typescript client tests.

func (App) Serve added in v0.24.0

func (a App) Serve(msg string, options ...ExecOption) (ok bool)

Serve serves an application lives under path with options where msg describes the execution from the serving action. unless calling with Must(), Serve() will not exit test runtime on failure.

func (*App) SetConfigPath added in v0.24.0

func (a *App) SetConfigPath(path string)

func (App) Simulate added in v0.24.0

func (a App) Simulate(numBlocks, blockSize int)

Simulate runs the simulation test for the app.

func (App) SourcePath added in v0.24.0

func (a App) SourcePath() string

func (App) UseRandomHomeDir added in v0.24.0

func (a App) UseRandomHomeDir() (homeDirPath string)

UseRandomHomeDir sets in the blockchain config files generated temporary directories for home directories. Returns the random home directory.

type AppOption added in v0.24.0

type AppOption func(*App)

func AppConfigPath added in v0.24.0

func AppConfigPath(path string) AppOption

func AppHomePath added in v0.24.0

func AppHomePath(path string) AppOption

type ClientOption added in v0.25.0

type ClientOption func(*clientOptions)

ClientOption defines options for the TS client test runner.

func ClientEnv added in v0.25.0

func ClientEnv(env map[string]string) ClientOption

ClientEnv option defines environment values for the tests.

func ClientTestFile added in v0.25.0

func ClientTestFile(filePath string) ClientOption

ClientTestFile option defines the name of the file where to look for tests.

func ClientTestName added in v0.25.0

func ClientTestName(pattern string) ClientOption

ClientTestName option defines a pattern to match the test names that should be run.

type Env

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

Env provides an isolated testing environment and what's needed to make it possible.

func New

func New(t *testing.T) Env

New creates a new testing environment.

func (Env) App added in v0.24.0

func (e Env) App(path string, options ...AppOption) App

func (Env) AppHome added in v0.24.0

func (e Env) AppHome(name string) string

AppHome returns app's root home/data dir path.

func (Env) Ctx

func (e Env) Ctx() context.Context

Ctx returns parent context for the test suite to use for cancelations.

func (Env) Exec

func (e Env) Exec(msg string, steps step.Steps, options ...ExecOption) (ok bool)

Exec executes a command step with options where msg describes the expectation from the test. unless calling with Must(), Exec() will not exit test runtime on failure.

func (Env) HasFailed added in v0.24.0

func (e Env) HasFailed() bool

func (Env) Home

func (e Env) Home() string

Home returns user's home dir.

func (Env) IsAppServed

func (e Env) IsAppServed(ctx context.Context, apiAddr string) error

IsAppServed checks that app is served properly and servers are started to listening before ctx canceled.

func (Env) IsFaucetServed

func (e Env) IsFaucetServed(ctx context.Context, faucetClient cosmosfaucet.HTTPClient) error

IsFaucetServed checks that faucet of the app is served properly.

func (Env) Must

func (e Env) Must(ok bool)

Must fails the immediately if not ok. t.Fail() needs to be called for the failing tests before running Must().

func (Env) RequireExpectations added in v0.24.0

func (e Env) RequireExpectations()

func (Env) Scaffold

func (e Env) Scaffold(name string, flags ...string) App

Scaffold scaffolds an app to a unique appPath and returns it.

func (Env) SetCleanup

func (e Env) SetCleanup(f func())

SetCleanup registers a function to be called when the test (or subtest) and all its subtests complete.

func (Env) T added in v0.25.0

func (e Env) T() *testing.T

func (Env) TmpDir

func (e Env) TmpDir() (path string)

TmpDir creates a new temporary directory.

type ExecOption

type ExecOption func(*execOptions)

func ExecCtx

func ExecCtx(ctx context.Context) ExecOption

ExecCtx sets cancelation context for the execution.

func ExecRetry

func ExecRetry() ExecOption

ExecRetry retries command until it is successful before context is canceled.

func ExecShouldError

func ExecShouldError() ExecOption

ExecShouldError sets the expectations of a command's execution to end with a failure.

func ExecStderr

func ExecStderr(w io.Writer) ExecOption

ExecStderr captures stderr of an execution.

func ExecStdout

func ExecStdout(w io.Writer) ExecOption

ExecStdout captures stdout of an execution.

type Hosts added in v0.25.0

type Hosts struct {
	RPC     string
	P2P     string
	Prof    string
	GRPC    string
	GRPCWeb string
	API     string
	Faucet  string
}

Hosts contains the "hostname:port" addresses for different service hosts.

Jump to

Keyboard shortcuts

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