https://github.com/buildkite/bintest
Golang tools for generating mock binaries for that can be orchestrated in realtime for testing
https://github.com/buildkite/bintest
cli golang golang-library mock testing
Last synced: about 1 year ago
JSON representation
Golang tools for generating mock binaries for that can be orchestrated in realtime for testing
- Host: GitHub
- URL: https://github.com/buildkite/bintest
- Owner: buildkite
- License: mit
- Created: 2017-09-09T10:48:30.000Z (almost 9 years ago)
- Default Branch: master
- Last Pushed: 2024-08-20T01:50:19.000Z (almost 2 years ago)
- Last Synced: 2024-08-21T05:30:12.941Z (almost 2 years ago)
- Topics: cli, golang, golang-library, mock, testing
- Language: Go
- Homepage:
- Size: 284 KB
- Stars: 11
- Watchers: 19
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Bintest
> :warning: This is an open-sourced tool we use internally. You're welcome to
> use it, but we are unable to provide support.
[](http://godoc.org/github.com/buildkite/bintest)
A set of tools for generating fake binaries that can be used for testing. A binary is compiled and then can be orchestrated from your test suite and later checked for assertions.
Mocks can communicate and respond in real-time with the tests that are calling them, which allows for testing complicated dependencies. See https://github.com/buildkite/agent/tree/master/bootstrap/integration for how we use it to test buildkite-agent's bootstrap process.
## Mocks
Mocks are your typical mock object, but as an executable that your code can shell out to and then later test assertions on.
```go
agent, err := bintest.NewMock("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.CheckAndClose(t)
```
## Proxies
Proxies are what power Mocks.
```go
// Compile a proxy for the git command that echos some debug
proxy, err := bintest.CompileProxy("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](https://github.com/jasonkarns/bats-mock) and [go-binmock](https://github.com/pivotal-cf/go-binmock).