buildkite/go-binmock

Name: go-binmock

Owner: Buildkite

Description: null

Forked from: pivotal-cf/go-binmock

Created: 2017-09-07 01:27:23.0

Updated: 2017-09-07 01:27:25.0

Pushed: 2017-08-07 17:28:13.0

Homepage: null

Size: 44

Language: Go

GitHub Committers

UserMost Recent Commit# Commits

Other Committers

UserEmailMost Recent Commit# Commits

README

go-binmock

A library to mock interactions with collaborating executables. It works by creating a fake executable that can be orchestrated by the test. The path of the test executable can be injected into the system under test.

Usage

Create a mock binary and getting its path.

Monit = binmock.NewBinMock(ginkgo.Fail)
tPath := mockMonit.Path

gToTest := NewThingToTest(monitPath)

Setup expected interactions with the binary

Monit.WhenCalledWith("start", "all").WillExitWith(0)
Monit.WhenCalledWith("summary").WillPrintToStdOut(output)
Monit.WhenCalledWith("summary").WillPrintToStdOut(output).WillPrintToStdErr("Noooo!").WillExitWith(1)

Assert on the interactions with the binary, after the fact

ct(mockPGDump.Invocations()).To(HaveLen(1))
ct(mockPGDump.Invocations()[0].Args()).To(Equal([]string{"dbname"}))
ct(mockPGDump.Invocations()[0].Env()).To(HaveKeyWithValue("PGPASS", "p@ssw0rd"))

This work is supported by the National Institutes of Health's National Center for Advancing Translational Sciences, Grant Number U24TR002306. This work is solely the responsibility of the creators and does not necessarily represent the official views of the National Institutes of Health.