Skip to content

Commit

Permalink
Add custom error messages for assertions.
Browse files Browse the repository at this point in the history
  • Loading branch information
severb committed Jan 28, 2016
1 parent 6627a4d commit b8fd642
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 9 deletions.
6 changes: 4 additions & 2 deletions logging/facility_test.go
Expand Up @@ -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() {
Expand Down
9 changes: 6 additions & 3 deletions logging/level_test.go
Expand Up @@ -17,16 +17,19 @@ 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.")
}
}

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.")
}
}

Expand Down
12 changes: 8 additions & 4 deletions logging/named_test.go
Expand Up @@ -63,15 +63,17 @@ 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

// logger.Debugf("format", "msg")
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.")
}
}

Expand All @@ -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) {
Expand Down

0 comments on commit b8fd642

Please sign in to comment.