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.
Creating a mock binary and getting its path:
mockMonit = binmock.NewBinMock(ginkgo.Fail)
monitPath := mockMonit.Path
thingToTest := NewThingToTest(monitPath)
Setting up expected interactions with the binary:
mockMonit.WhenCalledWith("start", "all").WillExitWith(0)
mockMonit.WhenCalledWith("summary").WillPrintToStdOut(output)
mockMonit.WhenCalledWith("summary").WillPrintToStdOut(output).WillPrintToStdErr("Noooo!").WillExitWith(1)
Asserting on the interactions with the binary, after the fact:
Expect(mockPGDump.Invocations()).To(HaveLen(1))
Expect(mockPGDump.Invocations()[0].Args()).To(Equal([]string{"dbname"}))
Expect(mockPGDump.Invocations()[0].Env()).To(HaveKeyWithValue("PGPASS", "p@ssw0rd"))
For a working example you can look at backup-and-restore-sdk