...
1 package errors
2
3 import (
4 "errors"
5 "testing"
6
7 "github.com/stretchr/testify/assert"
8 )
9
10 func TestContextualError(t *testing.T) {
11 err := errors.New("example wrapped error")
12 cerr := New("example message", err)
13
14 assert.ErrorIs(t, cerr, err, "Error did not unwrap into expected error")
15
16 t.Log(cerr.Context)
17
18 assert.NotEmpty(t, cerr.Context, "Error context should have been successfully created")
19 assert.Contains(t, cerr.Context, "TestContextualError", "Error context should contain function name")
20 assert.Contains(t, cerr.Context, "12", "Error should contain the line number it was created on")
21 }
22
View as plain text