github.com/machinefi/w3bstream@v1.6.5-rc9.0.20240426031326-b8c7c4876e72/pkg/test/mock_depends_kit_sqlx/error.go (about) 1 package mock_sqlx 2 3 import ( 4 "errors" 5 "testing" 6 7 . "github.com/onsi/gomega" 8 9 "github.com/machinefi/w3bstream/pkg/depends/kit/sqlx" 10 "github.com/machinefi/w3bstream/pkg/depends/kit/statusx" 11 "github.com/machinefi/w3bstream/pkg/errors/status" 12 ) 13 14 var ( 15 ErrConflict = sqlx.NewSqlError(sqlx.SqlErrTypeConflict, "") 16 ErrNotFound = sqlx.NewSqlError(sqlx.SqlErrTypeNotFound, "") 17 ErrDatabase = errors.New("database error") 18 ) 19 20 func ExpectError(t *testing.T, err error, se status.Error, desc ...string) { 21 NewWithT(t).Expect(err).NotTo(BeNil()) 22 expect, ok := statusx.IsStatusErr(err) 23 NewWithT(t).Expect(ok).To(BeTrue()) 24 NewWithT(t).Expect(expect.Key).To(Equal(se.Key())) 25 if len(desc) > 0 { 26 NewWithT(t).Expect(desc[0]).To(Equal(expect.Desc)) 27 } 28 } 29 30 func ErrNotFoundFrom(from string) error { 31 return sqlx.NewSqlError(sqlx.SqlErrTypeNotFound, from) 32 } 33 34 func ErrConflictFrom(from string) error { 35 return sqlx.NewSqlError(sqlx.SqlErrTypeConflict, from) 36 }