GithubHelp home page GithubHelp logo

isabella232 / bintest Goto Github PK

View Code? Open in Web Editor NEW

This project forked from buildkite/bintest

0.0 0.0 0.0 241 KB

Golang tools for generating mock binaries for that can be orchestrated in realtime for testing

License: MIT License

Go 100.00%

bintest's Introduction

Bintest

Documentation

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.

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.

// 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 and go-binmock.

bintest's People

Contributors

lox avatar pda avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.