Exemplo n.º 1
0
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)
}
Exemplo n.º 2
0
func (s *GripInternalSuite) TestConditionalSendFatalDoesNotExitIfNotLoggable() {
	msg := message.NewLinesMessage("foo")
	s.grip.conditionalSendFatal(s.grip.DefaultLevel(), false, msg)

	s.True(level.Debug > s.grip.DefaultLevel())
	s.grip.conditionalSendFatal(level.Debug, true, msg)
}
Exemplo n.º 3
0
func (s *GripInternalSuite) TestPanicSenderRespectsTThreshold() {
	s.True(level.Debug > s.grip.DefaultLevel())

	// test that there is a no panic if the message isn't "logabble"
	defer func() {
		s.Nil(recover())
	}()

	s.grip.sendPanic(level.Debug, message.NewLinesMessage("foo"))
}
Exemplo n.º 4
0
func (s *GripInternalSuite) TestPanicSenderActuallyPanics() {
	// both of these are in anonymous functions so that the defers
	// cover the correct area.

	func() {
		// first make sure that the defualt send method doesn't panic
		defer func() {
			s.Nil(recover())
		}()

		s.grip.Sender().Send(s.grip.DefaultLevel(), message.NewLinesMessage("foo"))
	}()

	func() {
		// call a panic function with a recoverer set.
		defer func() {
			s.NotNil(recover())
		}()

		s.grip.sendPanic(s.grip.DefaultLevel(), message.NewLinesMessage("foo"))
	}()
}
Exemplo n.º 5
0
func TestConditionalSendFatalExits(t *testing.T) {
	std.UseNativeLogger()
	if os.Getenv("SHOULD_CRASH") == "1" {
		std.EmergencyFatalWhen(true, message.NewLinesMessage("foo"))
		return
	}

	cmd := exec.Command(os.Args[0], "-test.run=TestConditionalSendFatalExits")
	cmd.Env = append(os.Environ(), "SHOULD_CRASH=1")
	err := cmd.Run()
	if err == nil {
		t.Errorf("sendFatal should have exited 1, instead: %s", err.Error())
	}
}
Exemplo n.º 6
0
// This testing method uses the technique outlined in:
// http://stackoverflow.com/a/33404435 to test a function that exits
// since it's impossible to "catch" an os.Exit
func TestSendFatalExits(t *testing.T) {
	grip := NewGrip("test")
	if os.Getenv("SHOULD_CRASH") == "1" {
		grip.sendFatal(grip.DefaultLevel(), message.NewLinesMessage("foo"))
		return
	}

	cmd := exec.Command(os.Args[0], "-test.run=TestSendFatalExits")
	cmd.Env = append(os.Environ(), "SHOULD_CRASH=1")
	err := cmd.Run()
	if err == nil {
		t.Errorf("sendFatal should have exited 0, instead: %s", err.Error())
	}
}
Exemplo n.º 7
0
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)
	})
}
Exemplo n.º 8
0
func (g *Grip) ErrorPanicln(a ...interface{}) {
	g.sendPanic(level.Error, message.NewLinesMessage(a...))
}
Exemplo n.º 9
0
func (g *Grip) Warningln(a ...interface{}) {
	g.sender.Send(level.Warning, message.NewLinesMessage(a...))
}
Exemplo n.º 10
0
func (g *Grip) Noticeln(a ...interface{}) {
	g.sender.Send(level.Notice, message.NewLinesMessage(a...))
}
Exemplo n.º 11
0
func (g *Grip) ErrorFatalln(a ...interface{}) {
	g.sendFatal(level.Error, message.NewLinesMessage(a...))
}
Exemplo n.º 12
0
func (g *Grip) EmergencyFatalWhenln(conditional bool, msg ...interface{}) {
	g.conditionalSendFatal(level.Emergency, conditional, message.NewLinesMessage(msg...))
}
Exemplo n.º 13
0
func (g *Grip) Debugln(a ...interface{}) {
	g.sender.Send(level.Debug, message.NewLinesMessage(a...))
}
Exemplo n.º 14
0
func (g *Grip) ErrorPanicWhenln(conditional bool, msg ...interface{}) {
	g.conditionalSendPanic(level.Error, conditional, message.NewLinesMessage(msg...))
}
Exemplo n.º 15
0
func (g *Grip) CriticalWhenln(conditional bool, msg ...interface{}) {
	g.CriticalWhen(conditional, message.NewLinesMessage(msg...))
}
Exemplo n.º 16
0
func (g *Grip) EmergencyPanicln(a ...interface{}) {
	g.sendPanic(level.Emergency, message.NewLinesMessage(a...))
}
Exemplo n.º 17
0
func (g *Grip) Emergencyln(a ...interface{}) {
	g.sender.Send(level.Emergency, message.NewLinesMessage(a...))
}
Exemplo n.º 18
0
func (g *Grip) Defaultln(a ...interface{}) {
	g.sender.Send(g.sender.DefaultLevel(), message.NewLinesMessage(a...))
}
Exemplo n.º 19
0
func (g *Grip) Sendln(l level.Priority, a ...interface{}) {
	g.sender.Send(l, message.NewLinesMessage(a...))
}
Exemplo n.º 20
0
func (g *Grip) SendWhenln(conditional bool, l level.Priority, msg ...interface{}) {
	g.SendWhen(conditional, l, message.NewLinesMessage(msg...))
}
Exemplo n.º 21
0
func (g *Grip) EmergencyFatalln(a ...interface{}) {
	g.sendFatal(level.Emergency, message.NewLinesMessage(a...))
}
Exemplo n.º 22
0
func (g *Grip) Infoln(a ...interface{}) {
	g.sender.Send(level.Info, message.NewLinesMessage(a...))
}
Exemplo n.º 23
0
func (g *Grip) CriticalFatalWhenln(conditional bool, msg ...interface{}) {
	g.conditionalSendFatal(level.Critical, conditional, message.NewLinesMessage(msg...))
}
Exemplo n.º 24
0
func (g *Grip) Alertln(a ...interface{}) {
	g.sender.Send(level.Alert, message.NewLinesMessage(a...))
}
Exemplo n.º 25
0
func (g *Grip) WarningWhenln(conditional bool, msg ...interface{}) {
	g.WarningWhen(conditional, message.NewLinesMessage(msg...))
}
Exemplo n.º 26
0
func (g *Grip) AlertPanicln(a ...interface{}) {
	g.sendPanic(level.Alert, message.NewLinesMessage(a...))
}
Exemplo n.º 27
0
func (g *Grip) EmergencyWhenln(conditional bool, msg ...interface{}) {
	g.EmergencyWhen(conditional, message.NewLinesMessage(msg...))
}
Exemplo n.º 28
0
func (g *Grip) AlertFatalln(a ...interface{}) {
	g.sendFatal(level.Alert, message.NewLinesMessage(a...))
}
Exemplo n.º 29
0
func (g *Grip) AlertWhenln(conditional bool, msg ...interface{}) {
	g.AlertWhen(conditional, message.NewLinesMessage(msg...))
}
Exemplo n.º 30
0
func (g *Grip) Errorln(a ...interface{}) {
	g.sender.Send(level.Error, message.NewLinesMessage(a...))
}