github.com/MontFerret/ferret@v0.18.0/pkg/runtime/core/errors_test.go (about) 1 package core_test 2 3 import ( 4 "testing" 5 6 "github.com/pkg/errors" 7 . "github.com/smartystreets/goconvey/convey" 8 9 "github.com/MontFerret/ferret/pkg/runtime/core" 10 ) 11 12 func TestSourceError(t *testing.T) { 13 Convey("Should match", t, func() { 14 sm := core.NewSourceMap("test", 1, 1) 15 16 msg := "test at 1:1" 17 cause := errors.New("cause") 18 e := errors.Errorf("%s: %s", cause.Error(), msg) 19 20 cse := core.SourceError(sm, cause) 21 So(cse, ShouldNotBeNil) 22 So(cse.Error(), ShouldEqual, e.Error()) 23 }) 24 } 25 26 func TestTypeError(t *testing.T) { 27 Convey("Should match", t, func() { 28 e := core.TypeError(TypeA{}) 29 So(e, ShouldNotBeNil) 30 31 e = core.TypeError(TypeA{}, TypeB{}) 32 So(e, ShouldNotBeNil) 33 34 cause := errors.New("invalid type: expected type_b or type_c, but got type_a") 35 e = core.TypeError(TypeA{}, TypeB{}, TypeC{}) 36 So(e.Error(), ShouldEqual, cause.Error()) 37 }) 38 } 39 40 func TestError(t *testing.T) { 41 Convey("Should match", t, func() { 42 msg := "test message" 43 cause := errors.New("cause") 44 e := errors.Errorf("%s: %s", cause.Error(), msg) 45 46 ce := core.Error(cause, msg) 47 So(ce, ShouldNotBeNil) 48 So(ce.Error(), ShouldEqual, e.Error()) 49 }) 50 }