clie2e

package
v1.0.10 Latest Latest
Warning

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

Go to latest
Published: Apr 13, 2026 License: MIT Imports: 14 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 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 GenerateSuffix added in v1.0.10

func GenerateSuffix() string

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

func ResolveBinaryPath

func ResolveBinaryPath(req Request) (string, error)

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

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
}

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.

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.

Jump to

Keyboard shortcuts

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