bradcypert.com
Testing a Cobra CLI in Go - Brad Cypert
Testing a Cobra CLI is easy if you take the time to refactor your command function out into function with an identifier. It can then be tested as normal.