pivotal-cf/go-binmock

Name: go-binmock

Owner: Pivotal Cloud Foundry

Description: null

Created: 2017-04-20 14:50:00.0

Updated: 2017-11-08 08:23:35.0

Pushed: 2017-10-27 11:27:08.0

Homepage: null

Size: 49

Language: Go

GitHub Committers

UserMost Recent Commit# Commits

Other Committers

UserEmailMost Recent Commit# Commits

README

go-binmock

Build Status

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

Creating a mock binary and getting its path:

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

gToTest := NewThingToTest(monitPath)

Setting up 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)

Asserting 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"))

For a working example you can look at backup-and-restore-sdk


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.