cmdexec

Go library for mocking exec.Command and exec.CommandContext calls.

LGPL-3.0 License

Stars
1

cmdexec

Go library for mocking exec.Command and exec.CommandContext calls. Aims to provide an as close as possible [exec.Cmd]-like interface for drop-in support.

Differences

  • Instead of setting cmd.Stdin (or in/err), use SetStdin()
    functions instead. This is due to those being fields on a struct,
    which cannot be on an interface.

Usage

See our Go docs.

Asserting Output

Normally, you shouldn't need to assert anything as your function that executes a command should give you testing signal (is it working or not 😉). However, you can assert certain fields with this library. Currently, this is limited to Stdin checking.

If you set [MockCommand.Stdin] and call SetStdin in the function executing a command, Stdin will be checked to ensure it is equal. This is to allow greater testing if required.

License

LGPL-3.0