From b8fd642435ab441beb8003665c71f77fbdbafe19 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sever=20B=C4=83ne=C5=9Fiu?= Date: Fri, 29 Jan 2016 00:26:58 +0200 Subject: [PATCH] Add custom error messages for assertions. --- logging/facility_test.go | 6 ++++-- logging/level_test.go | 9 ++++++--- logging/named_test.go | 12 ++++++++---- 3 files changed, 18 insertions(+), 9 deletions(-) diff --git a/logging/facility_test.go b/logging/facility_test.go index cd8fd50d..833d9797 100644 --- a/logging/facility_test.go +++ b/logging/facility_test.go @@ -74,11 +74,13 @@ func (s *LogFacilityTestSuite) afterLevelIsSet() { } func (s *LogFacilityTestSuite) TestSetLevelError() { - s.Error(s.facility.SetLevel("name", Panic)) + s.Error(s.facility.SetLevel("name", Panic), + "Setting a severity level above Fatal should fail.") } func (s *LogFacilityTestSuite) TestSetLevelsError() { - s.Error(s.facility.SetLevels(map[string]Level{"name": Panic})) + s.Error(s.facility.SetLevels(map[string]Level{"name": Panic}), + "Setting a severity level above Fatal should fail.") } func (s *LogFacilityTestSuite) TestNamedLogger() { diff --git a/logging/level_test.go b/logging/level_test.go index 2e78db69..9d1605e5 100644 --- a/logging/level_test.go +++ b/logging/level_test.go @@ -17,8 +17,10 @@ func (s *LogLevelTestSuite) TestLevels() { levels := []Level{Panic, Fatal, Error, Warn, Info, Debug, customLevel} for _, level := range levels { gotLevel, err := Parse(level.String()) - s.NoError(err) - s.Equal(gotLevel, level) + s.NoError(err, + "Converting a Level to a string and back should not fail.") + s.Equal(gotLevel, level, + "Converting a Level to a string and back should produce the same Level.") } } @@ -26,7 +28,8 @@ func (s *LogLevelTestSuite) TestInvalidLevel() { levels := []string{"", "1234", "abc"} for _, level := range levels { _, err := Parse(level) - s.Error(err) + s.Error(err, + "Converting an invalid string to a Level should fail.") } } diff --git a/logging/named_test.go b/logging/named_test.go index 69ff40ac..b1c0f505 100644 --- a/logging/named_test.go +++ b/logging/named_test.go @@ -63,7 +63,8 @@ func (s *NamedLoggerTestSuite) TestForwarding() { Msg: []interface{}{"msg"}, } - s.Equal(s.recv, expected) + s.Equal(s.recv, expected, + "Log messages should be forwarded unmodified.") *s.recv = recv{} // reset @@ -71,7 +72,8 @@ func (s *NamedLoggerTestSuite) TestForwarding() { c.logMethf(s.logger, "format", "msg") expected.Format = "format" - s.Equal(s.recv, expected) + s.Equal(s.recv, expected, + "Log messages should be forwarded unmodified.") } } @@ -84,11 +86,13 @@ func (s *NamedLoggerTestSuite) TestWithFields() { Fields: bark.Fields{"key": 1, "a": 3, "b": 2}, Msg: []interface{}{"msg"}, } - s.Equal(s.recv, expected) + s.Equal(s.recv, expected, + "Multiple fields should be merged.") } func (s *NamedLoggerTestSuite) TestFields() { - s.Equal(s.logger.Fields(), bark.Fields{"key": 1}) + s.Equal(s.logger.Fields(), bark.Fields{"key": 1}, + "A logger should return its fields.") } func TestNamedLoggerTestSuite(t *testing.T) {