ffmpegtest

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Oct 13, 2026 License: AGPL-3.0 Imports: 11 Imported by: 0

Documentation

Overview

Package ffmpegtest provides fake ffmpeg and ffprobe binaries for tests.

A fake is the running test binary itself, reached through a symlink named after the fake. Install writes what the fake does to a data file beside the symlink, and Dispatch, called first in the package's TestMain, acts it out when the binary starts under that name. No executable file is ever written, so running a fake can never fail with "text file busy".

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Dispatch

func Dispatch()

Dispatch acts out a fake when the test binary started as one.

It then exits. It returns only when no stub sits beside the binary. Call it first in TestMain.

func Install

func Install(tb testing.TB, stub Stub) string

Install creates a fake binary for the length of a test.

Parameters:

  • tb: The test the fake belongs to.
  • stub: What the fake does.

Returns:

  • path: The fake to hand to the code under test.

Types

type Case

type Case struct {
	// Arg is the argument that selects the case.
	Arg string `json:"arg"`

	// Stdout is written to standard output.
	Stdout string `json:"stdout"`

	// Stderr is written to standard error.
	Stderr string `json:"stderr"`

	// ExitCode is the status the fake exits with.
	ExitCode int `json:"exitCode"`

	// Output, when set, is written to the file named by the last argument.
	Output string `json:"output"`
}

Case is what a fake does instead for a run whose arguments include Arg.

type Stub

type Stub struct {
	// Stdout is written to standard output.
	Stdout string `json:"stdout"`

	// Stderr is written to standard error.
	Stderr string `json:"stderr"`

	// ExitCode is the status the fake exits with.
	ExitCode int `json:"exitCode"`

	// Swap names a file the fake replaces with replacement.mkv from the same
	// directory before it writes anything, so a cache keyed on the file's
	// identity sees it change mid-run.
	Swap Swap `json:"swap"`

	// ArgvFile, when set, receives every argument on its own line.
	ArgvFile string `json:"argvFile"`

	// ArgvSeparator, when set, is appended to ArgvFile after the arguments, so
	// several runs can be told apart.
	ArgvSeparator string `json:"argvSeparator"`

	// ArgvBesideOutput appends every argument to "<last argument>.argv".
	ArgvBesideOutput bool `json:"argvBesideOutput"`

	// Output, when set, is written to the file named by the last argument.
	Output string `json:"output"`

	// Cases replace Stdout, Stderr, ExitCode, and Output for a run whose
	// arguments include a case's Arg, so one fake can answer each kind of
	// call a caller makes. The first case that matches wins.
	Cases []Case `json:"cases"`
}

Stub is what a fake binary does when it runs.

type Swap

type Swap string

Swap names the argument whose file a fake replaces while it runs.

const (
	// SwapNone leaves every file alone.
	SwapNone Swap = ""

	// SwapInput replaces the file after the "-i" argument, as ffmpeg reads it.
	SwapInput Swap = "input"

	// SwapLast replaces the file named by the last argument, as ffprobe reads it.
	SwapLast Swap = "last"
)

Jump to

Keyboard shortcuts

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