clie2e

package
v1.0.67 Latest Latest
Warning

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

Go to latest
Published: Jul 8, 2026 License: MIT Imports: 13 Imported by: 0

README

CLI E2E Tests

This directory contains end-to-end tests for lark-cli.

The purpose of this module is to verify real CLI workflows from a user-facing perspective: run the compiled binary, execute commands end to end, and catch regressions that are not obvious from unit tests alone.

What Is Here

  • core.go, core_test.go: the shared E2E test harness and its own tests
  • demo/: reference testcase(s)
  • cli-e2e-testcase-writer/: the local skill for adding or updating testcase files in this module

For Contributors

When writing or updating testcases under tests/cli_e2e, install and use this skill first:

npx skills add ./tests/cli_e2e/cli-e2e-testcase-writer

Then follow tests/cli_e2e/cli-e2e-testcase-writer/SKILL.md.

Example prompt:

Use $cli-e2e-testcase-writer to write lark-cli xxx domain related testcases.
Put them under tests/cli_e2e/xxx.

Run

make build
go test ./tests/cli_e2e/... -count=1

Documentation

Overview

Package clie2e contains end-to-end tests for lark-cli.

Index

Constants

View Source
const (
	// CleanupTimeout is the outer teardown budget. Keep it above any
	// per-resource wait so cleanup command retries still have room to run.
	CleanupTimeout = 60 * time.Second
)
View Source
const EnvBinaryPath = "LARK_CLI_BIN"

Variables

This section is empty.

Functions

func BuildArgs

func BuildArgs(req Request) ([]string, error)

BuildArgs converts a request into CLI arguments.

func CleanupContext added in v1.0.14

func CleanupContext() (context.Context, context.CancelFunc)

CleanupContext returns a bounded context for teardown operations so cleanup cannot outlive the test indefinitely when the remote API stalls.

func CleanupWarning added in v1.0.67

func CleanupWarning(err error) error

CleanupWarning marks a cleanup verification issue as non-fatal after the destructive cleanup command itself has already succeeded.

func GenerateSuffix added in v1.0.10

func GenerateSuffix() string

GenerateSuffix returns a high-entropy UTC timestamp suffix suitable for remote test resource names.

func IsCleanupWarning added in v1.0.67

func IsCleanupWarning(err error) bool

IsCleanupWarning reports whether err should be logged without failing the parent test.

func ReportCleanupFailure added in v1.0.14

func ReportCleanupFailure(parentT *testing.T, prefix string, result *Result, err error)

ReportCleanupFailure emits a uniform cleanup error with command output.

func ResolveBinaryPath

func ResolveBinaryPath(req Request) (string, error)

ResolveBinaryPath finds the CLI binary path using request, env, then PATH.

func ResultHasRetryableError added in v1.0.67

func ResultHasRetryableError(result *Result) bool

ResultHasRetryableError reports whether lark-cli returned a structured service error with error.retryable=true in either output stream.

func SkipWithoutUserToken added in v1.0.14

func SkipWithoutUserToken(t *testing.T)

func WaitForCondition added in v1.0.67

func WaitForCondition(ctx context.Context, opts WaitOptions, condition func() (bool, error)) error

WaitForCondition polls condition until it returns true, an error, the context is canceled, or the configured timeout expires.

Types

type Request

type Request struct {
	// Args are required and exclude the lark-cli binary name.
	Args []string
	// Params is optional and becomes --params '<json>' when non-nil.
	Params any
	// Data is optional and becomes --data '<json>' when non-nil.
	Data any
	// Stdin is optional and becomes the child process stdin when non-nil.
	// Use an empty slice to exercise empty-stdin behavior explicitly.
	Stdin []byte
	// BinaryPath is optional. Empty means: LARK_CLI_BIN, project-root ./lark-cli, then PATH.
	BinaryPath string
	// DefaultAs is optional and becomes --as <value> when non-empty.
	DefaultAs string
	// Format is optional and becomes --format <format> when non-empty.
	Format string
	// WorkDir is optional and becomes the child process working directory when non-empty.
	WorkDir string
	// Env adds or overrides environment variables for this one child process only.
	Env map[string]string
	// Yes confirms high-risk-write commands. When true, the runner appends
	// --yes so the framework-level confirmation gate passes. Setting it on a
	// non-high-risk command will fail with "unknown flag: --yes".
	Yes bool
}

Request describes one lark-cli invocation.

type Result

type Result struct {
	BinaryPath string
	Args       []string
	ExitCode   int
	Stdout     string
	Stderr     string
	RunErr     error
}

Result captures process execution output.

func RunCmd

func RunCmd(ctx context.Context, req Request) (*Result, error)

RunCmd executes lark-cli and captures stdout/stderr/exit code. Service errors that return {"error":{"retryable":true}} are retried with bounded exponential backoff so individual tests do not need to remember RunCmdWithRetry for normal transient server contention.

func RunCmdWithRetry added in v1.0.10

func RunCmdWithRetry(ctx context.Context, req Request, opts RetryOptions) (*Result, error)

RunCmdWithRetry reruns a command when the result matches the configured retry condition.

func (*Result) AssertExitCode

func (r *Result) AssertExitCode(t *testing.T, code int)

AssertExitCode asserts the exit code.

func (*Result) AssertStdoutStatus

func (r *Result) AssertStdoutStatus(t *testing.T, expected any)

AssertStdoutStatus asserts stdout JSON status using either {"ok": ...} or {"code": ...}. This intentionally keeps one shared assertion entrypoint for CLI E2E call sites, so tests can stay uniform across shortcut-style {"ok": ...} responses and service-style {"code": ...} responses without branching on response shape.

func (*Result) StderrJSON

func (r *Result) StderrJSON(t *testing.T) any

StderrJSON decodes stderr as JSON.

func (*Result) StdoutJSON

func (r *Result) StdoutJSON(t *testing.T) any

StdoutJSON decodes stdout as JSON.

type RetryOptions added in v1.0.10

type RetryOptions struct {
	Attempts        int
	InitialDelay    time.Duration
	MaxDelay        time.Duration
	BackoffMultiple int
	ShouldRetry     func(*Result) bool
}

RetryOptions configures retry behavior for flaky external API calls.

type WaitOptions added in v1.0.67

type WaitOptions struct {
	Timeout      time.Duration
	Interval     time.Duration
	TimeoutError func() error
}

WaitOptions configures a bounded poll loop for eventually consistent cleanup or verification checks.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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