func (s *GripInternalSuite) TestConditionalSend() { // because sink is an internal type (implementation of // sender,) and "GetMessage" isn't in the interface, though it // is exported, we can't pass the sink between functions. sink, err := send.NewInternalLogger(s.grip.ThresholdLevel(), s.grip.DefaultLevel()) s.NoError(err) s.grip.SetSender(sink) msg := message.NewLinesMessage("foo") msgTwo := message.NewLinesMessage("bar") // when the conditional argument is true, it should work s.grip.conditionalSend(level.Emergency, true, msg) s.Equal(sink.GetMessage().Message, msg) // when the conditional argument is true, it should work, and the channel is fifo s.grip.conditionalSend(level.Emergency, false, msgTwo) s.grip.conditionalSend(level.Emergency, true, msg) s.Equal(sink.GetMessage().Message, msg) // change the order s.grip.conditionalSend(level.Emergency, true, msg) s.grip.conditionalSend(level.Emergency, false, msgTwo) s.Equal(sink.GetMessage().Message, msg) }
func (s *GripInternalSuite) TestConditionalSendPanic() { sink, err := send.NewInternalLogger(s.grip.ThresholdLevel(), s.grip.DefaultLevel()) s.NoError(err) s.grip.SetSender(sink) msg := message.NewLinesMessage("foo") // first if the conditional is false, it can't panic. s.NotPanics(func() { s.grip.conditionalSendPanic(level.Emergency, false, msg) }) // next, if the conditional is true it should panic s.Panics(func() { s.grip.conditionalSendPanic(level.Emergency, true, msg) }) }