cmdtest

package
v3.0.0 Latest Latest
Warning

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

Go to latest
Published: Sep 18, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package cmdtest is the shared test harness for rde command groups. It replaces five near-duplicate per-package `run` helpers (one apiece for session/template/savedinput/stack/machinetype in the reference implementation) with a single Run, adapted to how this repo actually resolves token/format/workspace: token from auth.yaml/BITRISE_TOKEN via cmdutil.ResolveToken, format from a real --format flag, workspace from flag/env/config layering — none of which live on a single flat struct the way the reference's config.Resolved does.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Run

func Run(t *testing.T, cmd *cobra.Command, opts Opts) (stdout, stderr string, err error)

Run executes cmd with opts and returns its captured stdout/stderr.

func RunIsolated

func RunIsolated(m *testing.M) int

RunIsolated sandboxes a package's tests with a temp XDG_CONFIG_HOME (so the token-refresh path never touches a developer's real auth.yaml) and a no-op analytics tracker (LogCommandParameters needs one set globally — see cli/app/main_test.go). Use from a package TestMain:

func TestMain(m *testing.M) { os.Exit(cmdtest.RunIsolated(m)) }

Every env var below reaches a command through a cli/cmdutil resolver rather than through config.WithResolved, so a developer who exports one would get different results than CI: an ambient BITRISE_WORKSPACE_ID alone silently redirects every request a test asserts a path for.

Types

type Opts

type Opts struct {
	Args               []string
	RDEAPIBaseURL      string
	DefaultWorkspaceID string
	Format             string // "raw"/"json"/"yml"; empty leaves the command's own default
	Stdin              string
}

Opts configures a single Run of cmd under test.

Jump to

Keyboard shortcuts

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