dougblack/sleepy — pull request #27 by eduncan911 (2014-12-11 03:59:19+00:00)
Title: converting to use interface, to allow for mocking in unit tests

For best practices in allowing for others to mock packages for unit tests of their own code, packages should export interfaces - especially from the New() convention.

This pull request remains backwards compatible with all existing code. Read: `NewAPI()` isn't broken and remains functional, along with all func()s on the returned object.

In addition, the existing `go test` tests continue to run (just the 1 lightweight one already there).

The difference now is that `NewAPI()` returns an interface instead of a pointer (thank you for using a pointer! it is the perfect replacement with an interface). That interface exports the exact same func()s. Only now, an end-user (like myself) can mockup a test struct to use in place of that interface for unit tests.