Esempio n. 1
0
func TestGetCode(t *testing.T) {
	for _, test := range []struct {
		originalError error
		originalCode  stacktrace.ErrorCode
	}{
		{
			originalError: errors.New("err"),
			originalCode:  stacktrace.NoCode,
		},
		{
			originalError: stacktrace.NewError("err"),
			originalCode:  stacktrace.NoCode,
		},
		{
			originalError: stacktrace.NewErrorWithCode(EcodeInvalidVillain, "err"),
			originalCode:  EcodeInvalidVillain,
		},
		{
			originalError: stacktrace.NewMessageWithCode(EcodeNoSuchPseudo, "err"),
			originalCode:  EcodeNoSuchPseudo,
		},
	} {
		err := test.originalError
		assert.Equal(t, test.originalCode, stacktrace.GetCode(err))

		err = stacktrace.Propagate(err, "")
		assert.Equal(t, test.originalCode, stacktrace.GetCode(err))

		err = stacktrace.PropagateWithCode(err, EcodeNotFastEnough, "")
		assert.Equal(t, EcodeNotFastEnough, stacktrace.GetCode(err))

		err = stacktrace.PropagateWithCode(err, EcodeTimeIsIllusion, "")
		assert.Equal(t, EcodeTimeIsIllusion, stacktrace.GetCode(err))
	}
}
Esempio n. 2
0
func TestPropagateNil(t *testing.T) {
	var err error

	err = stacktrace.Propagate(err, "")
	assert.Nil(t, err)

	err = stacktrace.PropagateWithCode(err, EcodeNotImplemented, "")
	assert.Nil(t, err)

	assert.Equal(t, stacktrace.NoCode, stacktrace.GetCode(err))
}