Categorygithub.com/lox/bintest
modulepackage
1.0.0
Repository: https://github.com/lox/bintest.git
Documentation: pkg.go.dev

# README

Bintest

A set of tools for generating binaries for testing. Mock objects are the primary usage, built on top of a general Proxy object that allows for binaries to be added to a system under test that are controlled from the main test case.

Mocks

agent, err := bintest.Mock("buildkite-agent")
if err != nil {
  t.Fatal(err)
}

agent.
  Expect("meta-data", "exists", "buildkite:git:commit").
  AndExitWith(1)
agent.
  Expect("meta-data", "set", mock.MatchAny()).
  AndExitWith(0)
agent.
  Expect("meta-data", "set", "buildkite:git:branch", mock.MatchAny()).
  AndExitWith(0)

agent.AssertExpectations(t)

Proxies

// create a proxy for the git command that echos some debug
proxy, err := proxy.New("git")
if err != nil {
  log.Fatal(err)
}

// call the proxy like a normal binary
go fmt.Println(exec.Command("git", "test", "arguments").CombinedOutput())

// handle invocations of the proxy binary
for call := range proxy.Ch {
  fmt.Fprintln(call.Stdout, "Llama party! 🎉")
  call.Exit(0)
}

// Llama party! 🎉

Credit

Inspired by bats-mock and go-binmock.

# Packages

No description provided by the author

# Functions

No description provided by the author
ExpectEnv asserts that certain environment vars/values exist, otherwise an error is reported to T and a matching error is returned (for Before).
Prints a slice of interface{} as quoted arguments.
Prints a slice of strings as quoted arguments.
GetEnv returns the value for a given env in the invocation.
No description provided by the author
Mock returns a new Mock instance, or fails if the bintest fails to compile.

# Constants

No description provided by the author

# Variables

No description provided by the author

# Structs

Expectation is used for setting expectations.
Invocation is a call to the binary.
No description provided by the author
Mock provides a wrapper around a Proxy for testing.

# Interfaces

No description provided by the author
TestingT is an interface for *testing.T.

# Type aliases

No description provided by the author
expectationSet is a set of expectations.