Commit graph

7 commits

Author SHA1 Message Date
Owen Waller
6b28e38cea Expansion of unit tests for utils/utils.go
This commit expands the test coverage for the utils/utils.go module.

The utils module uses the 'github.com/spf13/jwalterweatherman' (aka jww)
package for logging. The tests take the approach of examining the log
file that is produced by this module to verify correct behaviour. This
avoids refactoring the utils module.

The log file messages written by the jww module are of the form:
<log level>: yyyy/mm/dd <string|error message>

The checkLogFile function checks each of these parts in turn except for
the date string, which is currently ignored. The final part of the log
file format can either be a single error message, or a series of
strings followed by an error message. Both the error message and the
series of strings can be empty strings.

The log file is checked using a combination of the regex package,
along with the bufio scanner type. Each test logs to its own temporary
log file. This is achieved with standard test setup and teardown
functions.

One consequence of these tests is that StopOnErr has been refactored
into call a new unexported function doStopOnErr which contains the bulk
of the original logic. This allows the same testing approach to be used
with StopOnErr as with CheckErr and cutUsageMessage, rather than look at
the exit status code of the test itself.

An unfortunate side effect of this is that the author of the tests must
now know if a log file is expected or not. If doStopOnErr determines
that an empty error message would be written to the log file then
nothing is written. In the context of the tests this means that the log
file created by the test would have no contents. Consequently there
would be nothing for the test to examine. This situation is indicated by
the boolean flag logFileExoected in the testData struct, and processed
by the logFileIsExpectedAndValid function.

Although not ideal this was deemed a reasonable compromise.
2015-02-17 02:20:00 -07:00
Tatsushi Demachi
d9964451a5 More error messages at syncing static contents 2014-09-08 11:57:06 -04:00
Joel Scoble
4b979b17cc added functionality to check the error message returned from Cobra, if any. for uage message text. If its present, the usage message gets truncated and the resulting message is returned to be used for the rest of the error message. If the resulting error is blank, no error message is printed 2014-08-25 11:50:23 -04:00
Billie H. Cleek
73dd4f38d0 report errors
Modify CheckErr and StopOnErrErr to report the error if there aren't any
other messages.
2014-06-30 15:26:40 -04:00
spf13
e50b9d8ac1 Adding support for logging & verbose logging. Consolidation of error handling. Integration of jWalterWeatherman library. Fixed #137 2014-03-31 13:23:34 -04:00
spf13
f5fda80486 simplified buildSite & better error handling around it 2013-10-09 19:14:26 -04:00
spf13
0318f7c149 Clean up server & build site logic. Fixed #94 2013-10-09 18:53:46 -04:00