Esempio n. 1
0
func TestNotCatchNilPanic(t *testing.T) {
	rt := &fakeRoundTripper{}
	c := newTestClient(rt)
	defer func() {
		r := rt.req
		if r != nil {
			t.Errorf("got error report, expected none")
		}
	}()
	defer c.Catch(ctx, errors.WithMessage("hello, error"))
	panic(nil)
}
Esempio n. 2
0
func TestCatchNilPanic(t *testing.T) {
	rt := &fakeRoundTripper{}
	c := newTestClient(rt)
	defer func() {
		r := rt.req
		if r == nil {
			t.Fatalf("got no error report, expected one")
		}
		commonChecks(t, rt.body, "errors_test.TestCatchNilPanic")
		if !strings.Contains(rt.body, "nil") {
			t.Errorf("error report didn't contain recovered value")
		}
	}()
	b := true
	defer c.Catch(ctx, errors.WithMessage("hello, error"), errors.PanicFlag(&b))
	panic(nil)
}
Esempio n. 3
0
func TestCatchPanic(t *testing.T) {
	rt := &fakeRoundTripper{}
	c := newTestClient(rt)
	defer func() {
		r := rt.req
		if r == nil {
			t.Fatalf("got no error report, expected one")
		}
		commonChecks(t, rt.body, "errors_test.TestCatchPanic")
		if !strings.Contains(rt.body, "divide by zero") {
			t.Errorf("error report didn't contain recovered value")
		}
	}()
	defer c.Catch(ctx, errors.WithMessage("hello, error"))
	var x int
	x = x / x
}
Esempio n. 4
0
func TestLogFailedReports(t *testing.T) {
	rt := &fakeRoundTripper{}
	c := newTestClient(rt)
	rt.fail = true
	buf := new(bytes.Buffer)
	log.SetOutput(buf)
	defer func() {
		recover()
		body := buf.Bytes()
		commonChecks(t, string(body), "errors_test.TestLogFailedReports")
		if !strings.Contains(string(body), "divide by zero") {
			t.Errorf("error report didn't contain recovered value")
		}
	}()
	defer c.Catch(ctx, errors.WithMessage("hello, error"))
	var x int
	x = x / x
}
Esempio n. 5
0
func TestCatchPanicNilClient(t *testing.T) {
	buf := new(bytes.Buffer)
	log.SetOutput(buf)
	defer func() {
		recover()
		body := buf.Bytes()
		if !strings.Contains(string(body), "divide by zero") {
			t.Errorf("error report didn't contain recovered value")
		}
		if !strings.Contains(string(body), "hello, error") {
			t.Errorf("error report didn't contain message")
		}
		if !strings.Contains(string(body), "errors_test.TestCatchPanicNilClient") {
			t.Errorf("error report didn't contain recovered value")
		}
	}()
	var c *errors.Client
	defer c.Catch(ctx, errors.WithMessage("hello, error"))
	var x int
	x = x / x
}